Beispiel #1
0
def test_round_robin():
    db = Database()
    db.bugs.update(EXPECTED_BUGS)
    data = io.StringIO()
    db.save(data)
    data.seek(0)
    db2 = Database()
    db2.load(data)
    assert db2.bugs == EXPECTED_BUGS
Beispiel #2
0
def main() -> int:
    """CLI interface for kuroneko scraper."""
    argp = argparse.ArgumentParser()
    argp.add_argument('-l', '--limit', type=int,
                      help='Limit the results to LIMIT bugs')
    argp.add_argument('-o', '--output', default='-',
                      help='Output JSON file (default: - = stdout)')
    argp.add_argument('-q', '--quiet', action='store_true',
                      help='Disable status output')
    argp.add_argument('-X', '--exclude-file', type=argparse.FileType(),
                      help='File to read list of excluded bugs from')
    args = argp.parse_args()

    if args.output == '-':
        output = sys.stdout
    else:
        output = open(args.output, 'w')
    exclude: typing.List[int] = []
    if args.exclude_file is not None:
        for line in args.exclude_file:
            line = line.strip()
            if line.startswith('#'):
                continue
            exclude.extend(int(x) for x in line.split())
    exclude_set = frozenset(exclude)

    db = Database()
    for i, bug in enumerate(find_security_bugs(limit=args.limit)):
        if bug.id in exclude_set:
            continue
        packages = sorted(split_version_ranges(
            find_package_specs(bug.summary)))
        # skip bugs with no packages
        if not packages:
            continue
        # skip RESO/INVALID bugs
        if bug.resolution == 'INVALID':
            continue
        # skip resolved bugs without specific version ranges
        resolved = bug.resolution != ''
        if resolved and not all(p[0] in '<>~=' for p
                                in itertools.chain.from_iterable(packages)):
            continue
        db.add_bug(bug=bug.id,
                   packages=packages,
                   summary=bug.summary,
                   severity=get_severity(bug.whiteboard),
                   created=bug.creation_time.split('T', 1)[0],
                   resolved=resolved)
    if not args.quiet:
        print(f'Found {i+1} bugs', file=sys.stderr)
    db.save(output)

    return 0