830
by wagrant
Add an svnlog app. It nicely displays all log entries for a path, |
1 |
#!/usr/bin/python
|
2 |
||
3 |
# IVLE - Informatics Virtual Learning Environment
|
|
4 |
# Copyright (C) 2008 The University of Melbourne
|
|
5 |
#
|
|
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.
|
|
10 |
#
|
|
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.
|
|
15 |
#
|
|
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
|
|
19 |
||
20 |
# Script: logservice
|
|
21 |
# Author: William Grant
|
|
22 |
# Date: 08/07/2008
|
|
23 |
||
24 |
# A CGI script for viewing a Subversion log. Used by the svnlog app.
|
|
25 |
||
26 |
import os |
|
27 |
import time |
|
901
by wagrant
svnlogservice: Fix arbitrary content injection by commit message. |
28 |
import cgi |
830
by wagrant
Add an svnlog app. It nicely displays all log entries for a path, |
29 |
import pysvn |
30 |
||
890
by wagrant
svnlogservice: Link the revision number to a view of the current path |
31 |
import common.cgirequest |
32 |
import common.util |
|
892
by wagrant
fileservice_lib: Give date pretty-printing functions to common.date. |
33 |
import common.date |
903
by wagrant
svnlogservice: Add the ability to show diff links. |
34 |
import common.svn |
830
by wagrant
Add an svnlog app. It nicely displays all log entries for a path, |
35 |
|
890
by wagrant
svnlogservice: Link the revision number to a view of the current path |
36 |
req = common.cgirequest.CGIRequest() |
854
by wagrant
Enable the new CGIRequest error handler in the diff, file and svnlog |
37 |
req.install_error_handler() |
830
by wagrant
Add an svnlog app. It nicely displays all log entries for a path, |
38 |
req.content_type = "text/html" |
39 |
||
40 |
req.write('<h1>Subversion Log</h1>\n') |
|
41 |
||
903
by wagrant
svnlogservice: Add the ability to show diff links. |
42 |
r_str = req.get_fieldstorage().getfirst("r") |
43 |
sr = common.svn.revision_from_string(r_str) |
|
830
by wagrant
Add an svnlog app. It nicely displays all log entries for a path, |
44 |
|
891
by wagrant
svnlogservice: Link changed paths. |
45 |
def pretty_path(cpath, revno=None): |
46 |
path = cpath['path'] |
|
47 |
# XXX: We can't assume that the repository root is always equivalent to
|
|
48 |
# the current user's home directory, although it does work for our
|
|
49 |
# current setup.
|
|
50 |
url = common.util.make_path(os.path.join('files', |
|
51 |
common.util.split_path(req.path)[0], |
|
52 |
path[1:])) |
|
53 |
if revno: |
|
54 |
url += '?r=%d' % revno |
|
901
by wagrant
svnlogservice: Fix arbitrary content injection by commit message. |
55 |
return '%s <a href="%s">%s</a>' % (cpath['action'], cgi.escape(url, True), |
56 |
cgi.escape(path)) |
|
830
by wagrant
Add an svnlog app. It nicely displays all log entries for a path, |
57 |
|
891
by wagrant
svnlogservice: Link changed paths. |
58 |
def pretty_paths(paths, revno=None): |
830
by wagrant
Add an svnlog app. It nicely displays all log entries for a path, |
59 |
output = '<ul>' |
60 |
for path in paths: |
|
891
by wagrant
svnlogservice: Link changed paths. |
61 |
output += '<li>' + pretty_path(path, revno) + '</li>' |
830
by wagrant
Add an svnlog app. It nicely displays all log entries for a path, |
62 |
output += '</ul>' |
63 |
return output |
|
64 |
||
65 |
def pretty_log(log): |
|
903
by wagrant
svnlogservice: Add the ability to show diff links. |
66 |
revno = log.revision.number |
67 |
author = cgi.escape(log.author) |
|
68 |
message = cgi.escape(log.message) |
|
69 |
result = ''' |
|
830
by wagrant
Add an svnlog app. It nicely displays all log entries for a path, |
70 |
<div class="svnlogentry">
|
71 |
<div class="svnloginfo">
|
|
891
by wagrant
svnlogservice: Link changed paths. |
72 |
Revision <a href="%s?r=%d" style="font-weight: bold">%d</a> |
73 |
by <strong>%s</strong> on <strong>%s</strong> |
|
903
by wagrant
svnlogservice: Add the ability to show diff links. |
74 |
''' % (cgi.escape(common.util.make_path(os.path.join('files', req.path))), |
75 |
revno, revno, author, common.date.make_date_nice(log.date)) |
|
76 |
||
77 |
# Now we get ugly. We need to sometimes present [select] and [diff] links.
|
|
78 |
if sr and sr.kind == pysvn.opt_revision_kind.number and sr.number == revno: |
|
79 |
result += '[selected]' |
|
80 |
else: |
|
81 |
result += '<a href="%s?r=%d">[select]</a>' % ( |
|
82 |
cgi.escape(common.util.make_path(os.path.join('svnlog', req.path))), |
|
83 |
revno) |
|
84 |
if sr and sr.kind == pysvn.opt_revision_kind.number: |
|
85 |
result += ' <a href="%s?r=%d&r=%d">[diff]</a>' % ( |
|
86 |
cgi.escape(common.util.make_path(os.path.join('diff', req.path))), |
|
87 |
sr.number, revno) |
|
88 |
||
89 |
result += ''' |
|
830
by wagrant
Add an svnlog app. It nicely displays all log entries for a path, |
90 |
</div>
|
91 |
<pre>%s</pre> |
|
92 |
<hr size="1"/>
|
|
93 |
<h2>Changed paths:</h2>
|
|
94 |
<div class="svnlogpathlist">
|
|
95 |
%s |
|
96 |
</div>
|
|
903
by wagrant
svnlogservice: Add the ability to show diff links. |
97 |
</div>''' % (message, pretty_paths(log.changed_paths, log.revision.number)) |
98 |
return result |
|
830
by wagrant
Add an svnlog app. It nicely displays all log entries for a path, |
99 |
|
100 |
try: |
|
101 |
client = pysvn.Client() |
|
102 |
logs = client.log(os.path.join('/home', req.path), discover_changed_paths=True) |
|
103 |
[req.write(pretty_log(log)) for log in logs] |
|
104 |
except pysvn.ClientError, e: |
|
105 |
req.write('<p><b>Error:</b></p>\n') |
|
106 |
req.write('<pre>%s</pre>\n' % cgi.escape(str(e))) |