utils.py
changeset 95 ebdbda3dd5d0
parent 89 2dc6de43f317
child 115 751e3fcd11d2
equal deleted inserted replaced
94:6673de9bc911 95:ebdbda3dd5d0
     1 """
     1 """
     2     Miscellaneous things
     2     Miscellaneous things
     3 """
     3 """
     4 
     4 
     5 import datetime, calendar, pytz
     5 import datetime, calendar, pytz
       
     6 import os, errno
     6 
     7 
     7 from qmsk.web.urltree import URLType
     8 from qmsk.web.urltree import URLType
     8 
     9 
     9 class URLChannelName (URLType) :
    10 class URLChannelName (URLType) :
    10     """
    11     """
    89         Converts a datetime.datetime into a UNIX timestamp
    90         Converts a datetime.datetime into a UNIX timestamp
    90     """
    91     """
    91 
    92 
    92     return calendar.timegm(dt.utctimetuple())
    93     return calendar.timegm(dt.utctimetuple())
    93 
    94 
       
    95 def mtime (path, ignore_missing=False) :
       
    96     """
       
    97         Gets the mtime for the given path as an UTC datetime, or None, if the file doesn't exist and ignore_missing
       
    98     """
       
    99 
       
   100     try :
       
   101         # stat
       
   102         st = os.stat(path)
       
   103     
       
   104     # trap IOError
       
   105     except os.error, e :
       
   106         # ENOENT?
       
   107         if ignore_missing and e.errno == errno.ENOENT :
       
   108             return None
       
   109 
       
   110         else :
       
   111             raise
       
   112 
       
   113     else :
       
   114         # decode
       
   115         return from_utc_timestamp(st.st_mtime)
       
   116