-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_commit_grep.py
More file actions
executable file
·87 lines (75 loc) · 2.81 KB
/
git_commit_grep.py
File metadata and controls
executable file
·87 lines (75 loc) · 2.81 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/python
# coding:utf-8
import csv
import os
import sys
import xml.dom.minidom as xmldom
if sys.getdefaultencoding() != 'utf-8':
reload(sys)
sys.setdefaultencoding('utf-8')
def get_data(path, commit_grep, keyword):
path = path+'/'+commit_grep
final = []
output=os.popen(' cd %s ;git log --author=htc --pretty=format:"%%s == %%ae == %%H == %%cd"'%(path)).read().splitlines()
# output=os.popen(' cd %s ;git log --pretty=format:"%%s = %%ae = %%H = %%cd"'%(path)).read().splitlines()
for item_list in output:
temp = []
item=item_list.split('==')
for n in item:
temp.append(n)
for item in temp:
if keyword in item:
temp.insert(0,commit_grep)
final.append(temp)
print("temp:"+'=='.join(temp))
break;
return final
def write_data_html(data, name, path ):
file_name = name+".html"
f = open(file_name,'w')
message ="""
<html>
<body>
<font size="10" color="#008000">Keywords</font>
<font size="4" color="#008000">("""+path+""")</font></br></br>
<table border="1" cellspacing="0">
<tr bgcolor="#008000">
<th>Index</th>
<th>Path</th>
<th>Title</th>
<th>Author</th>
</tr>
<font size="5" color="#FF0000">Grep '"""+name +"""' Total: """+bytes(len(data))+"""</font>"""
for index, n in enumerate(data):
message = message+"""<tr>"""
message = message+"""<td style="padding-right:20px">"""+str(index)+"""</td>"""
message = message+"""<td style="padding-right:20px">"""+n[0]+"""</td><td style="padding-right:20px">"""+n[1]+""" """+"""</td>"""
message = message+"""<td style="padding-right:20px">"""+n[2]+"""</td>"""
message = message+"""</tr>"""
message = message+"""</table>
</br></br>
<div style="float:right;">
<font size="4 style="padding-right:20px" color="#008000">HTC SSD BT</font>
</div>
</body>
</html>"""
f.write(message)
f.close()
def commit_grep (path, keyword):
result = []
xmlfilepath = os.path.abspath(path+'/.repo/manifest.xml')
domobj = xmldom.parse(xmlfilepath)
elementobj = domobj.documentElement
subElementObj = elementobj.getElementsByTagName("project")
for item in subElementObj:
commit_grep = item.getAttribute("path")
temp_list = get_data(path, commit_grep, keyword)
for temp in temp_list:
result.append(temp)
write_data_html(result, keyword, path)
if __name__ == '__main__':
print("Path:")
print(sys.argv[1])
print("keyword:")
print(sys.argv[2])
commit_grep(sys.argv[1], sys.argv[2])