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 m_lib.defenc import default_encoding
16 from xsetbg_db import SqliteSequence, XSetBg, xsetbg_db
18 dump_file = open(sys.argv[1], 'rU')
22 seq = SqliteSequence.byName(XSetBg.sqlmeta.table)
23 except SQLObjectNotFound:
24 SqliteSequence(name=XSetBg.sqlmeta.table, seq=0)
26 seq.seq = 0 # Reset autoincrement counter
27 xsetbg_db.clearTable()
30 xsetbg_db.createTable()
38 connection = xsetbg_db._connection
40 connection.query("PRAGMA synchronous=OFF")
41 connection.query("PRAGMA count_changes=OFF")
42 connection.query("PRAGMA journal_mode=MEMORY")
43 connection.query("PRAGMA temp_store=MEMORY")
45 txn = connection.transaction()
46 sqlhub.processConnection = txn
48 for line in dump_file:
49 id, timestamp, filename = line.strip().split(None, 2)
51 timestamp = convert_str(timestamp)
52 if default_encoding != 'utf-8':
53 filename = filename.decode(default_encoding).encode('utf-8')
54 values = {'last_shown': timestamp, 'full_name': filename}
57 query = txn.sqlrepr(Insert(XSetBg.sqlmeta.table, values=values))
61 sqlhub.processConnection = connection