]> git.phdru.name Git - xsetbg.git/commitdiff
Fix(py3): Fix encodings
authorOleg Broytman <phd@phdru.name>
Sat, 24 Feb 2024 15:21:27 +0000 (18:21 +0300)
committerOleg Broytman <phd@phdru.name>
Sat, 24 Feb 2024 15:21:27 +0000 (18:21 +0300)
dump_db.py
print-filename.py
reload_db.py
rescan_fs.py

index 470ff0a06c9120de7ad72667ac0bc18017ba9a22..ca3c6a74be70213190721f1940f564607e9eb79a 100755 (executable)
@@ -6,11 +6,15 @@ This file is a part of XSetBg.
 """
 
 import sys
-from m_lib.defenc import default_encoding
+from xsetbg_conf import xsetbg_conf
 from xsetbg_db import xsetbg_db
 
 if not xsetbg_db:
     sys.exit("Error: no database found")
 
+fs_encoding = xsetbg_conf.get("images", "fs_encoding")
 for row in xsetbg_db.select(orderBy='-last_shown'):
-    print(row.id, row.last_shown, row.full_name.encode(default_encoding))
+    sys.stdout.buffer.write(
+        ('%d %s %s\n' % (row.id, row.last_shown, row.full_name
+                         )).encode(fs_encoding)
+    )
index d5413976761bfc625c54d780de2e8654b6d2c8b6..e9f217b75b46920f4561b72ce29c0ac6dfcd0cf8 100755 (executable)
@@ -58,4 +58,4 @@ index, output_encoding = get_args()
 filename = xsetbg_db.select('last_shown IS NOT NULL',
                             orderBy='-last_shown')[index].full_name
 
-print(filename.encode(output_encoding))
+sys.stdout.buffer.write(filename.encode(output_encoding) + b'\n')
index ffa0013b7b2803f7e850c8de6b62fb2dac0b74f8..c12607a2f3fa00aab5a99748ecdf8ff3968c87d7 100755 (executable)
@@ -19,17 +19,16 @@ def convert_str(s):
         return int(float(s))
 
 
-dump_file = open(sys.argv[1], 'r')
+dump_file = open(sys.argv[1], 'r',
+                 encoding=xsetbg_conf.get("images", "fs_encoding"))
 xsetbg_db = recreate_db()
 count_new = count_old = count_updated = 0
-fs_encoding = xsetbg_conf.get("images", "fs_encoding")
 
 with SQLiteMassInsert() as txn:
     for line in dump_file:
         id, timestamp, filename = line.strip().split(None, 2)
         id = convert_str(id)
         timestamp = convert_str(timestamp)
-        filename = filename.decode(fs_encoding)
         try:
             if id:
                 row = xsetbg_db.get(id)
index 0abed44c1b3feaec860317f64ee930138570ac05..346f92b28f387c3434731ec9d0e19e4949955aa2 100755 (executable)
@@ -9,8 +9,11 @@ This file is a part of XSetBg.
 
 import os
 import subprocess
+
 from sqlobject import SQLObjectNotFound
 from sqlobject.sqlbuilder import Insert, Update, Delete
+from m_lib.defenc import default_encoding
+
 from xsetbg_conf import xsetbg_dir, xsetbg_conf
 from xsetbg_db import recreate_db, SQLiteMassInsert
 
@@ -58,7 +61,9 @@ with SQLiteMassInsert() as txn:
         # List images in all subdirectories
         for dirpath, dirs, files in os.walk(image_dir):
             for file in files:
-                full_name = os.path.join(dirpath, file).decode(fs_encoding)
+                if default_encoding != fs_encoding:
+                    file = file.encode().decode(fs_encoding)
+                full_name = os.path.join(dirpath, file)
                 try:
                     row = xsetbg_db.byFull_name(full_name)
                 except SQLObjectNotFound: