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 handling file requests. This is a wrapper around the
25
# FileService library module. It is intended to be run from the trampoline by
26
# the FileService application.
27
# (The purpose of all of this is to let FileService read and write the user's
28
# file system as them).
30
from common import cgirequest
31
from cgi import parse_qs
37
def htmlfy_diff(difftext):
38
"""Adds HTML markup to a udiff string"""
40
match_file = re.compile(r'^([\+\-]{3})\s(\S+)\s\((.+)\)$',re.MULTILINE)
41
match_range = re.compile(r'^\@\@ (.*) \@\@$',re.MULTILINE)
42
match_add = re.compile(r'^\+(.*)$',re.MULTILINE)
43
match_sub = re.compile(r'^\-(.*)$',re.MULTILINE)
44
match_special = re.compile(r'^\\(.*)$',re.MULTILINE)
45
output = match_file.sub(
46
r'<span class="diff_files">\1 \2 <em>(\3)</em></span>', output)
47
output = match_range.sub(
48
r'<span class="diff_range">@@ \1 @@</span>', output)
49
output = match_add.sub(
50
r'<span class="diff_add">+\1</span>', output)
51
output = match_sub.sub(
52
r'<span class="diff_sub">-\1</span>', output)
53
output = match_special.sub(
54
r'<span class="diff_special">\\\1</span>', output)
57
def get_revision(r_str):
58
""" Returns a Revison object for pysvn from a r query string """
60
return pysvn.Revision( pysvn.opt_revision_kind.head )
61
elif r_str == "WORKING":
62
return pysvn.Revision( pysvn.opt_revision_kind.working )
64
return pysvn.Revision( pysvn.opt_revision_kind.base )
68
return pysvn.Revision( pysvn.opt_revision_kind.number, int(r_str))
72
# Use a CGIRequest object to make the CGI environment look like the normal
73
# IVLE handler environment. This lets us call FileService as if it were an
76
req = cgirequest.CGIRequest()
77
#fileservice_lib.handle(req)
80
print("Content-Type: text/html\n")
83
print("<h1>Diff</h1>")
85
# Work out the revisions from query
86
url = urlparse.urlparse(req.path)
89
query = parse_qs(querystr)
91
rev1=pysvn.Revision( pysvn.opt_revision_kind.base )
92
rev2=pysvn.Revision( pysvn.opt_revision_kind.working )
94
if len(query['r']) == 2:
95
r2 = get_revision(query['r'][1])
99
r1 = get_revision(query['r'][0])
103
# Attempt to get the diff for these revisons
105
svnclient = pysvn.Client()
106
diff = svnclient.diff
107
diff_text = diff( '/tmp/svndiff',
108
path.join('/home/', urlpath),
110
#revision1=pysvn.Revision( pysvn.opt_revision_kind.base ),
111
#url_or_path2=url_or_path,
113
#revision2=pysvn.Revision( opt_revision_kind.working ),
115
#ignore_ancestry=False,
117
#ignore_content_type=False,
122
# Split up the udiff into individual files
123
diff_matcher = re.compile(
124
r'^Index: (.*)\n\=+\n((?:[^I].*\n)*)',re.MULTILINE
126
split_diff = diff_matcher.findall(diff_text)
130
for filediff in split_diff:
131
filename = filediff[0]
132
diffbody = htmlfy_diff(filediff[1])
133
print("<dt><strong>File:</strong> " + filename + "</dt>")
134
print("<dd><code><pre>" + diffbody + "</pre></code></dd>")
137
except pysvn._pysvn_2_5.ClientError, e:
138
print("<dl><dt><strong>Error:</strong></dt><dd>")