#! /usr/local/bin/python -O
"""Set a random background image (XWin)
-Select a random image from $HOME/lib/xsetbg/images subdirectories
-and set it as the desktop wallpaper (display it in the root window).
+Select a random image from a (list of) directory(s)
+and set it as the desktop wallpaper (display it in the root window)
+using xli or xsetbg programs.
"""
global_db_name = "xsetbg.db"
+# DB keys
+timestamp_key = "timestamp"
+filename_key = "filename"
+old_filename_key = "old_filename"
+
+
import random
import anydbm, shelve
from time import time
os.remove(global_db_name)
global_db = shelve.open(global_db_name, flag='c')
-global_db.close() # Close DB in parent process
+# Remove old filenames
+old_time = time() - min_delay
+to_delete = [timestamp_key]
+for key in global_db.keys():
+ if key.startswith('/') and global_db[key] < old_time:
+ to_delete.append(key)
-# DB keys
-timestamp_key = "timestamp"
-filename_key = "filename"
-old_filename_key = "old_filename"
+for key in to_delete:
+ del global_db[key]
+
+global_db.close() # Close DB in the parent process
images = []