-
Notifications
You must be signed in to change notification settings - Fork 3
/
api-ref-burndown.py
executable file
·149 lines (123 loc) · 4.25 KB
/
api-ref-burndown.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python
import argparse
import base64
import collections
import time
import glob
import os
import ConfigParser
import json
from multiprocessing import Pool
import re
import requests
from requests.auth import HTTPDigestAuth
TOP = 'nova/api-ref/source'
PROJECT_SITE = "https://review.openstack.org/changes/"
DIFF_QUERY = "%s/revisions/current/patch"
QUERY = "q=project:openstack/nova+file:^api-ref/source/.*.inc+NOT+age:7d"
ATTRS = ("&o=CURRENT_REVISION&o=ALL_COMMITS&o=ALL_FILES&o=LABELS"
"&o=DETAILED_LABELS&o=DETAILED_ACCOUNTS")
URL = "%s?%s%s" % (PROJECT_SITE, QUERY, ATTRS)
DIFF_URL = PROJECT_SITE + DIFF_QUERY
PHASES = ['needs:method_verification', 'needs:parameter_verification',
'needs:example_verification', 'needs:body_verification']
counts = collections.OrderedDict()
for phase in PHASES:
counts[phase] = []
counts['done'] = []
files = []
def _parse_content(resp, debug=False):
# slice out the "safety characters"
if resp.content[:4] == ")]}'":
content = resp.content[5:]
if debug:
print("Response from Gerrit:\n")
print(content)
return json.loads(content)
elif ('X-FYI-Content-Encoding' in resp.headers and
resp.headers['X-FYI-Content-Encoding'] == 'base64'):
return base64.b64decode(resp.content)
else:
print resp
return resp.content
def fetch_data(url, debug=False):
config = ConfigParser.ConfigParser()
config.read('config.ini')
user = config.get('default', 'user')
password = config.get('default', 'password')
auth = HTTPDigestAuth(user, password)
resp = requests.get(url, auth=auth)
return _parse_content(resp, debug)
def _http_process(change):
diff = fetch_data(change['url'])
files = []
fname = None
for line in diff.split('\n'):
m = re.match('--- a/api-ref/source/(.*.inc)$', line)
if m:
fname = m.group(1)
m = re.match('-.. needs:(.*)', line)
if m:
tag = {'number': change['number'],
'filename': fname,
'tag': m.group(1)}
files.append(tag)
return files
def gather_reviews():
data = fetch_data(URL)
changes = []
for change in data:
if change['status'] != 'NEW':
continue
newchange = {}
newchange['number'] = change['_number']
newchange['url'] = DIFF_URL % change['id']
changes.append(newchange)
pool = Pool(processes=10)
files = pool.map(_http_process, changes)
relevant = []
for f in files:
if f:
relevant.extend(f)
return relevant
def update_review_list(files, updated):
for fdata in files:
updates = [x for x in updated if x['filename'] == fdata['filename']]
for update in updates:
what = "needs:%s" % update['tag']
fdata[what] = update['number']
for fname in sorted(glob.glob("%s/*.inc" % TOP)):
with open(fname) as f:
fdata = {'filename': os.path.basename(fname)}
content = f.readlines()
done = True
for key in PHASES:
if ".. %s\n" % key in content:
fdata[key] = "TODO"
done = False
counts[key].append(fname)
else:
fdata[key] = u"\u2713"
if done:
counts['done'].append(fname)
files.append(fdata)
relevant = gather_reviews()
update_review_list(files, relevant)
with open("data.csv", "a") as f:
f.write("%d,%d,%d,%d,%d\n" % (
int(time.time()),
len(counts['needs:method_verification']),
len(counts['needs:parameter_verification']),
len(counts['needs:example_verification']),
len(counts['needs:body_verification'])))
with open("data.json", "w") as f:
f.write(json.dumps(files))
with open("data.txt", "w") as f:
FORMAT = "%-40s %10s %10s %10s %10s\n"
f.write(FORMAT % ("File Name", "Method", "Param", "Example", "Body"))
for fdata in files:
f.write((FORMAT % (fdata['filename'],
fdata['needs:method_verification'],
fdata['needs:parameter_verification'],
fdata['needs:example_verification'],
fdata['needs:body_verification'])).encode('utf8'))