mirror of
git://git.yoctoproject.org/yocto-autobuilder-helper.git
synced 2025-07-19 20:59:02 +02:00
62 lines
2.4 KiB
Python
Executable File
62 lines
2.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import json, os.path, collections
|
|
import sys
|
|
import argparse
|
|
import subprocess
|
|
import tempfile
|
|
|
|
args = argparse.ArgumentParser(description="Update Patch Metrics")
|
|
args.add_argument("-j", "--json", help="update JSON")
|
|
args.add_argument("-m", "--metadata", help="metadata directry to scan")
|
|
args.add_argument("-s", "--patchscript", help="review script to use")
|
|
args.add_argument("-r", "--repo", help="repository to use")
|
|
args = args.parse_args()
|
|
|
|
status_values = ["accepted", "pending", "inappropriate", "backport", "submitted", "denied", "inactive-upstream", "malformed-upstream-status", "malformed-sob"]
|
|
|
|
with tempfile.TemporaryDirectory(prefix="patchmetrics-") as tempdir:
|
|
subprocess.check_call(["git", "clone", args.repo, tempdir])
|
|
repo_revisions = subprocess.check_output(["git", "rev-list", "--since", "1274625106", "origin/master"], universal_newlines=True, cwd=tempdir).strip().split()
|
|
|
|
with open(args.json) as f:
|
|
data = json.load(f)
|
|
|
|
seen = set()
|
|
for i in data:
|
|
if "commit" in i:
|
|
seen.add(i["commit"])
|
|
|
|
needed_revisions = set(repo_revisions) - seen
|
|
|
|
print("Need to scan revisions %s" % str(needed_revisions))
|
|
|
|
print("Needed %s revsisions (%s in data set)" % (len(needed_revisions), len(seen)))
|
|
|
|
for rev in needed_revisions:
|
|
print("Processing %s" % rev)
|
|
subprocess.check_output(["git", "reset", "--hard", rev], universal_newlines=True, cwd=tempdir).strip()
|
|
subprocess.check_call([args.patchscript, os.path.join(tempdir, os.path.relpath(args.metadata, args.repo)), "-j", args.json])
|
|
|
|
newdata = []
|
|
with open(args.json) as f:
|
|
data = json.load(f)
|
|
|
|
for i in data:
|
|
if "commit" not in i:
|
|
print("Ignoring data with no commit %s" % str(i))
|
|
continue
|
|
|
|
if "commit_count" not in i:
|
|
i['commit_count'] = subprocess.check_output(["git", "rev-list", "--count", i['commit']], universal_newlines=True, cwd=tempdir).strip()
|
|
if "recipe_count" not in i:
|
|
subprocess.check_output(["git", "reset", "--hard", i['commit']], universal_newlines=True, cwd=tempdir).strip()
|
|
i['recipe_count'] = subprocess.check_output(["find meta -type f -name *.bb | wc -l"], shell=True, universal_newlines=True, cwd=tempdir).strip()
|
|
|
|
#print(i['commit_count'] + " " + i['recipe_count'])
|
|
|
|
newdata.append(i)
|
|
|
|
with open(args.json, "w") as f:
|
|
json.dump(newdata, f, sort_keys=True, indent="\t")
|
|
|