# HG changeset patch # User Tero Marttila # Date 1234311703 -7200 # Node ID ebdbda3dd5d00f6239ba6b29ef4e707e376608d7 # Parent 6673de9bc9119b438481e03bf3ddca96627a8758 implement utils.mtime diff -r 6673de9bc911 -r ebdbda3dd5d0 scripts/search-index --- a/scripts/search-index Wed Feb 11 02:16:11 2009 +0200 +++ b/scripts/search-index Wed Feb 11 02:21:43 2009 +0200 @@ -277,19 +277,14 @@ print "reloading all:", # stat for mtime - # XXX: replace with single utils.mtime() - elif os.path.exists(statefile_path) : - # get last update date for channel - mtime = utils.from_utc_timestamp(os.stat(statefile_path).st_mtime) - - if not options.quiet : + else : + # stat for mtime, None if unknown + mtime = utils.mtime(statefile_path, ignore_missing=True) + + if mtime and not options.quiet : print "last load=%s:" % mtime, - else : - # unknown, load all - mtime = None - - if not options.quiet : + elif not options.quiet : print "no previous load state:", # only after some specific date? diff -r 6673de9bc911 -r ebdbda3dd5d0 utils.py --- a/utils.py Wed Feb 11 02:16:11 2009 +0200 +++ b/utils.py Wed Feb 11 02:21:43 2009 +0200 @@ -3,6 +3,7 @@ """ import datetime, calendar, pytz +import os, errno from qmsk.web.urltree import URLType @@ -91,3 +92,25 @@ return calendar.timegm(dt.utctimetuple()) +def mtime (path, ignore_missing=False) : + """ + Gets the mtime for the given path as an UTC datetime, or None, if the file doesn't exist and ignore_missing + """ + + try : + # stat + st = os.stat(path) + + # trap IOError + except os.error, e : + # ENOENT? + if ignore_missing and e.errno == errno.ENOENT : + return None + + else : + raise + + else : + # decode + return from_utc_timestamp(st.st_mtime) +