My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
# Make sure we have a module for doing shell scripts and one for simple web forms.
import os
import cgi
import re

# This function can probably be beautified
def parseRawLog(svnLog):
"""Parses a raw svn log.

Returns a list with entries, each list item containing a dictionary with
two keys; info (string) and changes (list)
"""
logList = cgi.escape(svnLog.read()).splitlines()
entries = []
current = 0
separator = "-" * 72
for i, line in enumerate(logList):
if line != separator:
# After the separator comes the log info
if logList[i - 1] == separator:
entries.append({"info": line, "changes": []})
elif line:
entries[current]["changes"].append(line)

# If next list item is a separator, there are no more changes
if logList[i + 1] == separator:
current += 1
return entries


def parseLogLine(logInfo):
mapping = {
"e": "editorial",
"a": "authors",
"c": "conformance-checkers",
"g": "gecko",
"i": "internet-explorer",
"o": "opera",
"w": "webkit",
"r": "google-gears",
"t": "tools",
"0": "draft-content",
"1": "stable-draft",
"2": "implemented",
"3": "stable"
}
changes = []
classes = []
bug = None
for line in logInfo:
if line.startswith("Fixing http://www.w3.org/Bugs/Public/show_bug.cgi?id="):
bug = line[53:]
elif line.startswith("Fixing https://www.w3.org/Bugs/Public/show_bug.cgi?id="):
bug = line[54:]
elif line.startswith("["):
for c in line:
if c in mapping:
classes.append(mapping[c])
if c == "]":
if (not classes) or (len(classes) == 1 and classes[0] == "editorial"):
classes.append("none")
if c == ")":
break
changes.append(line.split(") ", 1)[-1])
elif line.startswith("Affected topics:"):
pass
else:
changes.append(line)
return {"changes": changes, "classes": classes, "bug": bug}


def getRevisionData(revision):
revInfo = revision["info"] # This is the info line for a revision
revChanges = parseLogLine(revision["changes"]) # Changes for the revision

iconClasses = ["authors", "conformance-checkers", "gecko", "internet-explorer", "opera", "webkit", "google-gears", "tools"]
titleClasses = ["editorial", "draft-content", "stable-draft", "implemented", "stable"]

# Get the revision number
number = getNumber(revInfo, 1)
# Get the revision date and chop off the seconds and time zone
date = re.split(" \(", re.split(" \| ", revInfo)[2])[0][:16]

# Get stuff from the changes line(s)
# TODO: fix the classAttr and titleAttr to only return if non-empty
classAttr = " class=\"%s\"" % " ".join(revChanges["classes"])
titleAttr = " title=\"%s\"" % ", ".join([title.replace("-", " ").title() for title in revChanges["classes"] if title in titleClasses])
icons = "".join([("<img src=\"icons/%s\" alt=\"[%s]\"> ") % (class_, class_.replace("-", " ").title()) for class_ in revChanges["classes"] if class_ in iconClasses])
changes = "<br>".join(revChanges["changes"])

# TODO: Implement the source stuff to work with links
link = "?from=%s&amp;to=%s" % (str(toInt(number) - 1), number)

bug = ""
if revChanges["bug"]:
bug = "<a href=\"https://www.w3.org/Bugs/Public/show_bug.cgi?id=" + revChanges["bug"] + "\">" + revChanges["bug"] + "</a>"

return {
"number": number,
"link": link,
"classAttr": classAttr,
"titleAttr": titleAttr,
"icons": icons,
"changes": changes,
"date": date,
"bug" : bug
}


def formatLog(logList):
output = ""
if logList:
output += "<table id=\"log\">\n <tr>" \
"<th>SVN</th>" \
"<th>Bug</th>" \
"<th>Comment</th>" \
"<th>Time (UTC)</th></tr>"
for revision in logList:
revData = getRevisionData(revision)
output += "\n <tr%(classAttr)s%(titleAttr)s>" \
"<td>%(number)s</td>" \
"<td>%(bug)s</td>" \
"<td><a href=\"%(link)s\">%(icons)s%(changes)s</a></td>" \
"<td>%(date)s</td></tr>" % revData
output += "\n </table>"
return output


def formatDiff(diff):
"""Takes a svn diff and marks it up with elements for styling purposes

Returns a formatted diff
"""
diff = diff.splitlines()
diffList = []

def formatLine(line):
format = "<samp class=\"%s\">%s</samp>"
formattingTypes = {"+": "addition", "-": "deletion", "@": "line-info"}
diffType = line[0]
if diffType in formattingTypes.keys():
diffList.append(format % (formattingTypes[diffType], line))
else:
diffList.append("<samp>%s</samp>" % line)

for line in diff:
formatLine(line)

return "\n".join(diffList)

def getDiffCommand(source, revFrom, revTo):
command = "svn diff -r %s%s %s"
if revTo:
return command % (revFrom, ":%s" % revTo, source)
else:
return command % (revFrom, "", source)

def getLogCommand(source, revFrom, revTo):
revFrom += 1
return "svn log %s -r %s:%s" % (source, revFrom, revTo)

def getDiff(source, revFrom, revTo, identifier):
if identifier == "":
identifier = "html5"
filename = identifier + "-" + str(revFrom) + "-" + str(revTo)

# Specialcase revTo 0 so future revFrom=c&revTo=0 still show the latest
if revTo != 0 and os.path.exists("diffs/" + filename):
return open("diffs/" + filename, "r").read()
else:
diff = cgi.escape(os.popen(getDiffCommand(source, revFrom, revTo)).read())
if not diff:
return diff

# Specialcase revTo 0 so future revFrom=c&revTo=0 still show the
# latest
if revTo == 0:
filename = identifier + "-" + str(revFrom) + "-" + str(getNumber(diff, 2))

# Return early if we already have this diff stored
if os.path.exists("diffs/" + filename):
return diff

# Store the diff
if not os.path.isdir("diffs"):
os.mkdir("diffs")
file = open("diffs/" + filename, "w")
file.write(diff)
file.close()
return diff

def getNumber(s, n):
return int(re.split("\D+", s)[n])


def toInt(s):
return int(float(s))


def startFormatting(title, identifier, url, source):
document = """Content-Type:text/html;charset=UTF-8

<!doctype html>
<html lang=en>
<head>
<title>%s Tracker</title>
<style>
html { background:#fff; color:#000; font:1em/1 Arial, sans-serif }
form { margin:1em 0; font-size:.7em }
fieldset { margin:0; padding:0; border:0 }
legend { padding:0; font-weight:bold }
input[type=number] { width:4.5em }
table { border-collapse:collapse }
table td { padding:.1em .5em }
table td:last-child { white-space:nowrap }
img { font-size:xx-small }

.draft-content { background-color:#eee }
.stable-draft { background-color:#fcc }
.implemented { background-color:#f99 }
.stable { background-color:#f66 }
body .editorial { color:gray }

:link { background:transparent; color:#00f }
:visited { background:transparent; color:#066 }
img { border:0; vertical-align:middle }

td :link { color:inherit }
td a { text-decoration:none; display:block }
td a:hover { text-decoration:underline }

.editorial tr.editorial { display:none }

pre { display:table; white-space:normal }
samp samp { margin:0; display:block; white-space:pre }
.deletion { background:#fdd; color:#900 }
.addition { background:#dfd; color:#000 }
.line-info { background:#eee; color:#000 }
</style>
<script>
function setCookie(name,value) { localStorage["tracker%s-" + name] = value }
function readCookie(name) { return localStorage["tracker%s-" + name] }
function setFieldValue(idName, n) { document.getElementById(idName).value = n }
function getFieldValue(idName) { return document.getElementById(idName).value }
function setFrom(n) {
setCookie("from", n)
setFieldValue("from", n)
setFieldValue("to", "")
}

function showEdits() { return document.getElementById("editorial").checked }
function updateEditorial() {
var editorial = showEdits() ? "" : "editorial"
setCookie("editorial", editorial)
document.body.className = editorial
}
</script>
</head>
<body>
<h1>%s</h1>
<form>
<fieldset>
<legend>Diff</legend>
<label>From: <input id=from type=number min=1 value="%s" name=from required></label>
<label>To: <input id=to type=number min=0 value="%s" name=to></label> (omit for latest revision)
<input type=submit value="Generate diff">
</fieldset>
</form>
<form>
<fieldset>
<legend>Filter</legend>
<label class="editorial">Show editorial changes <input type="checkbox" id="editorial" checked="" onchange="updateEditorial()"></label>
</fieldset>
</form>
<script>
if(getFieldValue("from") == "" && readCookie("from") != null)
setFrom(readCookie("from"))
if(readCookie("editorial") == "editorial") {
document.getElementById("editorial").checked = false
updateEditorial()
}
</script>
%s
</body>
</html>"""
showDiff = False
revFrom = 290 # basically ignored, but sometimes a useful fiction for debugging
revTo = 0
os.environ["TZ"] = "" # Set time zone to UTC. Kinda hacky, but works :-)
form = cgi.FieldStorage()

if "from" in form:
try:
revFrom = toInt(form["from"].value)
showDiff = True
except:
pass

if showDiff and "to" in form:
try:
revTo = toInt(form["to"].value)
if 0 < revTo < revFrom:
revFrom, revTo = revTo, revFrom
except:
pass

# Put it on the screen
if not showDiff:
#
# HOME
#
if "limit" in form and form["limit"].value == "-1":
limit = ""
else:
limit = " --limit 100"
try:
limit = " --limit %s" % toInt(form["limit"].value)
except:
pass
svnLog = os.popen("svn log %s%s" % (source, limit))
parsedLog = parseRawLog(svnLog)
formattedLog = formatLog(parsedLog)
print document % (title, identifier, identifier, title + " Tracker", "", "", formattedLog)
else:
#
# DIFF
#
diff = formatDiff(getDiff(source, revFrom, revTo, identifier))
markuptitle = "<a href=" + url + ">" + title + " Tracker" + "</a>"
try:
# This fails if there is no diff -- hack
revTo = getNumber(diff, 2)
svnLog = os.popen(getLogCommand(source, revFrom, revTo))
parsedLog = parseRawLog(svnLog)
formattedLog = formatLog(parsedLog)
result = """%s
<pre id="diff"><samp>%s</samp></pre>
<p><a href="?from=%s&amp;to=%s" rel=prev>Previous</a> | <a href="?from=%s&amp;to=%s" rel=next>Next</a>
<p><input type="button" value="Prefill From field for next time!" onclick="setFrom(%s)">""" % (formattedLog, diff, revFrom-1, revFrom, revTo, revTo+1, revTo)

# Short URL
shorturlmarkup = ""
if title == "HTML5":
shorturl = "http://html5.org/r/"
if revTo - revFrom == 1:
shorturl += str(revTo)
else:
shorturl += str(revFrom) + "-" + str(revTo)
shorturlmarkup = """<p>Short URL: <code><a href="%s">%s</a></code>\n """ % (shorturl, shorturl)
shorturlmarkup += result
print document % (title, identifier, identifier, markuptitle, revFrom, revTo, shorturlmarkup)
except:
print document % (title, identifier, identifier, markuptitle, revFrom, "", "No result.")

Change log

r202 by Ms2ger on Feb 5, 2012   Diff
Ignore 'Affected topics' lines.
Go to: 
Project members, sign in to write a code review

Older revisions

r201 by Ms2ger on Feb 5, 2012   Diff
Always output HTTPS URLs to the W3C
Bugzilla.
r200 by Ms2ger on Feb 5, 2012   Diff
Make web-apps-tracker recognize HTTPS
bug URLs in Hixie's commit messages.
r185 by philip.jagenstedt on Mar 6, 2011   Diff
Create the diffs dir if it does not
exist (for a fresh setup)
All revisions of this file

File info

Size: 12158 bytes, 353 lines
Powered by Google Project Hosting