def reorgdb(outname, fname, threshold, verbose): print >>stderr, 'input=%s, output=%s, threshold=%d' % (fname, outname, threshold) try: os.stat(outname) raise IOError('file %r already exists.' % outname) except OSError: pass now = int(time.time()) db = dbmopen(fname, 'r') out = dbmopen(outname, 'c') remain = 0 filtered = 0 for (k,v) in db.iteritems(): t = struct.unpack('<L', v)[0] if now-t < threshold: out[k] = v remain += 1 else: filtered += 1 if verbose: print ''.join([ '%02x' % ord(c) for c in k ]), time.asctime(time.localtime(t)), '(out)' print >>stderr, 'total: %d (remain: %d, filtered: %d)' % (remain+filtered, remain, filtered) db.close() out.close() return
def dispdb(fname, threshold, verbose): now = int(time.time()) db = dbmopen(fname, 'r') for (k,v) in db.iteritems(): t = struct.unpack('<L', v)[0] print ''.join([ '%02x' % ord(c) for c in k ]), time.asctime(time.localtime(t)), if threshold <= now-t: print '(out)' else: print '(in)' db.close() return
def __init__(self, path, debug=0): self.db = dbmopen(path, 'c') self.debug = debug if self.debug: print >>stderr, 'URLDB open: %r' % path return