]> git.phdru.name Git - xsetbg.git/commitdiff
Feat(DB): Export/import column `is_image`
authorOleg Broytman <phd@phdru.name>
Mon, 19 Aug 2024 11:59:11 +0000 (14:59 +0300)
committerOleg Broytman <phd@phdru.name>
Mon, 19 Aug 2024 11:59:11 +0000 (14:59 +0300)
dump_db.py
reload_db.py

index ca3c6a74be70213190721f1940f564607e9eb79a..e2e6dc3a5c0162ba6b010b3647fecda26eeeb309 100755 (executable)
@@ -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)
     )
index c12607a2f3fa00aab5a99748ecdf8ff3968c87d7..d2b33256adc2f721ae3dd1045811d86cc59bd49e 100755 (executable)
@@ -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()