blob: 2f7eb96b85b379264a401013ced33783684f7ca8 [file] [log] [blame]
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# Copyright 2018 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Local cache generator for syzbot-autotriager."""
from __future__ import print_function
import argparse
import os
import subprocess
import sys
import tempfile
import config
import git
import issuetracker
import simpledb
import syzweb
def fetch_it(hotlistid):
"""Uses Issuetracker to fetch bugs from a specific |hotlistid|."""
b = issuetracker.Issuetracker(hotlistid)
def fetch_commits():
"""Uses Gitlog to fetch and cache commits from various kernels."""
dbs = (
config.SRC_LINUX_DB, config.SRC_V414_DB, config.SRC_V44_DB,
config.SRC_V318_DB, config.SRC_V314_DB, config.SRC_V310_DB,
tfiles = [tempfile.NamedTemporaryFile() for _ in xrange(len(dbs))]
env = os.environ.copy()
env.update({'TFILE_%d' % (i): for i, tfile in enumerate(tfiles)})
env['CROS_ROOT'] = os.path.expanduser(config.CROS_ROOT)
env['LINUX'] = os.path.expanduser(config.LINUX)
env['LINUXSTABLE'] = os.path.expanduser(config.LINUX_STABLE)
subprocess.check_call(['./'], env=env)
for tfile, dbname in zip(tfiles, dbs):
g = git.Gitlog(, dbname=dbname)
for f in tfiles:
def fetch_syzweb():
"""Uses SyzkallerWeb to fetch and cache info from"""
sw = syzweb.SyzkallerWeb()
def get_parser():
"""Create and return an ArgumentParser instance."""
parser = argparse.ArgumentParser(description=__doc__)
type=str, dest='hotlistid',
help='fetch all bugs from issuetracker and cache them '
parser.add_argument('--commits', action='store_true',
help='fetch all commits from various git '
'repositories and cache them locally')
parser.add_argument('--syzweb', action='store_true',
help='fetch all fixes from '
'and cache them locally')
parser.add_argument('--fetchall', action='store_true',
help='equivalent of --it[HOTLISTID] --commits --syzweb')
parser.add_argument('--list', action='store_true',
help='list the number of records in each local cache')
return parser
def main(argv):
parser = get_parser()
opts = parser.parse_args(argv)
if opts.fetchall or opts.hotlistid:
if not opts.hotlistid:
parser.error('No HOTLISTID provided')
return 1
if opts.fetchall or opts.commits:
print('[+] Fetching commits')
if opts.fetchall or opts.syzweb:
print('[+] Fetching syzweb issues')
if opts.list:
nodb = True
for db in (config.ISSUETRACKER_DB, config.SYZWEB_DB,
config.SRC_LINUX_DB, config.SRC_V414_DB, config.SRC_V44_DB,
config.SRC_V318_DB, config.SRC_V314_DB, config.SRC_V310_DB,
if not os.path.exists(db):
nodb = False
s = simpledb.SimpleDB(db)
print('[+] %s found with %d records' % (db, s.count()))
print('[x] No local caches found' if nodb else '')
if not (opts.hotlistid or opts.commits or opts.syzweb or opts.fetchall or
parser.error('No options selected')
return 1
return 0
if __name__ == '__main__':