catacomb/__init__.py: Add iterfoo methods to _groupmap.
[catacomb-python] / pwsafe
diff --git a/pwsafe b/pwsafe
index e285380..52f9abb 100755 (executable)
--- a/pwsafe
+++ b/pwsafe
@@ -1,4 +1,4 @@
-#! /usr/bin/python2.2
+#! /usr/bin/python
 # -*-python-*-
 
 import catacomb as C
 # -*-python-*-
 
 import catacomb as C
@@ -8,6 +8,14 @@ from os import environ
 from sys import argv, exit, stdin, stdout, stderr
 from getopt import getopt, GetoptError
 from fnmatch import fnmatch
 from sys import argv, exit, stdin, stdout, stderr
 from getopt import getopt, GetoptError
 from fnmatch import fnmatch
+import re
+
+prog = re.sub(r'^.*[/\\]', '', argv[0])
+def moan(msg):
+  print >>stderr, '%s: %s' % (prog, msg)
+def die(msg):
+  moan(msg)
+  exit(1)
 
 if 'PWSAFE' in environ:
   file = environ['PWSAFE']
 
 if 'PWSAFE' in environ:
   file = environ['PWSAFE']
@@ -70,7 +78,10 @@ def cmd_find(av):
   if len(av) != 1:
     return 1
   pw = PW(file)
   if len(av) != 1:
     return 1
   pw = PW(file)
-  print pw[av[0]]
+  try:
+    print pw[av[0]]
+  except KeyError, exc:
+    die('Password `%s\' not found.' % exc.args[0])
 
 def cmd_store(av):
   if len(av) < 1 or len(av) > 2:
 
 def cmd_store(av):
   if len(av) < 1 or len(av) > 2:
@@ -134,7 +145,10 @@ def cmd_del(av):
     return 1
   pw = PW(file, 'w')
   tag = av[0]
     return 1
   pw = PW(file, 'w')
   tag = av[0]
-  del pw[tag]
+  try:
+    del pw[tag]
+  except KeyError, exc:
+    die('Password `%s\' not found.' % exc.args[0])
 
 def asciip(s):
   for ch in s:
 
 def asciip(s):
   for ch in s:
@@ -152,24 +166,24 @@ def cmd_dump(av):
     k = db.nextkey(k)
 
 commands = { 'create': [cmd_create,
     k = db.nextkey(k)
 
 commands = { 'create': [cmd_create,
-                        '[-c CIPHER] [-h HASH] [-m MAC] [PP-TAG]'],
-             'find' : [cmd_find, 'LABEL'],
-             'store' : [cmd_store, 'LABEL [VALUE]'],
-             'list' : [cmd_list, '[GLOB-PATTERN]'],
-             'changepp' : [cmd_changepp, ''],
-             'copy' : [cmd_copy, 'DEST-FILE [GLOB-PATTERN]'],
-             'to-pixie' : [cmd_topixie, '[TAG [PIXIE-TAG]]'],
-             'delete' : [cmd_del, 'TAG'],
-             'dump' : [cmd_dump, '']}
+                       '[-c CIPHER] [-h HASH] [-m MAC] [PP-TAG]'],
+            'find' : [cmd_find, 'LABEL'],
+            'store' : [cmd_store, 'LABEL [VALUE]'],
+            'list' : [cmd_list, '[GLOB-PATTERN]'],
+            'changepp' : [cmd_changepp, ''],
+            'copy' : [cmd_copy, 'DEST-FILE [GLOB-PATTERN]'],
+            'to-pixie' : [cmd_topixie, '[TAG [PIXIE-TAG]]'],
+            'delete' : [cmd_del, 'TAG'],
+            'dump' : [cmd_dump, '']}
 
 def version():
 
 def version():
-  print 'pwsafe 1.0.0'
+  print '%s 1.0.0' % prog
 def usage(fp):
 def usage(fp):
-  print >>fp, 'Usage: pwsafe COMMAND [ARGS...]'
+  print >>fp, 'Usage: %s COMMAND [ARGS...]' % prog
 def help():
   version()
   print
 def help():
   version()
   print
-  usage(stdout)  
+  usage(stdout)
   print '''
 Maintains passwords or other short secrets securely.
 
   print '''
 Maintains passwords or other short secrets securely.
 
@@ -179,6 +193,8 @@ Options:
 -v, --version          Show program version number.
 -u, --usage            Show short usage message.
 
 -v, --version          Show program version number.
 -u, --usage            Show short usage message.
 
+-f, --file=FILE                Where to find the password-safe file.
+
 Commands provided:
 '''
   for c in commands:
 Commands provided:
 '''
   for c in commands:
@@ -186,8 +202,8 @@ Commands provided:
 
 try:
   opts, argv = getopt(argv[1:],
 
 try:
   opts, argv = getopt(argv[1:],
-                      'hvuf:',
-                      ['help', 'version', 'usage', 'file='])
+                     'hvuf:',
+                     ['help', 'version', 'usage', 'file='])
 except GetoptError:
   usage(stderr)
   exit(1)
 except GetoptError:
   usage(stderr)
   exit(1)
@@ -215,5 +231,5 @@ if argv[0] in commands:
 else:
   c = 'find'
 if commands[c][0](argv):
 else:
   c = 'find'
 if commands[c][0](argv):
-  print >>stderr, 'Usage: pwsafe %s %s' % (c, commands[c][1])
+  print >>stderr, 'Usage: %s %s %s' % (prog, c, commands[c][1])
   exit(1)
   exit(1)