class Updater(object): """Updates the shadow database and allows hand-correction of image ID synchronization.""" reader = None """reader instance""" shadow = None """persistence instance""" # String -> Updater def __init__(self, kpadir, shadow_path): """Takes the location of the KPA root directory and a relative path to the shadow DB.""" db_path = os.path.abspath(os.path.join(kpadir, shadow_path)) self.shadow = Shadow(db_path) self.reader = Reader(kpadir) # -> Boolean def update(self, force=False): """Update database and resolve any created, deleted, moved, or edited files. Does not update if index file has not changed and force=False (default). Returns boolean indicating whether an update was performed.""" new_checksum = self.reader.get_checksum() # will need either way if force: need_update = True else: old_checksum = self.shadow.get_checksum() need_update = old_checksum != new_checksum if not need_update: return False data = self.reader.read_latest_data() # imageID:None self.shadow.apply_latest_data(data, new_checksum) return True