mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
allow dump/load of gdbm files
This commit is contained in:
parent
9c8f7eafca
commit
48f9c6dfb8
2 changed files with 28 additions and 6 deletions
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/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
|
Convert the database file given on the command line to a pickle
|
||||||
representation. The optional flags indicate the type of the database (hash,
|
representation. The optional flags indicate the type of the database (hash,
|
||||||
|
@ -20,6 +20,10 @@ try:
|
||||||
import dbm
|
import dbm
|
||||||
except ImportError:
|
except ImportError:
|
||||||
dbm = None
|
dbm = None
|
||||||
|
try:
|
||||||
|
import gdbm
|
||||||
|
except ImportError:
|
||||||
|
gdbm = None
|
||||||
try:
|
try:
|
||||||
import anydbm
|
import anydbm
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -37,8 +41,9 @@ def usage():
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(args, "hbrda",
|
opts, args = getopt.getopt(args, "hbrdag",
|
||||||
["hash", "btree", "recno", "dbm", "anydbm"])
|
["hash", "btree", "recno", "dbm",
|
||||||
|
"gdbm", "anydbm"])
|
||||||
except getopt.error:
|
except getopt.error:
|
||||||
usage()
|
usage()
|
||||||
return 1
|
return 1
|
||||||
|
@ -83,6 +88,12 @@ def main(args):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
sys.stderr.write("anydbm module unavailable.\n")
|
sys.stderr.write("anydbm module unavailable.\n")
|
||||||
return 1
|
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"):
|
elif opt in ("-d", "--dbm"):
|
||||||
try:
|
try:
|
||||||
dbopen = dbm.open
|
dbopen = dbm.open
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/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
|
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
|
database. If the database already exists, any contents are deleted. The
|
||||||
|
@ -24,6 +24,10 @@ try:
|
||||||
import dbm
|
import dbm
|
||||||
except ImportError:
|
except ImportError:
|
||||||
dbm = None
|
dbm = None
|
||||||
|
try:
|
||||||
|
import gdbm
|
||||||
|
except ImportError:
|
||||||
|
gdbm = None
|
||||||
try:
|
try:
|
||||||
import anydbm
|
import anydbm
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -41,8 +45,9 @@ def usage():
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(args, "hbrda",
|
opts, args = getopt.getopt(args, "hbrdag",
|
||||||
["hash", "btree", "recno", "dbm", "anydbm"])
|
["hash", "btree", "recno", "dbm", "anydbm",
|
||||||
|
"gdbm"])
|
||||||
except getopt.error:
|
except getopt.error:
|
||||||
usage()
|
usage()
|
||||||
return 1
|
return 1
|
||||||
|
@ -87,6 +92,12 @@ def main(args):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
sys.stderr.write("anydbm module unavailable.\n")
|
sys.stderr.write("anydbm module unavailable.\n")
|
||||||
return 1
|
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"):
|
elif opt in ("-d", "--dbm"):
|
||||||
try:
|
try:
|
||||||
dbopen = dbm.open
|
dbopen = dbm.open
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue