scripts/migrate_shorturls.py
author terom
Wed, 16 Jan 2008 18:44:03 +0000
changeset 22 72696ca68c34
child 26 81d6679d50d0
permissions -rw-r--r--
use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
22
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
     1
from lib import shorturl, db
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
     2
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
     3
sdb = shorturl.DB()
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
     4
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
     5
def gen () :
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
     6
    count = 0
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
     7
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
     8
    for key in sdb.db.keys() :
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
     9
        if key.startswith("_") :
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    10
            continue
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    11
        
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    12
        print "%6s" % key,
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    13
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    14
        value = sdb.db[key]
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    15
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    16
        if not isinstance(value, tuple) or len(value) != 3 :
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    17
            print "CORRUPT VALUE!!!"
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    18
            continue
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    19
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    20
        type, dirpath, fname = value
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    21
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    22
        if type == "img" :
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    23
            id = shorturl.key2int(key)
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    24
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    25
            dirpath = dirpath.lstrip('.').lstrip('/')
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    26
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    27
            print "%6d %50s %10s" % (id, dirpath, fname)
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    28
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    29
            yield id, dirpath, fname
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    30
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    31
            count += 1
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    32
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    33
            if count % 500 == 0 :
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    34
                print count
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    35
        else :
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    36
            print "dir"
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    37
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    38
print "Starting import..."
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    39
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    40
c = db.cursor()
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    41
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    42
c.executemany("""
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    43
    INSERT INTO images VALUES (?, ?, ?)
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    44
""", gen())
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    45
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    46
print "Done!"
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    47
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    48
print "%d rows affected" % c.rowcount
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    49
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    50
c.execute("SELECT id FROM images").fetchall()
72696ca68c34 use sqlite3 instead of bdb, series and shorturl should still work with this (adding new images won't yet)
terom
parents:
diff changeset
    51