-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreview.py
113 lines (86 loc) · 3.11 KB
/
review.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
import datetime
import argparse
import csv
def parse_date(datestr):
from dateutil import parser
if not datestr:
return None
else:
return parser.parse(datestr)
class IssueState (object):
def __init__(self):
self.repo = None
self.number = None
self.url = None
self.name = None
self.size = None
self.opened = None
self.started = None
self.done = None
self.closed = None
self.committers = None
def __cmp__(self, other):
if self.started and other.started:
return cmp(self.started, other.started)
elif self.started:
return -1
elif other.started:
return 1
else:
return cmp(self.opened, other.opened)
def main():
p = argparse.ArgumentParser("review",
description="Generate a CSV for review from daily trackers")
p.add_argument("startdate", help="Starting date of sprint (first tracker date)")
p.add_argument("trackers", nargs="+",
help="Names of tracking spreadsheet CSV files ('none' skips a day)")
p.add_argument("-o", "--outfile", help="Output CSV to file")
opts = vars(p.parse_args())
outfile = opts.get("outfile", "csvout.csv")
start = parse_date(opts.get("startdate"))
dateoff = 0
issues = {}
print "Reading tracking spreadsheets..."
for f in opts.get("trackers"):
if f == "none":
dateoff += 1
continue
rows = []
today = start + datetime.timedelta(days=dateoff)
print "%s (%s)" % (f, today)
with open(f, "r") as csvdata:
reader = csv.reader(csvdata)
rows = [r for r in reader]
mentioned = []
for r in rows:
print len(r), r
repo, number, url, name, size, working, done, committers, labels = r[:9]
if issues.has_key(number):
i = issues.get(number)
else:
i = IssueState()
i.repo = repo
i.number = number
i.url = url
i.name = name
i.size = size
i.opened = today
issues[number] = i
if working and i.started is None:
i.started = today
if done and i.done is None:
i.done = today
if committers and (i.committers is None or i.committers != committers):
i.committers = committers
for num, issue in issues.items():
if num not in mentioned and issue.started is not None and issue.closed is None:
issue.closed = today
print "Writing CSV..."
with open(outfile, "w+") as csvdata:
w = csv.writer(csvdata)
for num in sorted(issues, key=lambda i: issues[i]):
i = issues.get(num)
w.writerow([i.repo, i.number, i.url, i.name,
i.opened, i.started, i.done, i.closed, i.committers])
print "Finished"
main()