chiark / gitweb /
catacomb/pwsafe.py: New FlatFileStorageBackend class.
[catacomb-python] / pwsafe
diff --git a/pwsafe b/pwsafe
index 50a58780f6e1bb565cffa0805adde996a1a07c15..153ee54b56b55b3856dde83abcdcff01a472e5f9 100644 (file)
--- a/pwsafe
+++ b/pwsafe
@@ -65,13 +65,16 @@ def cmd_create(av):
 
   ## Parse the options.
   try:
-    opts, args = getopt(av, 'c:h:m:', ['cipher=', 'mac=', 'hash='])
+    opts, args = getopt(av, 'c:d:h:m:',
+                        ['cipher=', 'database=', 'mac=', 'hash='])
   except GetoptError:
     return 1
+  dbty = 'gdbm'
   for o, a in opts:
     if o in ('-c', '--cipher'): cipher = a
     elif o in ('-m', '--mac'): mac = a
     elif o in ('-h', '--hash'): hash = a
+    elif o in ('-d', '--database'): dbty = a
     else: raise 'Barf!'
   if len(args) > 2: return 1
   if len(args) >= 1: tag = args[0]
@@ -79,7 +82,10 @@ def cmd_create(av):
 
   ## Set up the database.
   if mac is None: mac = hash + '-hmac'
-  PW.create(file, C.gcciphers[cipher], C.gchashes[hash], C.gcmacs[mac], tag)
+  try: dbcls = StorageBackend.byname(dbty)
+  except KeyError: die("Unknown database backend `%s'" % dbty)
+  PW.create(dbcls, file, tag,
+            C.gcciphers[cipher], C.gchashes[hash], C.gcmacs[mac])
 
 def cmd_changepp(av):
   if len(av) != 0: return 1
@@ -142,7 +148,7 @@ def cmd_del(av):
     except KeyError, exc: die("Password `%s' not found" % exc.args[0])
 
 commands = { 'create': [cmd_create,
-                        '[-c CIPHER] [-h HASH] [-m MAC] [PP-TAG]'],
+                        '[-c CIPHER] [-d DBTYPE] [-h HASH] [-m MAC] [PP-TAG]'],
              'find' : [cmd_find, 'LABEL'],
              'store' : [cmd_store, 'LABEL [VALUE]'],
              'list' : [cmd_list, '[GLOB-PATTERN]'],
@@ -156,6 +162,8 @@ commands = { 'create': [cmd_create,
 
 def version():
   print '%s 1.0.0' % prog
+  print 'Backend types: %s' % \
+      ' '.join([c.NAME for c in StorageBackend.classes()])
 
 def usage(fp):
   print >>fp, 'Usage: %s COMMAND [ARGS...]' % prog