Created
July 15, 2016 22:31
-
-
Save jongrimm/80c246d2d6c04fda5b5d8df49c52be1f to your computer and use it in GitHub Desktop.
first stab at adding team responsibility mapping to Ryan's merges2csv script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (C) 2013 Canonical Ltd. | |
# | |
# Author: Ryan Harper <ryan.harper@canonical.com> | |
# | |
# Curtin is free software: you can redistribute it and/or modify it under | |
# the terms of the GNU Affero General Public License as published by the | |
# Free Software Foundation, either version 3 of the License, or (at your | |
# option) any later version. | |
# | |
# Curtin is distributed in the hope that it will be useful, but WITHOUT ANY | |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for | |
# more details. | |
# | |
# You should have received a copy of the GNU Affero General Public License | |
# along with Curtin. If not, see <http://www.gnu.org/licenses/>. | |
import csv | |
import json | |
import subprocess | |
import sys | |
import urllib3 | |
COMPONENT = sys.argv[1] | |
URL = 'https://merges.ubuntu.com/%s.json' % COMPONENT | |
MAP = 'http://people.canonical.com/~ubuntu-archive/package-team-mapping.json' | |
# download json from merges | |
http = urllib3.PoolManager() | |
print('Downloading merge data from ' + URL) | |
mergereq = http.request('GET', URL) | |
if mergereq.status != 200: | |
print('Failed to fetch: ' + URL) | |
sys.exit(1) | |
print('Downloading package to team map from ' + MAP) | |
mapreq = http.request('GET', MAP) | |
if mapreq.status != 200: | |
print('Failed to fetch: ' + MAP) | |
sys.exit(1) | |
def dpkg_compare_versions(upkg, dpkg): | |
if "-" in upkg: | |
uver = upkg.split("-")[0] | |
dver = dpkg.split("-")[0] | |
else: | |
uver = upkg | |
dver = dpkg | |
result="" | |
if uver == dver: | |
result = "=" | |
return result | |
ge = subprocess.call(['dpkg', '--compare-versions', upkg, 'ge', dpkg]) | |
if ge == 0: | |
return ">" | |
else: | |
return "<" | |
KEY_TO_HEADING = { | |
'user': 'Last Uploader', | |
'age' : 'Days since last merge', | |
'left_version': 'Ubuntu Version', | |
'base_version': 'Upstream Version', | |
'right_version': 'Debian Version' | |
} | |
def heading(key): | |
return KEY_TO_HEADING.get(key, key) | |
merges = json.loads(mergereq.data.decode('utf-8')) | |
pkg2team = json.loads(mapreq.data.decode('utf-8')) | |
#merges = json.loads(open("%s.json" % component, "r").read()) | |
with open('merges-%s.csv' % COMPONENT , 'w') as f: | |
writer = csv.writer(f) | |
header_order = [ | |
heading('source_package'), | |
heading('Responsibility'), | |
heading('Status'), | |
heading('Progress'), | |
heading('left_version'), | |
heading('right_version'), | |
heading('vs debian'), | |
heading('base_version'), | |
heading('age'), | |
heading('user'), | |
heading('link'), | |
heading('uploader'), | |
heading('binaries'), | |
heading('short_description'), | |
heading('uploaded'), | |
] | |
key_order = [ | |
('source_package'), | |
('responsibility'), | |
('status'), | |
('progress'), | |
('left_version'), | |
('right_version'), | |
('vs debian'), | |
('base_version'), | |
('age'), | |
('user'), | |
('link'), | |
('uploader'), | |
('binaries'), | |
('short_description'), | |
('uploaded'), | |
] | |
writer.writerow(header_order) | |
for package in merges: | |
#print('{}:'.format(package['source_package'])) | |
dataline = [] | |
for key in key_order: | |
if key == 'vs debian': | |
value = dpkg_compare_versions(package['left_version'], | |
package['right_version']) | |
# google sheets requires leading tick to indicate field | |
# is not a formula | |
if value == '=': | |
value = "'=" | |
elif key == 'responsibility': | |
for team in pkg2team: | |
if package['source_package'] in pkg2team[team]: | |
if key in package: | |
package['responsibility'] += ", " + team | |
else: | |
package['responsibility'] = team | |
value = package.get(key, '') | |
else: | |
value = package.get(key, '') | |
#print(' {}: {}'.format(key, value)) | |
dataline.append(value) | |
#print(dataline) | |
writer.writerow(dataline) | |
print('Wrote merges-%s.csv' % COMPONENT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment