def list_problems(args): probs = sort_problems(problem.list(auth=args.auth)) if args.since: probs = filter_since_timestamp(probs, args.since) if args.until: probs = filter_until_timestamp(probs, args.until) if args.not_reported: probs = filter_not_reported(probs) if not args.fmt: fmt = config.MEDIUM_FMT else: fmt = args.fmt if args.pretty != 'medium': fmt = getattr(config, '{}_FMT'.format(args.pretty.upper())) out = fmt_problems(probs, fmt=fmt) if out: print(out) else: print(_('No problems'))
def match_get_problem(problem_match, allow_multiple=False, auth=False): ''' Return problem matching `problem_match` pattern or exit if there are no such problems or pattern results in multiple problems (unless `allow_multiple` is set to True). ''' prob = None if problem_match == 'last': probs = sort_problems(problem.list(auth=auth)) if not probs: print(_('No problems')) sys.exit(0) prob = probs[0] else: probs = match_lookup(problem_match, auth=auth) if not probs: print(_('No problem(s) matched')) sys.exit(1) elif len(probs) > 1: if allow_multiple: return probs match_collision(probs) sys.exit(1) else: prob = probs[0] return prob
def test_sort_problems(self): ''' Test if problems are sotred by time ''' pl = problem.list() spl = sort_problems(pl) self.assertTrue(spl[-1] == pl[2]) self.assertTrue(spl[0] == pl[3])
def match_lookup(patterns, authenticate=False, executables=None, components=None, since=None, until=None, n_latest=None, not_reported=False): ''' Return problems that match `in_arg` passed on command line ''' problems = problem.list(auth=authenticate) if not patterns: return sort_problems(problems)[:1] if '*' not in patterns: id_matches = filter_ids(problems, patterns) path_matches = filter_paths(problems, patterns) problems = list(set(id_matches) | set(path_matches)) problems = filter_executables(problems, executables) problems = filter_components(problems, components) if since: problems = filter_since_timestamp(problems, since) if until: problems = filter_until_timestamp(problems, until) if n_latest: problems = sort_problems(problems)[:n_latest] if not_reported: problems = filter_not_reported(problems) return problems