terom@22: from lib import shorturl, db terom@22: terom@22: sdb = shorturl.DB() terom@22: terom@22: def gen () : terom@22: count = 0 terom@22: terom@22: for key in sdb.db.keys() : terom@22: if key.startswith("_") : terom@22: continue terom@22: terom@22: print "%6s" % key, terom@22: terom@22: value = sdb.db[key] terom@22: terom@22: if not isinstance(value, tuple) or len(value) != 3 : terom@22: print "CORRUPT VALUE!!!" terom@22: continue terom@22: terom@22: type, dirpath, fname = value terom@22: terom@26: id = shorturl.key2int(key) terom@26: dirpath = dirpath.lstrip('.').lstrip('/') terom@22: terom@26: if type == "img" : terom@26: print "img" terom@26: continue # already imported images terom@22: terom@26: print "img %6d %50s %10s" % (id, dirpath, fname) terom@22: terom@22: yield id, dirpath, fname terom@22: terom@26: else : terom@22: terom@26: print "dir %6d %50s" % (id, dirpath) terom@26: terom@26: yield id, dirpath, '' terom@26: terom@26: count += 1 terom@26: terom@26: if count % 500 == 0 : terom@26: print count terom@26: terom@22: terom@22: print "Starting import..." terom@22: terom@26: c = db.insert_many(""" terom@26: INSERT OR IGNORE INTO nodes VALUES (?, ?, ?) terom@22: """, gen()) terom@22: terom@22: print "Done!" terom@22: terom@26: print "%d rows affected" % c