yocto-autobuilder-helper/scripts/cve-generate-chartdata
Richard Purdie 3f489eb396 cve-generate-chartdata: Exclude linux-yocto for old release branches for now
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2023-03-31 17:20:15 +01:00

2.1 KiB
Executable File

#!/usr/bin/env python3 import json, os.path, collections import sys import argparse import subprocess import tempfile from datetime import datetime, date, timedelta

args = argparse.ArgumentParser(description="Generate CVE count data files") args.add_argument("-j", "--json", help="JSON data file to use") args.add_argument("-r", "--resultsdir", help="results directory to parse") args = args.parse_args()

with open(args.json) as f: counts = json.load(f)

lastyear = {}

Write CVE counts by day

def round_to_day(val): return int((datetime.fromtimestamp(int(val)).date() - date(1970, 1, 1)).total_seconds())

a_year_ago = (datetime.now() - timedelta(days=365) - datetime(1970, 1, 1)).total_seconds()

for branch in os.listdir(args.resultsdir): branchdir = os.path.join(args.resultsdir, branch) for f in os.listdir(branchdir): ts = f.split(".")[0] rounded_ts = str(round_to_day(ts)) if rounded_ts not in counts: counts[rounded_ts] = {} if branch not in counts[rounded_ts]: cvereport = os.path.join(branchdir, f) with open(cvereport) as report: reportdata = json.load(report) count = 0 seen = [] for package in reportdata['package']: if branch in ['dunfell', 'kirkstone', 'langdale'] and if package['name'] in ['linux-yocto']: continue for issue in package['issue']: if issue['status'] == "Unpatched" and issue['id'] not in seen: count = count + 1 seen.append(issue['id']) print("Adding count %s for branch %s from file %s (ts %s)" % (count, branch, cvereport, rounded_ts)) counts[rounded_ts][branch] = str(count)

for c in counts: if int(c) > a_year_ago: lastyear[c] = counts[c]

with open(args.json, "w") as f: json.dump(counts, f, sort_keys=True, indent="\t")

with open(args.json.replace(".json", "-lastyear.json") , "w") as f: json.dump(lastyear, f, sort_keys=True, indent="\t")