X-Git-Url: https://git.phdru.name/?p=xsetbg.git;a=blobdiff_plain;f=reload_db.py;h=3c9c56e64ef3d26ca6fcc0f3cd9f9589309fff4d;hp=d60e3ec314207c0213e745bd35c8757352afa6f7;hb=HEAD;hpb=c35e3acf494456a9ab66a307aee8eae9f167d8ed diff --git a/reload_db.py b/reload_db.py index d60e3ec..c12607a 100755 --- a/reload_db.py +++ b/reload_db.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 """Reload a dump into DB This file is a part of XSetBg. @@ -19,17 +19,16 @@ def convert_str(s): return int(float(s)) -fs_encoding = xsetbg_conf.get("images", "fs_encoding") -dump_file = open(sys.argv[1], 'r') +dump_file = open(sys.argv[1], 'r', + encoding=xsetbg_conf.get("images", "fs_encoding")) xsetbg_db = recreate_db() -count_new = count_old = 0 +count_new = count_old = count_updated = 0 with SQLiteMassInsert() as txn: for line in dump_file: id, timestamp, filename = line.strip().split(None, 2) id = convert_str(id) timestamp = convert_str(timestamp) - filename = filename.decode(fs_encoding) try: if id: row = xsetbg_db.get(id) @@ -47,9 +46,14 @@ with SQLiteMassInsert() as txn: assert id is None or row.id == id if row.last_shown is not None: assert row.last_shown == timestamp - count_old += 1 + if row.full_name == filename: + count_old += 1 + else: + row.full_name = filename + count_updated += 1 dump_file.close() -print "New images:", count_new -print "Existing images:", count_old +print("New images:", count_new) +print("Existing images:", count_old) +print("Updated images:", count_updated)