X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;ds=sidebyside;f=rescan_fs.py;h=24302fea4966a2f7259077ac8d24e65813dea435;hb=a0577ff865f17f5988b5192adae263e0ef32b09a;hp=1b74f8f15213a4932f4e5326f134bf60e815183b;hpb=9c73fd456403d1eb1dca034dd1321ae881b689db;p=xsetbg.git diff --git a/rescan_fs.py b/rescan_fs.py index 1b74f8f..24302fe 100755 --- a/rescan_fs.py +++ b/rescan_fs.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 """Rescan filesystem and update database Rescan images directories; remove unknown images from DB; add new images. @@ -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 @@ -49,7 +52,7 @@ NULL = open(os.devnull, 'w') def is_image(full_path): # Run `identify` from ImageMagic; convert retcode to bool - return not subprocess.call(['identify', full_path], + return not subprocess.call(['identify', full_path.encode(fs_encoding)], stdout=NULL, stderr=subprocess.STDOUT) @@ -58,11 +61,13 @@ 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: - values = {'full_name': full_name.encode('utf-8'), + values = {'full_name': full_name, 'is_image': is_image(full_name), 'flag': True, } @@ -82,6 +87,6 @@ with SQLiteMassInsert() as txn: txn.query(query) NULL.close() -print "New images:", count_new -print "Existing images:", count_old -print "Removed images:", count_del +print("New images:", count_new) +print("Existing images:", count_old) +print("Removed images:", count_del)