Files
scripts/maintainer-checks/maintainers.py
Paul Keith 246892130f maintainers-checks: Use elif to check 'dd' install method
* If a device doesn't have a valid install method,
  there's no point in checking if it has 'dd' as
  the install method, it won't match up anyways
* This has no visible impact on the time of running
  this script, but the logic is now better

Change-Id: I204903db40f02fe1ff837ed6feb8d06ace86cc92
2017-06-04 17:48:22 -05:00

119 lines
4.0 KiB
Python
Executable File

#!/usr/bin/python3
import yaml
import re
import os
import json
import argparse
mydir = os.path.dirname(os.path.abspath(__file__))
parser = argparse.ArgumentParser()
parser.add_argument('-m', '--maintainers', help='list maintainers for devices', action='store_true', required=False)
args = parser.parse_args()
# Paths to certain repos
repo = {
"updater": "../../updater",
"wiki": "../../wiki",
"hudson": "../../jenkins",
"cve": "../../cve"
}
# List of all codenames in hudson
codenames = []
# List of devices in cve tracker
cve_entries = []
# List of devices with updater pages
updater_pages = []
# Open file and input lines as items in list
hudson_file = os.path.join(mydir, repo["hudson"] + "/lineage-build-targets")
with open(hudson_file) as f:
for line in f:
# Ignore blank lines or lines with comments
if re.match(r"^\s*$", line) or re.match(r"#", line):
continue
# Add codenames to list
codenames.append(re.sub(r" .*", "", line.strip()))
# Sort codenames alphabetically
codenames.sort()
# Create list of devices in cve tracker
cve_json_file = os.path.join(mydir, repo["cve"] + "/kernels.json")
with open(cve_json_file) as f:
json_file = json.load(f)
for kernel in json_file:
for device in json_file[kernel]:
device = re.sub(r"android_device_[a-zA-Z0-9]*_", "", device)
cve_entries.append(device)
# CVE tracker checking
for codename in codenames:
if codename not in cve_entries:
print("{} doesn't have an entry in the CVE tracker".format(codename))
# Create list of updater pages
updater_json_file = os.path.join(mydir, repo["updater"] + "/devices.json")
with open(updater_json_file) as f:
json_file = json.load(f)
for device in json_file:
updater_pages.append(device["model"])
# Updater checking
for codename in codenames:
if codename not in updater_pages:
print("{} doesn't have an updater page".format(codename))
# Wiki checking
for codename in codenames:
wiki_yml_file = os.path.join(mydir, repo["wiki"] + "/_data/devices/" + codename + ".yml")
if not os.path.isfile(wiki_yml_file):
print("{} doesn't have a wiki page".format(codename))
continue
with open(wiki_yml_file) as f:
yml = yaml.load(f)
try:
if not yml["maintainers"]:
print("{} doesn't have a maintainer listed".format(codename))
except KeyError:
print("{} doesn't have a maintainers field".format(codename))
try:
if not yml["install_method"] or "TODO" in yml["install_method"]:
print("{} doesn't have an install method listed".format(codename))
elif "dd" in yml["install_method"]:
try:
if not yml["recovery_partition"]:
print("{} doesn't have a recovery partition listed".format(codename))
except KeyError:
print("{} doesn't have a recovery partition field".format(codename))
try:
if not yml["root_method"]:
print("{} doesn't have a root method listed".format(codename))
except KeyError:
print("{} doesn't have a root method field".format(codename))
except KeyError:
print("{} doesn't have an install method field".format(codename))
# Optionally print out all maintainer info
if args.maintainers:
print("---------------MAINTAINER INFO DUMP---------------")
for codename in codenames:
wiki_yml_file = os.path.join(mydir, repo["wiki"] + "/_data/devices/" + codename + ".yml")
toprint = "{}:".format(codename)
if not os.path.isfile(wiki_yml_file):
# Skip devices without wiki pages, we already errored about it
continue
with open(wiki_yml_file) as f:
yml = yaml.load(f)
try:
for maintainer in yml["maintainers"]:
toprint += ", {}".format(maintainer)
except KeyError:
# Skip devices without maintainer fields, we already errored about it
continue
print(toprint.replace(":,", ":"))