]> granicus.if.org Git - python/commitdiff
allow dump/load of gdbm files
authorSkip Montanaro <skip@pobox.com>
Tue, 28 Oct 2003 16:17:54 +0000 (16:17 +0000)
committerSkip Montanaro <skip@pobox.com>
Tue, 28 Oct 2003 16:17:54 +0000 (16:17 +0000)
Tools/scripts/db2pickle.py
Tools/scripts/pickle2db.py

index 492c1d7ba1a5566f3fcfe3c2d851f39cf5c428ad..7b0857c1a6da4b0b7745142037397d89259edead 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 
 """
-Synopsis: %(prog)s [-h|-b|-r] dbfile [ picklefile ]
+Synopsis: %(prog)s [-h|-g|-b|-r|-a] dbfile [ picklefile ]
 
 Convert the database file given on the command line to a pickle
 representation.  The optional flags indicate the type of the database (hash,
@@ -20,6 +20,10 @@ try:
     import dbm
 except ImportError:
     dbm = None
+try:
+    import gdbm
+except ImportError:
+    gdbm = None
 try:
     import anydbm
 except ImportError:
@@ -37,8 +41,9 @@ def usage():
 
 def main(args):
     try:
-        opts, args = getopt.getopt(args, "hbrda",
-                                   ["hash", "btree", "recno", "dbm", "anydbm"])
+        opts, args = getopt.getopt(args, "hbrdag",
+                                   ["hash", "btree", "recno", "dbm",
+                                    "gdbm", "anydbm"])
     except getopt.error:
         usage()
         return 1
@@ -83,6 +88,12 @@ def main(args):
             except AttributeError:
                 sys.stderr.write("anydbm module unavailable.\n")
                 return 1
+        elif opt in ("-g", "--gdbm"):
+            try:
+                dbopen = gdbm.open
+            except AttributeError:
+                sys.stderr.write("gdbm module unavailable.\n")
+                return 1
         elif opt in ("-d", "--dbm"):
             try:
                 dbopen = dbm.open
index a35021f63b1337e360c7501f8d14462d4efad43e..7e699f44b1b7df703f9ddcf6da8f57ff48123762 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 
 """
-Synopsis: %(prog)s [-h|-b|-r|-a|-d] dbfile [ picklefile ]
+Synopsis: %(prog)s [-h|-b|-g|-r|-a|-d] dbfile [ picklefile ]
 
 Read the given picklefile as a series of key/value pairs and write to a new
 database.  If the database already exists, any contents are deleted.  The
@@ -24,6 +24,10 @@ try:
     import dbm
 except ImportError:
     dbm = None
+try:
+    import gdbm
+except ImportError:
+    gdbm = None
 try:
     import anydbm
 except ImportError:
@@ -41,8 +45,9 @@ def usage():
 
 def main(args):
     try:
-        opts, args = getopt.getopt(args, "hbrda",
-                                   ["hash", "btree", "recno", "dbm", "anydbm"])
+        opts, args = getopt.getopt(args, "hbrdag",
+                                   ["hash", "btree", "recno", "dbm", "anydbm",
+                                    "gdbm"])
     except getopt.error:
         usage()
         return 1
@@ -87,6 +92,12 @@ def main(args):
             except AttributeError:
                 sys.stderr.write("anydbm module unavailable.\n")
                 return 1
+        elif opt in ("-g", "--gdbm"):
+            try:
+                dbopen = gdbm.open
+            except AttributeError:
+                sys.stderr.write("gdbm module unavailable.\n")
+                return 1
         elif opt in ("-d", "--dbm"):
             try:
                 dbopen = dbm.open