Min (and max?) image dimensions?
-
-
-Rating (likes and dislikes) to show more interestin pictures
-and skip less interesing?
--- /dev/null
+#! /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=<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)
try:
row = xsetbg_db.byFull_name(full_name)
except SQLObjectNotFound:
+ image_and_show = is_image(full_name)
values = {'full_name': full_name,
- 'is_image': is_image(full_name),
+ 'is_image': image_and_show,
'flag': True,
+ 'show': image_and_show,
}
query = txn.sqlrepr(Insert(xsetbg_db.sqlmeta.table,
values=values))
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()
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.")
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()
# 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()
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():