17
17
# along with this program; if not, write to the Free Software
18
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
21
# Author: William Grant
23
A script for viewing a Subversion log. It is intended to be run via trampoline
24
by ivle.webapp.filesystem.svnlog.SubversionLogView.
24
# A CGI script for viewing a Subversion log. Used by the svnlog app.
31
import ivle.cgirequest
37
locale.setlocale(locale.LC_CTYPE, "en_US.UTF-8")
36
req = ivle.cgirequest.CGIRequest()
37
req.install_error_handler()
38
req.content_type = "text/html"
40
req.write('<h1>Subversion Log</h1>\n')
42
r_str = req.get_fieldstorage().getfirst("r")
43
sr = ivle.svn.revision_from_string(r_str)
45
def pretty_path(cpath, revno=None):
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
50
url = ivle.util.make_path(os.path.join('files',
51
ivle.util.split_path(req.path)[0],
54
url += '?r=%d' % revno
55
return '%s <a href="%s">%s</a>' % (cpath['action'], cgi.escape(url, True),
58
def pretty_paths(paths, revno=None):
61
output += '<li>' + pretty_path(path, revno) + '</li>'
66
revno = log.revision.number
67
author = cgi.escape(log.author)
68
message = cgi.escape(log.message)
70
<div class="svnlogentry">
71
<div class="svnloginfo">
72
Revision <a href="%s?r=%d" style="font-weight: bold">%d</a>
73
by <strong>%s</strong> on <strong>%s</strong>
74
''' % (cgi.escape(ivle.util.make_path(os.path.join('files', req.path))),
75
revno, revno, author, ivle.date.make_date_nice(log.date))
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]'
81
result += '<a href="%s?r=%d">[select]</a>' % (
82
cgi.escape(ivle.util.make_path(os.path.join('svnlog', req.path))),
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(ivle.util.make_path(os.path.join('diff', req.path))),
93
<h2>Changed paths:</h2>
94
<div class="svnlogpathlist">
97
</div>''' % (message, pretty_paths(log.changed_paths, log.revision.number))
40
101
client = pysvn.Client()
41
client.exception_style = 1
42
logs = client.log(os.path.join('/home', sys.argv[1].decode('utf-8')),
43
discover_changed_paths=True)
44
print cjson.encode({'logs': [{'revno': log.revision.number,
45
'author': log.author.decode('utf-8'),
46
'message': log.message.decode('utf-8'),
48
'paths': [(p.path.decode('utf-8'), p.action)
49
for p in log.changed_paths]}
102
logs = client.log(os.path.join('/home', req.path), discover_changed_paths=True)
103
[req.write(pretty_log(log)) for log in logs]
51
104
except pysvn.ClientError, e:
56
# See subversion/include/svn_error_codes.h.
57
# 150000: ERR_ENTRY_NOT_FOUND
58
# 155007: WC_NOT_DIRECTORY.
59
# 160006: FS_NO_SUCH_REVISION
60
# 160013: FS_NOT_FOUND
61
# 200005: UNVERSIONED_RESOURCE
62
if code in (150000, 155007, 160006, 160013, 200005):
65
error = '%s (code %d)' % (error, code)
69
print cjson.encode({'error': error})
105
req.write('<p><b>Error:</b></p>\n')
106
req.write('<pre>%s</pre>\n' % cgi.escape(str(e)))