def load(self): timestamp = None try: timestamp = resource_timestamp(self.filename) self.result = load_dictionary(self.filename) except Exception as e: log.debug('loading dictionary %s failed', self.filename, exc_info=True) self.result = DictionaryLoaderException(self.filename, e) self.result.timestamp = timestamp
def load(cls, resource): filename = resource_filename(resource) timestamp = resource_timestamp(filename) d = cls() d._load(filename) if resource.startswith(ASSET_SCHEME): d.readonly = True d.path = resource d.timestamp = timestamp return d
def save(self): assert not self.readonly filename = resource_filename(self.path) # Write the new file to a temp location. tmp = filename + '.tmp' self._save(tmp) timestamp = resource_timestamp(tmp) # Then move the new file to the final location. shutil.move(tmp, filename) # And update our timestamp. self.timestamp = timestamp
def load(cls, resource): filename = resource_filename(resource) timestamp = resource_timestamp(filename) d = cls() d._load(filename) if (cls.readonly or resource.startswith(ASSET_SCHEME) or not os.access(filename, os.W_OK)): d.readonly = True d.path = resource d.timestamp = timestamp return d
def needs_reloading(self): try: new_timestamp = resource_timestamp(self.filename) except: # Bad resource name, permission denied, path # does not exist, ... new_timestamp = None # If no change in timestamp: don't reload. if new_timestamp == self.result.timestamp: return False # If we could not get the new timestamp: # the dictionary is not available anymore, # attempt to reload to notify the user. if new_timestamp is None: return True # If we're here, and no previous timestamp exists, # then the file was previously inaccessible, reload. if self.result.timestamp is None: return True # Otherwise, just compare timestamps. return self.result.timestamp < new_timestamp
def save(self): assert not self.readonly with resource_update(self.path) as temp_path: self._save(temp_path) self.timestamp = resource_timestamp(self.path)