<s> """<STR_LIT>""" <EOL> import datetime <EOL> import os . path <EOL> from . import gmacpyutil <EOL> PLIST_TIMESTAMP_KEY = '<STR_LIT>' <EOL> class Error ( Exception ) : <EOL> """<STR_LIT>""" <EOL> class ErrorReadingPlist ( Error ) : <EOL> """<STR_LIT>""" <EOL> class ErrorWritingPlist ( Error ) : <EOL> """<STR_LIT>""" <EOL> class TimeFile ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , path ) : <EOL> self . timeplist = path <EOL> def ReadTimeFile ( self ) : <EOL> """<STR_LIT>""" <EOL> time_str = gmacpyutil . GetPlistKey ( self . timeplist , PLIST_TIMESTAMP_KEY ) <EOL> if not time_str : <EOL> raise ErrorReadingPlist ( '<STR_LIT>' % <EOL> ( PLIST_TIMESTAMP_KEY , self . timeplist ) ) <EOL> self . stored_time = datetime . datetime . strptime ( time_str , <EOL> '<STR_LIT>' ) <EOL> return self . stored_time <EOL> def WriteTimeFile ( self , timestamp = None ) : <EOL> """<STR_LIT>""" <EOL> if timestamp : <EOL> self . stored_time = timestamp <EOL> else : <EOL> self . stored_time = datetime . datetime . utcnow ( ) <EOL> if not os . path . exists ( os . path . dirname ( self . timeplist ) ) : <EOL> os . mkdir ( os . path . dirname ( self . timeplist ) ) <EOL> timestr = self . stored_time . strftime ( '<STR_LIT>' ) <EOL> if not gmacpyutil . SetPlistKey ( self . timeplist , PLIST_TIMESTAMP_KEY , timestr ) : <EOL> raise ErrorWritingPlist ( '<STR_LIT>' <EOL> % ( PLIST_TIMESTAMP_KEY , self . timeplist ) ) <EOL> return self . stored_time <EOL> def GetOrCreateTimestamp ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . ReadTimeFile ( ) <EOL> except ( ErrorReadingPlist , ValueError ) : <EOL> return self . WriteTimeFile ( ) <EOL> def IsOlderThan ( self , interval ) : <EOL> """<STR_LIT>""" <EOL> return datetime . datetime . utcnow ( ) > ( self . GetOrCreateTimestamp ( ) + interval ) </s>
