-
Notifications
You must be signed in to change notification settings - Fork 0
/
launchpad-bugs-stat.py
92 lines (69 loc) · 2.17 KB
/
launchpad-bugs-stat.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
import argparse
import collections
from datetime import datetime
from datetime import timezone
import json
import sys
from launchpadlib.launchpad import Launchpad
from prettytable import PrettyTable
KNOWN_STATUSES = ['New', 'Confirmed', 'Triaged', 'In Progress']
KNOWN_PRIORITIES = ['Critical', 'High', 'Medium', 'Low', 'Wishlist', 'Undecided']
parser = argparse.ArgumentParser('')
parser.add_argument('project')
parser.add_argument('--quiet', action='store_true')
parser.add_argument('--stat-file')
args = parser.parse_args()
if args.stat_file:
try:
with open(args.stat_file) as f:
saved_data = json.loads(f.read())
except FileNotFoundError:
saved_data = {}
lp = Launchpad.login_anonymously('just testing', 'production')
proj = lp.projects[args.project]
bugtasks = proj.searchTasks()
stat = {}
for bugtask in bugtasks:
status = bugtask.status
priority = bugtask.importance
if status not in stat:
stat[status] = collections.defaultdict(int)
stat[status][priority] += 1
# Calculate total per status
total = collections.defaultdict(int)
for status in stat:
count = stat[status]
status_total = sum(count.values())
stat[status]['Total'] = status_total
for p in KNOWN_PRIORITIES:
total[p] += count[p]
total['Total'] += status_total
stat['Summary'] = total
if args.stat_file:
timestamp = datetime.now(timezone.utc).astimezone().isoformat()
saved_data[timestamp] = stat
with open(args.stat_file, 'w') as f:
f.write(json.dumps(saved_data, indent=4, sort_keys=True))
unknown_statuses = set(stat.keys()) - set(KNOWN_STATUSES)
x = PrettyTable()
x.field_names = ['Status'] + KNOWN_PRIORITIES + ['Total']
x.align['Status'] = "c"
for p in KNOWN_PRIORITIES:
x.align[p] = "r"
x.align['Total'] = "r"
for status in KNOWN_STATUSES + list(unknown_statuses):
if status == 'Summary':
continue
count = stat[status]
d = [status]
for p in KNOWN_PRIORITIES:
d.append(count.get(p, 0))
d.append(count['Total'])
x.add_row(d)
# Summary line
d = []
d.append('Summary')
d += [stat['Summary'][p] for p in KNOWN_PRIORITIES]
d.append(stat['Summary']['Total'])
x.add_row(d)
print(x)