forked from dougt/diff-mozilla-clones
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff-trees.py
More file actions
159 lines (144 loc) · 5.58 KB
/
diff-trees.py
File metadata and controls
159 lines (144 loc) · 5.58 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
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
import subprocess
from subprocess import Popen, PIPE
import urllib2
import simplejson
import re
import math
from datetime import datetime
import os
srcdir_1 = "./mozilla-aurora"
srcdir_2 = "./mozilla-beta"
directories_of_interest = "mobile/android widget/src/android widget/android"
aurora_merge_date_str = "2011-12-21"
aurora_merge_date = datetime.strptime(aurora_merge_date_str, "%Y-%m-%d");
landedBugs = {}
unlandedBugs = []
def getBugInfo(bug):
try:
spec = "https://api-dev.bugzilla.mozilla.org/latest/bug/" + bug
print "Getting: " + spec
req = urllib2.Request(spec, None, {'user-agent':'dougt/rocks', 'Content-Type': 'application/json'})
opener = urllib2.build_opener()
f = opener.open(req)
result = simplejson.load(f)
not11 = "false"
if datetime.strptime(result['last_change_time'], '%Y-%m-%dT%H:%M:%SZ') < aurora_merge_date:
return None
try:
if "not-fennec-11" in result['whiteboard']:
return None
except KeyError:
not11 = "false"
return result['assigned_to']['real_name'], result['summary'], not11
except urllib2.HTTPError:
return "Stuart", "I do not have a pony. See bug " + bug, "true"
def getLandedBugs(srcdir, dirs_to_diff):
cmd = "hg log -d \">" + aurora_merge_date_str + "\" --template '{desc|firstline}\n' " + dirs_to_diff
p = Popen(cmd, cwd=srcdir, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate()
lines = stdout.splitlines()
for line in lines:
try: # if the bugNum isn't a number it'll throw
bugNum = int(line[4:10], 10)
print "bug number: " + str(bugNum)
landedBugs[bugNum] = True
except ValueError:
print "not a bug: " + line
def getUnlandedBugs(srcdir, dirs_to_diff):
cmd = "hg log -d \">" + aurora_merge_date_str + "\" --template '{rev}\t{node|short}\t{author}\t{desc|firstline}\n' " + dirs_to_diff
p = Popen(cmd, cwd=srcdir, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate()
lines = stdout.splitlines()
for line in lines:
tmp = line.partition('\t')
rev = tmp[0]
remander = tmp[2].partition('\t')
changeset = remander[0]
remander2 = remander[2].partition('\t')
author = remander2[0]
summary = remander2[2]
try: # if the bugNum isn't a number it'll throw
bugNum = int(summary[4:10], 10)
print "bug num: " + str(bugNum)
if not landedBugs.has_key(bugNum):
tup = rev, bugNum, changeset, author, summary
unlandedBugs.append(tup)
except ValueError:
print "not a bug: " + summary
print "updating source directories:"
subprocess.call(["hg", "pull", "-u"], cwd=srcdir_2)
subprocess.call(["hg", "pull", "-u"], cwd=srcdir_1)
print "collecting data about " + srcdir_2
getLandedBugs(srcdir_2, directories_of_interest)
print "collecting data about " + srcdir_1
getUnlandedBugs(srcdir_1, directories_of_interest)
print str(len(unlandedBugs)) + " havent' landed in " + srcdir_2
html_out =\
\
"<html><head><title>Diff Between" + srcdir_1 + " and " + srcdir_2 + "</title><style>"\
"#container {width: 100%; display: table;}"\
".row { display: table-row;}"\
".bugnum { width: 15%; display: table-cell;}"\
".owner { width: 25%; display: table-cell;}"\
".summary { width: 60%; display: table-cell;}"\
"</style>\n" \
"<script>\n" \
"function openAllBugs() {\n" \
" var bugs = document.getElementsByTagName(\"a\");\n" \
" for (a in bugs) {\n" \
" try {\n" \
" var decor = bugs[a].parentNode.parentNode.style.textDecoration;\n" \
" if (decor != \"line-through\")\n" \
" window.open(bugs[a].getAttribute(\"href\"));\n" \
" } catch(e) {}\n" \
" }\n" \
"}\n" \
"</script>\n" \
"</head><body>"\
"<h1>Diff Between" + srcdir_1 + " and " + srcdir_2 + "</h1>"\
"<div id=\"container\">\n" \
"<button onClick=\"openAllBugs()\">Open All Bugs</button>\n"
written_out_bugs = {}
unlandedBugs.sort()
try:
os.mkdir("patches")
except OSError:
print "patches dir exists"
series_file = open("./patches/series", "w")
for index in unlandedBugs:
print index
bugNum = index[1]
rev = index[0]
changeset = index[2]
author = index[3]
summary = index[4]
not11 = False
if not written_out_bugs.has_key(bugNum):
written_out_bugs[bugNum] = True
print "bug number: " + str(bugNum) + " rev: " + rev
#info = getBugInfo(str(bugNum))
#if info is None:
# continue
html_out += "<div class=\"row\" "
if not11:
html_out += "style=\"text-decoration: line-through;\""
html_out += ">\n"
html_out += "\t<span class=\"bugnum\"> <a href=\"https://bugzilla.mozilla.org/show_bug.cgi?id=" + str(bugNum) + "\">" + str(bugNum) + "</a></span>"
html_out += "<span class=\"owner\">" + author + "</span>"
html_out += "<span class=\"summary\">" + summary + "</span>\n"
html_out += "</div>\n"
print "creating changeset file"
patch_file = open("patches/" + changeset, "w")
print "exporting changeset"
cmd = "hg export " + changeset
p = Popen(cmd, cwd=srcdir_1, shell=True, stdin=PIPE, stdout=patch_file, stderr=PIPE)
p.communicate()
print "closing changeset file"
patch_file.close()
print "writing series file"
series_file.write(changeset + " # rev: " + rev + " bug " + str(bugNum) + " " + author + " " + summary +"\n")
html_out += "</div></body></html>"
fout = open("data.html", "w")
fout.write(html_out.encode('UTF-8'))
fout.close()
series_file.close()