From: Oleg Broytman Date: Fri, 20 Dec 2024 15:54:26 +0000 (+0300) Subject: Build: For Python 3.13 SQLObject requires unreleased FormEncode X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;hp=d1e8443a665d4f5f23db32f5ee47d415a5424a04;p=xsetbg.git Build: For Python 3.13 SQLObject requires unreleased FormEncode Install SQLObject and FormEncode from GitHub. --- diff --git a/ChangeLog b/ChangeLog index 80643f1..0b3f0aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Version 5.1.2 (2024-02-25) + + DB: Fix column encoding. + Version 5.1.1 (2024-02-24) Python 3: Fix filesystem encoding. diff --git a/TODO b/TODO index 36a4908..71bd2bf 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,4 @@ -Rating (likes and dislikes) to show more interestin pictures -and skip less interesing. +OSD: Image title on screen. Should be in a real window to stay permanent. Min (and max?) image dimensions? - - -Image title on screen (OSD?). diff --git a/dump_db.py b/dump_db.py index ca3c6a7..de790aa 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 %d %s\n' % + (row.id, row.last_shown, row.is_image, row.show, row.full_name) + ).encode(fs_encoding) ) diff --git a/enable.py b/enable.py new file mode 100755 index 0000000..a1f2d00 --- /dev/null +++ b/enable.py @@ -0,0 +1,77 @@ +#! /usr/bin/env python3 +"""Enable/disable images + +This file is a part of XSetBg. + +""" + +import sys +from getopt import getopt, GetoptError + +from xsetbg_db import xsetbg_db + +if not xsetbg_db: + sys.exit("Error: no database found") + + +def usage(code=0): + sys.stderr.write("Usage: %s [-e|--enable] [-d|--disable] [-c|--clear]" + " [-i|--id=] [filename]\n" % sys.argv[0]) + sys.exit(code) + + +try: + options, arguments = getopt(sys.argv[1:], "edci:", + ["enable", "disable", "clear", + "id="]) +except GetoptError: + usage(1) + +enable = disable = clear = _id = filename = None + +for option, value in options: + if option in ("-e", "--enable"): + enable = True + if option in ("-d", "--disable"): + disable = True + if option in ("-c", "--clear"): + clear = True + if option in ("-i", "--id"): + _id = value + +if arguments: + if len(arguments) == 1: + try: + filename = arguments[0] + except ValueError: + usage(1) + else: + usage(1) + +if int(bool(enable)) + int(bool(disable)) + int(bool(clear)) != 1: + usage(1) + +if int(bool(_id)) + int(bool(filename)) != 1: + usage(1) + +if _id: + rows = list(xsetbg_db.selectBy(id=_id)) + if not rows: + sys.exit("No rows by id %s" % _id) +elif filename: + rows = list(xsetbg_db.selectBy(full_name=filename)) + if not rows: + sys.exit("No rows by filename %s" % filename) +else: + usage(1) + +row = rows[0] + +if enable: + row.show = True +elif disable: + row.show = False +elif clear: + row.show = None +else: + usage(1) diff --git a/print-stats.py b/print-stats.py index fe7cfa5..83fc04d 100755 --- a/print-stats.py +++ b/print-stats.py @@ -15,6 +15,8 @@ if not xsetbg_db: print("Total files:", xsetbg_db.select().count()) print("Images:", xsetbg_db.select('is_image = 1').count()) print("Non-images:", xsetbg_db.select('is_image = 0').count()) +print("Enabled:", xsetbg_db.select('show = 1').count()) +print("Disabled:", xsetbg_db.select('show = 0').count()) print("Unknown:", xsetbg_db.select('is_image IS NULL').count()) print("Shown files:", xsetbg_db.select('last_shown IS NOT NULL').count()) print("Not shown files:", xsetbg_db.select('last_shown IS NULL').count()) diff --git a/reload_db.py b/reload_db.py index c12607a..c6e9b19 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,11 @@ 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, show, filename = line.strip().split(None, 4) id = convert_str(id) timestamp = convert_str(timestamp) + is_image = convert_str(is_image, bool) + show = convert_str(show, bool) try: if id: row = xsetbg_db.get(id) @@ -36,7 +38,10 @@ 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, + 'show': show, + } if id: values['id'] = id query = txn.sqlrepr(Insert(xsetbg_db.sqlmeta.table, values=values)) @@ -51,6 +56,10 @@ with SQLiteMassInsert() as txn: else: row.full_name = filename count_updated += 1 + if row.is_image != is_image: + row.is_image = is_image + if row.show != show: + row.show = show dump_file.close() diff --git a/rescan_fs.py b/rescan_fs.py index 9688de9..b8284a9 100755 --- a/rescan_fs.py +++ b/rescan_fs.py @@ -67,9 +67,11 @@ with SQLiteMassInsert() as txn: try: row = xsetbg_db.byFull_name(full_name) except SQLObjectNotFound: - values = {'full_name': full_name.encode('utf-8'), - 'is_image': is_image(full_name), + image_and_show = is_image(full_name) + values = {'full_name': full_name, + 'is_image': image_and_show, 'flag': True, + 'show': image_and_show, } query = txn.sqlrepr(Insert(xsetbg_db.sqlmeta.table, values=values)) @@ -77,7 +79,8 @@ with SQLiteMassInsert() as txn: count_new += 1 else: if row.is_image is None: - row.is_image = is_image(full_name) + row.is_image = image_and_show = is_image(full_name) + row.show = image_and_show row.flag = True count_old += 1 count_del = xsetbg_db.select('flag IS NULL').count() diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..6b02812 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,14 @@ +[bdist_wheel] +universal = 1 + +[easy_install] +optimize = 2 + +[egg_info] +tag_build = +tag_date = 0 +tag_svn_revision = 0 + +[flake8] +exclude = .git + diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..1ed3e65 --- /dev/null +++ b/setup.py @@ -0,0 +1,44 @@ +#! /usr/bin/env python + +from setuptools import setup + +setup( + name = "xsetbg", + version = "5.1.2", + description = "XSetBg - set X background", + long_description=open('README.txt', 'r').read(), + long_description_content_type="text/plain", + author = "Oleg Broytman", + author_email = "phd@phdru.name", + license = "GPL", + classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'Environment :: No Input/Output (Daemon)', + 'Environment :: X11 Applications', + 'Intended Audience :: End Users/Desktop', + 'License :: OSI Approved :: GNU General Public License (GPL)', + 'Operating System :: OS Independent', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + ], + platforms = "POSIX", + python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*', + install_requires=[ + 'SQLObject>=2.2.1; python_version=="2.7"', + 'SQLObject>=3.0.0; python_version>="3.4" and python_version<="3.12"', + "SQLObject @ " + "git+https://github.com/sqlobject/sqlobject.git#egg=sqlobject" + " ; python_version >= '3.13'", + 'm_lib.defenc>=1.1', + ], +) diff --git a/xsetbg.py b/xsetbg.py index 825b20e..db2f2d0 100644 --- a/xsetbg.py +++ b/xsetbg.py @@ -73,7 +73,7 @@ else: if xsetbg_db.select( - '(is_image = 1) AND (last_shown IS NULL OR last_shown < %d)' % + '(is_image = 1) AND show AND (last_shown IS NULL OR last_shown < %d)' % (time() - min_delay)).count() == 0: error("No unshown images found. Run rescan_fs.py " "or decrease min_delay. Abort.") @@ -94,7 +94,7 @@ def change(force=False): try: timestamp = xsetbg_db.select( - '(is_image = 1) AND (last_shown IS NOT NULL)', + '(is_image = 1) AND show AND (last_shown IS NOT NULL)', orderBy='-last_shown')[0].last_shown current_time = time() @@ -105,13 +105,13 @@ def change(force=False): # Select a random image that has never been shown not_shown_select = xsetbg_db.select( - '(is_image = 1) AND (last_shown IS NULL)') + '(is_image = 1) AND show AND (last_shown IS NULL)') not_shown_count = not_shown_select.count() if not_shown_count: row = not_shown_select[random.randint(0, not_shown_count - 1)] else: old_shown_select = xsetbg_db.select( - '(is_image = 1) AND ' + '(is_image = 1) AND show AND ' '(last_shown IS NOT NULL AND last_shown < %d)' % current_time - min_delay) old_shown_count = old_shown_select.count() diff --git a/xsetbg_db.py b/xsetbg_db.py index ba5ab6c..638ce49 100755 --- a/xsetbg_db.py +++ b/xsetbg_db.py @@ -19,10 +19,12 @@ class XSetBg(SQLObject): last_shown = IntCol(default=None) # timestamp flag = BoolCol(default=None) is_image = BoolCol(default=None) + show = BoolCol(default=True) last_shown_idx = DatabaseIndex('last_shown') flag_idx = DatabaseIndex('flag') is_image_idx = DatabaseIndex('is_image') + show_idx = DatabaseIndex('show') def recreate_db():