1 #! /usr/bin/env python3
2 """Reload a dump into DB
4 This file is a part of XSetBg.
9 from sqlobject import SQLObjectNotFound
10 from sqlobject.sqlbuilder import Insert
11 from xsetbg_conf import xsetbg_conf
12 from xsetbg_db import recreate_db, SQLiteMassInsert
22 dump_file = open(sys.argv[1], 'r',
23 encoding=xsetbg_conf.get("images", "fs_encoding"))
24 xsetbg_db = recreate_db()
25 count_new = count_old = count_updated = 0
27 with SQLiteMassInsert() as txn:
28 for line in dump_file:
29 id, timestamp, filename = line.strip().split(None, 2)
31 timestamp = convert_str(timestamp)
34 row = xsetbg_db.get(id)
36 row = xsetbg_db.byFull_name(filename)
37 except SQLObjectNotFound:
38 values = {'last_shown': timestamp,
39 'full_name': filename.encode('utf-8')}
42 query = txn.sqlrepr(Insert(xsetbg_db.sqlmeta.table, values=values))
46 assert id is None or row.id == id
47 if row.last_shown is not None:
48 assert row.last_shown == timestamp
49 if row.full_name == filename:
52 row.full_name = filename
57 print("New images:", count_new)
58 print("Existing images:", count_old)
59 print("Updated images:", count_updated)