From: Oleg Broytman Date: Mon, 19 Aug 2024 11:59:11 +0000 (+0300) Subject: Feat(DB): Export/import column `is_image` X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=beb7342fcc8bbfa15140d0c0b75adacf27694a92;p=xsetbg.git Feat(DB): Export/import column `is_image` --- diff --git a/dump_db.py b/dump_db.py index ca3c6a7..e2e6dc3 100755 --- a/dump_db.py +++ b/dump_db.py @@ -15,6 +15,8 @@ if not xsetbg_db: fs_encoding = xsetbg_conf.get("images", "fs_encoding") for row in xsetbg_db.select(orderBy='-last_shown'): sys.stdout.buffer.write( - ('%d %s %s\n' % (row.id, row.last_shown, row.full_name - )).encode(fs_encoding) + ( + '%d %s %d %s\n' % + (row.id, row.last_shown, row.is_image, row.full_name) + ).encode(fs_encoding) ) diff --git a/reload_db.py b/reload_db.py index c12607a..d2b3325 100755 --- a/reload_db.py +++ b/reload_db.py @@ -12,11 +12,11 @@ from xsetbg_conf import xsetbg_conf from xsetbg_db import recreate_db, SQLiteMassInsert -def convert_str(s): +def convert_str(s, convert=int): if s == "None": return None else: - return int(float(s)) + return convert(float(s)) dump_file = open(sys.argv[1], 'r', @@ -26,9 +26,10 @@ 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, timestamp, is_image, filename = line.strip().split(None, 3) id = convert_str(id) timestamp = convert_str(timestamp) + is_image = convert_str(is_image, bool) try: if id: row = xsetbg_db.get(id) @@ -36,7 +37,9 @@ with SQLiteMassInsert() as txn: row = xsetbg_db.byFull_name(filename) except SQLObjectNotFound: values = {'last_shown': timestamp, - 'full_name': filename.encode('utf-8')} + 'full_name': filename.encode('utf-8'), + 'is_image': is_image, + } if id: values['id'] = id query = txn.sqlrepr(Insert(xsetbg_db.sqlmeta.table, values=values)) @@ -51,6 +54,8 @@ with SQLiteMassInsert() as txn: else: row.full_name = filename count_updated += 1 + if row.is_image != is_image: + row.is_image = is_image dump_file.close()