Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48f9c6d

Browse files
author
Skip Montanaro
committed
allow dump/load of gdbm files
1 parent 9c8f7ea commit 48f9c6d

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

Tools/scripts/db2pickle.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22

33
"""
4-
Synopsis: %(prog)s [-h|-b|-r] dbfile [ picklefile ]
4+
Synopsis: %(prog)s [-h|-g|-b|-r|-a] dbfile [ picklefile ]
55
66
Convert the database file given on the command line to a pickle
77
representation. The optional flags indicate the type of the database (hash,
@@ -20,6 +20,10 @@
2020
import dbm
2121
except ImportError:
2222
dbm = None
23+
try:
24+
import gdbm
25+
except ImportError:
26+
gdbm = None
2327
try:
2428
import anydbm
2529
except ImportError:
@@ -37,8 +41,9 @@ def usage():
3741

3842
def main(args):
3943
try:
40-
opts, args = getopt.getopt(args, "hbrda",
41-
["hash", "btree", "recno", "dbm", "anydbm"])
44+
opts, args = getopt.getopt(args, "hbrdag",
45+
["hash", "btree", "recno", "dbm",
46+
"gdbm", "anydbm"])
4247
except getopt.error:
4348
usage()
4449
return 1
@@ -83,6 +88,12 @@ def main(args):
8388
except AttributeError:
8489
sys.stderr.write("anydbm module unavailable.\n")
8590
return 1
91+
elif opt in ("-g", "--gdbm"):
92+
try:
93+
dbopen = gdbm.open
94+
except AttributeError:
95+
sys.stderr.write("gdbm module unavailable.\n")
96+
return 1
8697
elif opt in ("-d", "--dbm"):
8798
try:
8899
dbopen = dbm.open

Tools/scripts/pickle2db.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22

33
"""
4-
Synopsis: %(prog)s [-h|-b|-r|-a|-d] dbfile [ picklefile ]
4+
Synopsis: %(prog)s [-h|-b|-g|-r|-a|-d] dbfile [ picklefile ]
55
66
Read the given picklefile as a series of key/value pairs and write to a new
77
database. If the database already exists, any contents are deleted. The
@@ -24,6 +24,10 @@
2424
import dbm
2525
except ImportError:
2626
dbm = None
27+
try:
28+
import gdbm
29+
except ImportError:
30+
gdbm = None
2731
try:
2832
import anydbm
2933
except ImportError:
@@ -41,8 +45,9 @@ def usage():
4145

4246
def main(args):
4347
try:
44-
opts, args = getopt.getopt(args, "hbrda",
45-
["hash", "btree", "recno", "dbm", "anydbm"])
48+
opts, args = getopt.getopt(args, "hbrdag",
49+
["hash", "btree", "recno", "dbm", "anydbm",
50+
"gdbm"])
4651
except getopt.error:
4752
usage()
4853
return 1
@@ -87,6 +92,12 @@ def main(args):
8792
except AttributeError:
8893
sys.stderr.write("anydbm module unavailable.\n")
8994
return 1
95+
elif opt in ("-g", "--gdbm"):
96+
try:
97+
dbopen = gdbm.open
98+
except AttributeError:
99+
sys.stderr.write("gdbm module unavailable.\n")
100+
return 1
90101
elif opt in ("-d", "--dbm"):
91102
try:
92103
dbopen = dbm.open

0 commit comments

Comments
 (0)