def get_status_list(self, filter = None): status_relpath_dict = {} for file in os.listdir(self.destpath): match = re.match('^_status\.([^\.]+)\.json$', file) if match: log.debug('Checking ' + file) instance_name = match.group(1) instance_status_list = [] status_json = open(os.path.join(self.destpath, file)).read().decode('utf-8') if status_json != '': try: instance_status_list = json.loads(status_json) except ValueError as e: raise AppError('Error loading status list. Check that it is a valid json file or remove it. Error = ' + str(e)) #log.warn('Error reading status file (' + file + ') so we will skip it. Error = ' + str(e)) #log.debug('Contents of ' + file + ': ' + status_json) for status in instance_status_list: videofile = VideoFile() videofile.update(status['videofile']) destinationfile = DestinationFile() destinationfile.update(status['destinationfile']) destrelpath = destinationfile.relpath if destrelpath in status_relpath_dict: status_tupl = status_relpath_dict[destrelpath] if destinationfile.timestamp_start > status_tupl[2].timestamp_start: del status_relpath_dict[destrelpath] if destrelpath not in status_relpath_dict: status_relpath_dict[destrelpath] = (instance_name, videofile, destinationfile) if filter is not None: result = [] for tupl in status_relpath_dict.values(): if filter(*tupl): result.append(tupl) return result return status_relpath_dict.values()