"""Find outdated tasks""" from __future__ import print_function import errno import json import logging import os import sys from port_stats import lists from port_stats import rpm_ffi from port_stats import tasks from port_stats import utils LOG = logging.getLogger(__name__) def subtask_srpm_nevr(task, subtask_id): try: nevr_file = os.path.join(task['task_path'], 'gears', str(subtask_id), 'nevr') with open(nevr_file, 'r') as f: data = f.read() name, evr = data.strip().split('\t') return name, evr except OSError as e: if e.errno == errno.ENOENT: return None, None except Exception as e: pass LOG.info('Failed to parse subtask NEVR for %s %s', task, subtask_id) return None, None def is_outdated(task, package_evrs): if '/archive/' in task['task_path']: return False for subid, subtask in task['subtasks'].iteritems(): if list(subtask.keys()) == ['userid']: continue if 'srpm' not in subtask: return False name, evr = subtask_srpm_nevr(task, subid) if name is None or evr is None: return False existing_nevr = package_evrs.get(name) if existing_nevr is None: return False task_evr = rpm_ffi.parse_evr(evr) if rpm_ffi.evr_cmp(task_evr, existing_nevr.evr, 'pkg') > 0: return False return True def main(config_path, repo, owner='all'): logging.basicConfig( format='%(asctime)s %(levelname)-5s %(name)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S', stream=sys.stderr, level=logging.INFO) with open(config_path) as f: config = json.load(f) repo_cfg = config['repos'][repo] nevrs = lists.read_srclists(repo_cfg['path'], repo_cfg['arch']) existing = dict((p.name, p) for p in nevrs) task_list = tasks.load_tasks(config['tasks'], repo) outdated = (task for task in task_list if task['repo'] == repo and is_outdated(task, existing)) if owner and owner != 'all': outdated = (task for task in outdated if task['owner'] == owner) for task in outdated: print(tasks.format_task(task)) if __name__ == '__main__': sys.exit(main(*sys.argv[1:]))