]> git.phdru.name Git - xsetbg.git/commitdiff
Convert find_oldest.py
authorOleg Broytman <phd@phdru.name>
Tue, 21 Jul 2015 20:31:25 +0000 (23:31 +0300)
committerOleg Broytman <phd@phdru.name>
Tue, 21 Jul 2015 20:31:25 +0000 (23:31 +0300)
find_oldest.py

index f98b4e6d6c051756c996019b40514bb0110dc77a..9b94817ec4ed543a4a7216b59755a373ae42c6c2 100755 (executable)
@@ -1,25 +1,23 @@
 #! /usr/bin/env python
-"""Count shown files; display the date of oldest file
+"""Count all and shown files; display the date of oldest file
 
 This file is a part of XSetBg.
 
 """
 
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2006-2014 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2006-2015 PhiloSoft Design"
 __license__ = "GNU GPL"
 
+import sys
 from time import localtime, asctime
 from xsetbg_db import xsetbg_db
 
-count = 0
-oldest = None
+if not xsetbg_db:
+    sys.exit("Error: no database found")
 
-for key in xsetbg_db.keys():
-   count += 1
-   if key.startswith('/') and ((oldest is None) or (xsetbg_db[key] < oldest)):
-      oldest = xsetbg_db[key]
-xsetbg_db.close()
-
-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))