--- 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)
+