Back to index

python3.2  3.2.2
Functions | Variables
db2pickle Namespace Reference

Functions

def usage
def main

Variables

 bsddb = None
 dbm = None
 gdbm = None
 anydbm = None
list prog = sys.argv[0]

Function Documentation

def db2pickle.main (   args)

Definition at line 50 of file db2pickle.py.

00050 
00051 def main(args):
00052     try:
00053         opts, args = getopt.getopt(args, "hbrdag",
00054                                    ["hash", "btree", "recno", "dbm",
00055                                     "gdbm", "anydbm"])
00056     except getopt.error:
00057         usage()
00058         return 1
00059 
00060     if len(args) == 0 or len(args) > 2:
00061         usage()
00062         return 1
00063     elif len(args) == 1:
00064         dbfile = args[0]
00065         pfile = sys.stdout
00066     else:
00067         dbfile = args[0]
00068         try:
00069             pfile = open(args[1], 'wb')
00070         except IOError:
00071             sys.stderr.write("Unable to open %s\n" % args[1])
00072             return 1
00073 
00074     dbopen = None
00075     for opt, arg in opts:
00076         if opt in ("-h", "--hash"):
00077             try:
00078                 dbopen = bsddb.hashopen
00079             except AttributeError:
00080                 sys.stderr.write("bsddb module unavailable.\n")
00081                 return 1
00082         elif opt in ("-b", "--btree"):
00083             try:
00084                 dbopen = bsddb.btopen
00085             except AttributeError:
00086                 sys.stderr.write("bsddb module unavailable.\n")
00087                 return 1
00088         elif opt in ("-r", "--recno"):
00089             try:
00090                 dbopen = bsddb.rnopen
00091             except AttributeError:
00092                 sys.stderr.write("bsddb module unavailable.\n")
00093                 return 1
00094         elif opt in ("-a", "--anydbm"):
00095             try:
00096                 dbopen = anydbm.open
00097             except AttributeError:
00098                 sys.stderr.write("dbm module unavailable.\n")
00099                 return 1
00100         elif opt in ("-g", "--gdbm"):
00101             try:
00102                 dbopen = gdbm.open
00103             except AttributeError:
00104                 sys.stderr.write("dbm.gnu module unavailable.\n")
00105                 return 1
00106         elif opt in ("-d", "--dbm"):
00107             try:
00108                 dbopen = dbm.open
00109             except AttributeError:
00110                 sys.stderr.write("dbm.ndbm module unavailable.\n")
00111                 return 1
00112     if dbopen is None:
00113         if bsddb is None:
00114             sys.stderr.write("bsddb module unavailable - ")
00115             sys.stderr.write("must specify dbtype.\n")
00116             return 1
00117         else:
00118             dbopen = bsddb.hashopen
00119 
00120     try:
00121         db = dbopen(dbfile, 'r')
00122     except bsddb.error:
00123         sys.stderr.write("Unable to open %s.  " % dbfile)
00124         sys.stderr.write("Check for format or version mismatch.\n")
00125         return 1
00126 
00127     for k in db.keys():
00128         pickle.dump((k, db[k]), pfile, 1==1)
00129 
00130     db.close()
00131     pfile.close()
00132 
00133     return 0

Here is the call graph for this function:

def db2pickle.usage ( )

Definition at line 47 of file db2pickle.py.

00047 
00048 def usage():
00049     sys.stderr.write(__doc__ % globals())

Here is the caller graph for this function:


Variable Documentation

Definition at line 38 of file db2pickle.py.

Definition at line 26 of file db2pickle.py.

db2pickle.dbm = None

Definition at line 30 of file db2pickle.py.

Definition at line 34 of file db2pickle.py.

Definition at line 45 of file db2pickle.py.