]> git.phdru.name Git - xsetbg.git/blobdiff - find_oldest.py
Fix a bug: id can be None
[xsetbg.git] / find_oldest.py
index df79432bcf0bc34e1d88fe28335631659724bccd..9b94817ec4ed543a4a7216b59755a373ae42c6c2 100755 (executable)
@@ -1,35 +1,23 @@
-#! /usr/local/bin/python -O
-"""Count shown files; display the date of oldest file
+#! /usr/bin/env python
+"""Count all and shown files; display the date of oldest file
 
 This file is a part of XSetBg.
 
 """
 
-__version__ = "$Revision$"[11:-2]
-__revision__ = "$Id$"[5:-2]
-__date__ = "$Date$"[7:-2]
-
-__author__ = "Oleg BroytMann <phd@phd.pp.ru>"
-__copyright__ = "Copyright (C) 2006 PhiloSoft Design"
+__author__ = "Oleg Broytman <phd@phdru.name>"
+__copyright__ = "Copyright (C) 2006-2015 PhiloSoft Design"
 __license__ = "GNU GPL"
 
-import os, shelve
+import sys
 from time import localtime, asctime
+from xsetbg_db import xsetbg_db
 
-xsetbg_dir = os.path.join(os.environ["HOME"], "lib", "xsetbg")
-os.chdir(xsetbg_dir)
-
-global_db_name = "xsetbg.db"
-
-count = 0
-oldest = None
-
-global_db = shelve.open(global_db_name, flag='r')
-for key in global_db.keys():
-   count += 1
-   if key.startswith('/') and ((oldest is None) or (global_db[key] < oldest)):
-      oldest = global_db[key]
-global_db.close()
+if not xsetbg_db:
+    sys.exit("Error: no database found")
 
-print count, "files"
-print "Oldest:", asctime(localtime(oldest))
+print "Total files:", xsetbg_db.select().count()
+print "Shown files:", xsetbg_db.select('last_shown IS NOT NULL').count()
+last_shown = xsetbg_db.select('last_shown IS NOT NULL',
+                              orderBy='last_shown')[0].last_shown
+print "Oldest:", asctime(localtime(last_shown))