-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog2html.py
More file actions
69 lines (67 loc) · 2.61 KB
/
log2html.py
File metadata and controls
69 lines (67 loc) · 2.61 KB
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
from diffs2html import diffs2html
import os
def log2html(log):
'''
Return a list of dictionary, each dictionary has the following fields:
commit - the commit SHA1 for this commit
author - the author making this commit
date - the datetime making this commit
diffs - a list of dictionary, each of dictionary has the following fields:
name - file name of this diff
revision - blob SHA1 of this diff
html - diff representation in HTML
'''
lines = log.split('\n')
currentLine = 0
totalLines = len(lines)
htmls = []
while currentLine < totalLines:
line = lines[currentLine]
if line.startswith('commit '):
commit = line[7:]
author = lines[currentLine + 1][8:]
date = lines[currentLine + 2][8:]
offset = 3
while currentLine + offset < totalLines:
line = lines[currentLine + offset]
if line.startswith('diff --git'):
break
offset = offset + 1
message = '\n'.join(lines[currentLine + 3:currentLine + offset])
diffOffset = offset
while currentLine + offset < totalLines:
line = lines[currentLine + offset]
if line.startswith('commit '):
break
offset = offset + 1
diffs = '\n'.join(lines[currentLine + diffOffset:currentLine + offset])
diffshtml = diffs2html(diffs)
if diffshtml:
htmls.append({'commit':commit, 'author':author, 'date':date, 'message':message, 'diffs':diffshtml})
currentLine = currentLine + offset
else:
currentLine = currentLine + 1
return htmls
if __name__ == '__main__':
import sys
if len(sys.argv) > 1:
filenames = sys.argv[1:]
htmls = []
for filename in filenames:
file = open(filename, 'rt')
log = file.read()
file.close()
html = log2html(log)
if html:
htmls.extend(html)
if htmls:
for html in htmls:
print '<h3> commit:' + html['commit'] + '</h3>'
print '<h3> author:' + html['author'] + '</h3>'
print '<h3> date:' + html['date'] + '</h3>'
print '<h3> message:' + html['message'] + '</h3>'
diffs = html['diffs']
for diff in diffs:
print '<h3>' + diff['name'] + '[' + diff['revision'] + ']' + '</h3><br/>' + diff['html']
else:
print 'Usage: parsediff.py file [file...]'