Back to index

python3.2  3.2.2
Functions | Variables
pickle2db Namespace Reference

Functions

def usage
def main

Variables

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

Function Documentation

def pickle2db.main (   args)

Definition at line 55 of file pickle2db.py.

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

Here is the call graph for this function:

def pickle2db.usage ( )

Definition at line 52 of file pickle2db.py.

00052 
00053 def usage():
00054     sys.stderr.write(__doc__ % globals())

Here is the caller graph for this function:


Variable Documentation

Definition at line 43 of file pickle2db.py.

Definition at line 31 of file pickle2db.py.

pickle2db.dbm = None

Definition at line 35 of file pickle2db.py.

Definition at line 39 of file pickle2db.py.

Definition at line 50 of file pickle2db.py.