summaryrefslogtreecommitdiffstats
path: root/contrib/secbugstats/bin/fillbugtable.py
blob: 7f991a12d9fe18e22df811cf7bcc9bbfae1bc8bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/python
# Fill the secbugs_Bugs table
# Should not be run regularly as it runs bugdata.py (API script) on every
# bug_id we have stored in the DB.
import sys, MySQLdb, os
from settings import *

if "--debug" in sys.argv:
    DEBUG = True
else:
    DEBUG = False

# set up database connection
db = MySQLdb.connect(host=DB_HOST, user=DB_USER, passwd=DB_PASS, db=DB_NAME)
db.autocommit(True)
cur = db.cursor()

severities = ["sg_critical","sg_high","sg_moderate","sg_low"]

for sev in severities:
    sql = "SELECT d.bug_list FROM secbugs_Details d WHERE d.sid IN (SELECT s.sid FROM secbugs_Stats s WHERE category='%s' and date > '2008-07-01');" % (sev)
    # complete list of bugs for this severity level
    complete = []
    # print "#", sql
    cur.execute(sql)
    row = cur.fetchone()
    while row is not None:
        # row e.g. ('408736,430127',)
        # print "#  ", row
        bugs = row[0].split(",")
        for bug in bugs:
            if len(bug): complete.append(bug)
        row = cur.fetchone()

    unique = list(set(complete))
    print "Going to fetch data for %d %s bugs..." % (len(unique), sev[3:])

    for bug in unique:
        cmd = "%s/bugdata.py %s" % (SCRIPTS_DIR, bug)
        print cmd
        if not DEBUG: os.popen(cmd)