Move maintainers script to python

"A true interpretation is realised when not one line of the original
remains"

Contributors: harryyoud, javelinanddart, luk1337, mccreary, zifnab

Change-Id: Iec07c8a62ec6cb41317c2cdb00db6ae0be73f780
This commit is contained in:
Paul Keith
2017-05-20 08:19:44 +01:00
parent c71ce73624
commit f0ab2a92ae
4 changed files with 83 additions and 118 deletions

View File

@@ -0,0 +1,2 @@
1. Use Python 3.2 or higher
2. `pip3 install -r requirements.txt`

View File

@@ -0,0 +1,80 @@
#!/usr/bin/python3
import yaml
import re
import os
import json
# 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 = 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 = 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 = 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 = 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))
except KeyError:
print("{} doesn't have an install method field".format(codename))

View File

@@ -0,0 +1 @@
pyyaml

View File

@@ -1,118 +0,0 @@
#!/bin/bash
# Run this with no arguments for default functionality
# Run with anything as an argument and all maintainers and devices
# will be printed first, followed by regular functionality
updaterrepolocation="../updater"
wikirepolocation="../wiki"
jenkinsrepolocation="../jenkins"
cverepolocation="../cve"
showallmaintainers=false
if ! [ -z $1 ]; then showallmaintainers=true; fi
if ! [ -d $wikirepolocation ]; then
echo "wiki folder you specified doesn't exist, quitting" 1>&2
exit 1
fi
if ! [ -d $updaterrepolocation ]; then
echo "updater folder you specified doesn't exist, quitting" 1>&2
exit 1
fi
if ! [ -d $jenkinsrepolocation ]; then
echo "jenkins folder you specified doesn't exist, quitting" 1>&2
exit 1
fi
hudsonlist=$(cat $jenkinsrepolocation/lineage-build-targets | cut -f1 -d ' ' | sort | uniq | grep -v '^#' | grep -ve '^$')
# Print list of maintainers if told to
if [ $showallmaintainers == true ]; then
echo "## Maintainers of all devices in hudson according to the wiki:"
for codename in $hudsonlist; do
if [ -f $wikirepolocation/_data/devices/$codename.yml ]; then
wiki_maintainers=$(grep maintainer $wikirepolocation/_data/devices/$codename.yml | cut -d ':' -f2 | awk '{$1=$1};1')
if [[ $wiki_maintainers = *\[\'\'\]* ]]; then
wiki_maintainers="no maintainers"
fi
wiki_maintainers=$(echo $wiki_maintainers | tr -d \[\])
printf "%-15s%-40s\n" "$codename:" "$wiki_maintainers"
fi
done
printf "\n"
fi
# Check if a wiki page exists for each device
echo "## Devices present in hudson, but have no wiki page:"
wikipagefail=0
for codename in $hudsonlist; do
if ! [ -f $wikirepolocation/_data/devices/$codename.yml ]; then
echo $codename
((wikipagefail++))
fi
done
if [ $wikipagefail = 0 ]; then echo "none"; else echo "total = $wikipagefail"; fi
printf "\n"
# Check devices that have a wiki page have maintainers
echo "## Devices present in hudson, but with no maintainers on the wiki:"
wikimaintainerfail=0
for codename in $hudsonlist; do
if [ -f $wikirepolocation/_data/devices/$codename.yml ]; then
WIKI_MAINTAINERS=$(grep maintainer $wikirepolocation/_data/devices/$codename.yml | cut -d ':' -f2 | awk '{$1=$1};1')
if [[ $WIKI_MAINTAINERS = *\[\'\'\]* ]]; then
echo $codename
((wikimaintainerfail++))
fi
unset WIKI_MAINTAINERS
fi
done
if [ $wikimaintainerfail = 0 ]; then echo "none"; else echo "total = $wikimaintainerfail"; fi
printf "\n"
# Check devices that have a wiki page but no install_method
echo "## Devices present in hudson, but with install_method set as TODO on the wiki:"
wikiinstallmethodfail=0
for codename in $hudsonlist; do
if [ -f $wikirepolocation/_data/devices/$codename.yml ]; then
wiki_installmethod=$(grep install_method $wikirepolocation/_data/devices/$codename.yml | cut -d ':' -f2)
if [[ $wiki_installmethod = *TODO* ]]; then
echo $codename
((wikiinstallmethodfail++))
fi
unset wiki_installmethod
fi
done
if [ $wikiinstallmethodfail = 0 ]; then echo "none"; else echo "total = $wikiinstallmethodfail"; fi
printf "\n"
# Check that devices have an update page
echo "## Devices present in hudson, but don't have an update page:"
updaterfail=0
if [ -f $updaterrepolocation/devices.json ]; then
for codename in $hudsonlist; do
if ! grep -q "model\": \"$codename\"" $updaterrepolocation/devices.json; then
echo $codename
((updaterfail++))
fi
done
else
echo "$updaterrepolocation/devices.json doesn't exist"
((updaterfail++))
fi
if [ $updaterfail = 0 ]; then echo "none"; else echo "total = $updaterfail"; fi
printf "\n"
# Check that devices are listed in CVE tracker
echo "## Devices present in hudson, but don't have a kernel listed for them in CVE tracker:"
cvefail=0
if [ -f $cverepolocation/kernels.json ]; then
for codename in $hudsonlist; do
if ! grep -q "android_device_"'.*'"_$codename" $cverepolocation/kernels.json; then
echo $codename
((cvefail++))
fi
done
else
echo "$cverepolocation/kernels.json doesn't exist"
((cvefail++))
fi
if [ $cvefail = 0 ]; then echo "none"; else echo "total = $cvefail"; fi