2 """Reload a dump into DB
4 This file is a part of XSetBg.
8 __author__ = "Oleg Broytman <phd@phdru.name>"
9 __copyright__ = "Copyright (C) 2007-2015 PhiloSoft Design"
10 __license__ = "GNU GPL"
13 from sqlobject import SQLObjectNotFound, sqlhub
14 from sqlobject.sqlbuilder import Insert
15 from xsetbg_conf import xsetbg_conf
16 from xsetbg_db import SqliteSequence, XSetBg, xsetbg_db
18 fs_encoding = xsetbg_conf.get("images", "fs_encoding")
19 dump_file = open(sys.argv[1], 'rU')
23 seq = SqliteSequence.byName(XSetBg.sqlmeta.table)
24 except SQLObjectNotFound:
25 SqliteSequence(name=XSetBg.sqlmeta.table, seq=0)
27 seq.seq = 0 # Reset autoincrement counter
28 xsetbg_db.clearTable()
31 xsetbg_db.createTable()
39 connection = xsetbg_db._connection
41 connection.query("PRAGMA synchronous=OFF")
42 connection.query("PRAGMA count_changes=OFF")
43 connection.query("PRAGMA journal_mode=MEMORY")
44 connection.query("PRAGMA temp_store=MEMORY")
46 txn = connection.transaction()
47 sqlhub.processConnection = txn
49 for line in dump_file:
50 id, timestamp, filename = line.strip().split(None, 2)
52 timestamp = convert_str(timestamp)
53 if fs_encoding != 'utf-8':
54 filename = filename.decode(fs_encoding).encode('utf-8')
55 values = {'last_shown': timestamp, 'full_name': filename}
58 query = txn.sqlrepr(Insert(XSetBg.sqlmeta.table, values=values))
62 sqlhub.processConnection = connection