-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenspreadsheet.py
executable file
·472 lines (410 loc) · 14.4 KB
/
genspreadsheet.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
#!/usr/bin/env python3
"""Use information in rebase database to create rebase spreadsheet
Required python modules:
google-api-python-client google-auth-httplib2 google-auth-oauthlib
The Google Sheets API needs to be enabled to run this script.
Also, you'll need to generate access credentials and store those
in credentials.json.
Disable pyline noise
pylint: disable=no-absolute-import
"""
from __future__ import print_function
import sqlite3
from common import rebasedb, upstreamdb
from common import rebase_baseline, rebase_target_tag, rebase_target_version
import genlib
rebase_filename = 'rebase-spreadsheet.id'
other_topic_id = 0 # Sheet Id to be used for "other" topic
red = {'red': 1, 'green': 0.4, 'blue': 0}
yellow = {'red': 1, 'green': 1, 'blue': 0}
orange = {'red': 1, 'green': 0.6, 'blue': 0}
green = {'red': 0, 'green': 0.9, 'blue': 0}
blue = {'red': 0.3, 'green': 0.6, 'blue': 1}
white = {'red': 1, 'green': 1, 'blue': 1}
def get_other_topic_id():
"""Calculate other_topic_id"""
global other_topic_id # pylint: disable=global-statement
conn = sqlite3.connect(rebasedb)
c = conn.cursor()
c.execute('select topic, name from topics order by name')
for topic, name in c.fetchall():
if name == 'other':
other_topic_id = topic
break
if topic >= other_topic_id:
other_topic_id = topic + 1
conn.close()
return other_topic_id
def add_topics_summary(requests):
"""Add topics to summary sheet"""
conn = sqlite3.connect(rebasedb)
c = conn.cursor()
c2 = conn.cursor()
version = rebase_target_version()
counted_rows = 0
counted_effrows = 0
c.execute('select topic, name from topics order by name')
rowindex = 1
for (topic, name) in c.fetchall():
# Insert 'other' topic last, and don't count it here.
if name == 'other':
continue
# Only add summary entry if there are commits touching this topic
c2.execute('select disposition, reason from commits where topic=%d' %
topic)
rows = 0
effrows = 0
for (d, r) in c2.fetchall():
# Skip entries associated with a topic if they are fully upstream
# and are not being replaced.
if d == 'drop' and r == 'upstream':
continue
rows += 1
if d == 'pick':
effrows += 1
counted_rows += rows
counted_effrows += effrows
requests.append({
'pasteData': {
'data':
'=HYPERLINK("#gid=%d","%s");%d;%d;;;;chromeos-%s-%s' %
(topic, name, rows, effrows, version, name.replace(
'/', '-')),
'type':
'PASTE_NORMAL',
'delimiter':
';',
'coordinate': {
'sheetId': 0,
'rowIndex': rowindex
}
}
})
rowindex += 1
allrows = 0
alleff = 0
c2.execute('select disposition, reason from commits where topic != 0')
for (d, r) in c2.fetchall():
if d == 'drop' and r == 'upstream':
continue
allrows += 1
if d != 'drop':
alleff += 1
# Now create an 'other' topic. We'll use it for unnamed topics.
requests.append({
'pasteData': {
'data':
'=HYPERLINK("#gid=%d","other");%d;%d;;;;chromeos-%s-other' %
(other_topic_id, allrows - counted_rows,
alleff - counted_effrows, version),
'type':
'PASTE_NORMAL',
'delimiter':
';',
'coordinate': {
'sheetId': 0,
'rowIndex': rowindex
}
}
})
conn.close()
def create_summary(requests):
"""Create summary sheet"""
requests.append({
'updateSheetProperties': {
# 'sheetId': 0,
'properties': {
'title': 'Summary',
},
'fields': 'title'
}
})
header = ('Topic, Entries, Effective Entries, Owner, Reviewer, Status, '
'Topic branch, Comments')
genlib.add_sheet_header(requests, 0, header)
# Now add all topics
add_topics_summary(requests)
def add_description(requests):
"""Add describing text to 'Summary' sheet"""
requests.append({
'appendCells': {
'sheetId': 0,
'rows': [
{},
{
'values': [{
'userEnteredValue': {
'stringValue': 'Topic branch markers:'
},
},]
},
{
'values': [
{
'userEnteredValue': {
'stringValue': 'blue'
},
'userEnteredFormat': {
'backgroundColor': blue
}
},
{
'userEnteredValue': {
'stringValue':
'branch dropped: All patches upstream, no longer applicable, moved to another topic, or no longer needed' # pylint: disable=line-too-long
},
},
]
},
{
'values': [
{
'userEnteredValue': {
'stringValue': 'green'
},
'userEnteredFormat': {
'backgroundColor': green
}
},
{
'userEnteredValue': {
'stringValue': 'clean (no or minor conflicts)'
},
},
]
},
{
'values': [
{
'userEnteredValue': {
'stringValue': 'yellow'
},
'userEnteredFormat': {
'backgroundColor': yellow
}
},
{
'userEnteredValue': {
'stringValue':
'mostly clean; problematic patches marked yellow'
},
},
]
},
{
'values': [
{
'userEnteredValue': {
'stringValue': 'orange'
},
'userEnteredFormat': {
'backgroundColor': orange
}
},
{
'userEnteredValue': {
'stringValue':
'some problems; problematic patches marked orange'
},
},
]
},
{
'values': [
{
'userEnteredValue': {
'stringValue': 'red'
},
'userEnteredFormat': {
'backgroundColor': red
}
},
{
'userEnteredValue': {
'stringValue': 'severe problems'
},
},
]
},
],
'fields': '*'
}
})
def addsheet(requests, index, topic, name):
"""Add sheet with header"""
print('Adding sheet id=%d index=%d title="%s"' % (topic, index, name))
requests.append({
'addSheet': {
'properties': {
'sheetId': topic,
'index': index,
'title': name,
}
}
})
# Generate header row
genlib.add_sheet_header(requests, topic,
'SHA, Description, Disposition, Contact, Comments')
def add_topics_sheets(requests):
"""Add topics sheets"""
conn = sqlite3.connect(rebasedb)
c = conn.cursor()
c.execute('select topic, name from topics order by name')
index = 1
for (topic, name) in c.fetchall():
# Insert 'other' topic at very end
if name != 'other':
addsheet(requests, index, topic, name)
index += 1
# Add 'other' topic sheet at the very end
addsheet(requests, index, other_topic_id, 'other')
conn.close()
def add_sha(requests, sheetId, sha, contact, email, subject, disposition,
reason, dsha, origin):
"""Add sha to topics sheet"""
comment = ''
color = white
contact_format = 'stringValue'
if '@google.com' in email or '@chromium.org' in email or '@collabora.com' in email:
contact = '=HYPERLINK("mailto:%s","%s")' % (email, contact)
contact_format = 'formulaValue'
if disposition == 'pick' and reason == 'revisit':
if dsha:
comment = 'revisit (similarities with %s commit %s)' % (origin, dsha)
else:
comment = 'revisit (imperfect match)'
color = orange
elif disposition == 'replace' and dsha:
comment = 'with %s commit %s' % (origin, dsha)
color = yellow
if reason == 'revisit':
comment += ' (revisit: imperfect match)'
color = orange
elif disposition == 'drop':
color = yellow
if reason == 'revisit':
color = red
if dsha:
comment = 'revisit (imperfect match with %s commit %s)' % (origin, dsha)
else:
comment = 'revisit (imperfect match)'
elif reason == 'upstream/fixup':
comment = 'fixup of upstream patch %s' % dsha
elif reason == 'upstream/match':
comment = '%s commit %s' % (origin, dsha)
elif reason == 'revisit/fixup':
comment = 'fixup of %s commit %s' % (origin, dsha)
elif reason == 'reverted':
comment = reason
if dsha:
comment += ' (commit %s)' % dsha
elif reason == 'fixup/reverted':
comment = 'fixup of reverted commit %s' % dsha
else:
comment = reason
if dsha:
comment += ' (%s commit %s)' % (origin, dsha)
print('Adding sha %s (%s) to sheet ID %d' % (sha, subject, sheetId))
requests.append({
'appendCells': {
'sheetId': sheetId,
'rows': [{
'values': [
{
'userEnteredValue': {
'stringValue': sha
},
'userEnteredFormat': {
'backgroundColor': color
}
},
{
'userEnteredValue': {
'stringValue': subject
},
'userEnteredFormat': {
'backgroundColor': color
}
},
{
'userEnteredValue': {
'stringValue': disposition
},
'userEnteredFormat': {
'backgroundColor': color
}
},
{
'userEnteredValue': {
contact_format: contact
},
'userEnteredFormat': {
'backgroundColor': color
}
},
{
'userEnteredValue': {
'stringValue': comment
},
'userEnteredFormat': {
'backgroundColor': color
}
},
]
}],
'fields': '*'
}
})
def add_commits(requests):
"""Add commits to sheets"""
conn = sqlite3.connect(rebasedb)
uconn = sqlite3.connect(upstreamdb)
c = conn.cursor()
c2 = conn.cursor()
cu = uconn.cursor()
sheets = set([])
c.execute(
'select sha, dsha, contact, email, subject, disposition, reason, topic \
from commits where topic > 0'
)
for (sha, dsha, contact, email, subject, disposition, reason,
topic) in c.fetchall():
# Skip entries associated with a topic if they are fully upstream
# and are not being replaced.
if disposition == 'drop' and reason == 'upstream':
continue
c2.execute('select topic, name from topics where topic=%d' % topic)
if c2.fetchone():
sheetId = topic
else:
sheetId = other_topic_id
cu.execute("select sha from commits where sha='%s'" % dsha)
if cu.fetchone():
origin = 'upstream'
else:
origin = 'linux-next'
sheets.add(sheetId)
add_sha(requests, sheetId, sha, contact, email, subject, disposition,
reason, dsha, origin)
for s in sheets:
genlib.resize_sheet(requests, s, 0, 5)
def main():
"""Main function"""
sheet = genlib.init_spreadsheet(
rebase_filename,
'Rebase %s -> %s' % (rebase_baseline(), rebase_target_tag()))
get_other_topic_id()
requests = []
create_summary(requests)
add_topics_sheets(requests)
genlib.doit(sheet, requests)
requests = []
add_commits(requests)
# Now auto-resize columns A, B, C, and G in Summary sheet
genlib.resize_sheet(requests, 0, 0, 3)
genlib.resize_sheet(requests, 0, 6, 7)
# Add description after resizing
add_description(requests)
genlib.doit(sheet, requests)
if __name__ == '__main__':
main()