3
# IVLE - Informatics Virtual Learning Environment
4
# Copyright (C) 2007-2008 The University of Melbourne
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
# A CGI script for generating a diff report page in HTML. It is intended to be
25
# run from the trampoline by the Diff application.
27
from common import cgirequest
28
from cgi import parse_qs
34
def htmlfy_diff(difftext):
35
"""Adds HTML markup to a udiff string"""
37
match_file = re.compile(r'^([\+\-]{3})\s(\S+)\s\((.+)\)$',re.MULTILINE)
38
match_range = re.compile(r'^\@\@ (.*) \@\@$',re.MULTILINE)
39
match_add = re.compile(r'^\+(.*)$',re.MULTILINE)
40
match_sub = re.compile(r'^\-(.*)$',re.MULTILINE)
41
match_special = re.compile(r'^\\(.*)$',re.MULTILINE)
42
output = match_file.sub(
43
r'<span class="diff_files">\1 \2 <em>(\3)</em></span>', output)
44
output = match_range.sub(
45
r'<span class="diff_range">@@ \1 @@</span>', output)
46
output = match_add.sub(
47
r'<span class="diff_add">+\1</span>', output)
48
output = match_sub.sub(
49
r'<span class="diff_sub">-\1</span>', output)
50
output = match_special.sub(
51
r'<span class="diff_special">\\\1</span>', output)
54
def get_revision(r_str):
55
""" Returns a Revison object for pysvn from a r query string """
57
return pysvn.Revision( pysvn.opt_revision_kind.head )
58
elif r_str == "WORKING":
59
return pysvn.Revision( pysvn.opt_revision_kind.working )
61
return pysvn.Revision( pysvn.opt_revision_kind.base )
65
return pysvn.Revision( pysvn.opt_revision_kind.number, r)
69
# Use a CGIRequest object to make the CGI environment look like the normal
70
# IVLE handler environment.
72
req = cgirequest.CGIRequest()
75
print("Content-Type: text/html\n")
78
# Beginning of the page
79
print('<div id="ivle_padding">')
80
print('<h1>Diff</h1>')
82
# Work out the revisions from query
83
url = urlparse.urlparse(req.path)
86
query = parse_qs(querystr)
88
rev1=pysvn.Revision( pysvn.opt_revision_kind.base )
89
rev2=pysvn.Revision( pysvn.opt_revision_kind.working )
91
if len(query['r']) == 2:
92
r2 = get_revision(query['r'][1])
95
r1 = get_revision(query['r'][0])
99
# Attempt to get the diff for these revisons
101
svnclient = pysvn.Client()
102
diff = svnclient.diff
103
diff_text = diff( '/tmp/svndiff',
104
path.join('/home/', urlpath),
106
#revision1=pysvn.Revision( pysvn.opt_revision_kind.base ),
107
#url_or_path2=url_or_path,
109
#revision2=pysvn.Revision( opt_revision_kind.working ),
111
#ignore_ancestry=False,
113
#ignore_content_type=False,
118
# Split up the udiff into individual files
119
diff_matcher = re.compile(
120
r'^Index: (.*)\n\=+\n((?:[^I].*\n)*)',re.MULTILINE
122
split_diff = diff_matcher.findall(diff_text)
126
for filediff in split_diff:
127
filename = filediff[0]
128
diffbody = htmlfy_diff(filediff[1])
129
print("<dt><strong>File:</strong> " + filename + "</dt>")
130
print("<dd><code><pre>" + diffbody + "</pre></code></dd>")
133
except pysvn._pysvn_2_5.ClientError, e:
134
print("<dl><dt><strong>Error:</strong></dt><dd>")