~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to services/svnlogservice

tutorial/media/tutorial.js: Now sets the shown/hidden properties of the
    "previous attempts" elements after the request returns, not before.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
3
# IVLE - Informatics Virtual Learning Environment
4
 
# Copyright (C) 2008 The University of Melbourne
 
4
# Copyright (C) 2008-2009 The University of Melbourne
5
5
#
6
6
# This program is free software; you can redistribute it and/or modify
7
7
# it under the terms of the GNU General Public License as published by
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
19
19
 
20
 
# Script: logservice
21
20
# Author: William Grant
22
 
# Date:   08/07/2008
23
21
 
24
 
# A CGI script for viewing a Subversion log. Used by the svnlog app.
 
22
'''
 
23
A script for viewing a Subversion log. It is intended to be run via trampoline
 
24
by ivle.webapp.filesystem.svnlog.SubversionLogView.
 
25
'''
25
26
 
26
27
import os
27
 
import time
28
 
import cgi
 
28
import sys
 
29
 
 
30
import cjson
29
31
import pysvn
30
32
 
31
 
import ivle.cgirequest
32
 
import ivle.util
33
 
import ivle.date
34
33
import ivle.svn
35
34
 
36
 
req = ivle.cgirequest.CGIRequest()
37
 
req.install_error_handler()
38
 
req.content_type = "text/html"
39
 
 
40
 
req.write('<h1>Subversion Log</h1>\n')
41
 
 
42
 
r_str = req.get_fieldstorage().getfirst("r")
43
 
sr = ivle.svn.revision_from_string(r_str)
44
 
 
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 = ivle.util.make_path(os.path.join('files',
51
 
                              ivle.util.split_path(req.path)[0],
52
 
                              path[1:]))
53
 
    if revno:
54
 
        url += '?r=%d' % revno
55
 
    return '%s <a href="%s">%s</a>' % (cpath['action'], cgi.escape(url, True),
56
 
                                       cgi.escape(path))
57
 
 
58
 
def pretty_paths(paths, revno=None):
59
 
    output = '<ul>'
60
 
    for path in paths:
61
 
        output += '<li>' + pretty_path(path, revno) + '</li>'
62
 
    output += '</ul>'
63
 
    return output
64
 
 
65
 
def pretty_log(log):
66
 
    revno = log.revision.number
67
 
    author = cgi.escape(log.author)
68
 
    message = cgi.escape(log.message)
69
 
    result = '''
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))
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(ivle.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(ivle.util.make_path(os.path.join('diff', req.path))),
87
 
              sr.number, revno)
88
 
 
89
 
    result += '''
90
 
        </div>
91
 
        <pre>%s</pre>
92
 
        <hr size="1"/>
93
 
        <h2>Changed paths:</h2>
94
 
        <div class="svnlogpathlist">
95
 
        %s
96
 
        </div>
97
 
</div>''' % (message, pretty_paths(log.changed_paths, log.revision.number))
98
 
    return result
99
 
 
100
35
try:
101
36
    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]
 
37
    client.exception_style = 1
 
38
    logs = client.log(os.path.join('/home', sys.argv[1]),
 
39
                      discover_changed_paths=True)
 
40
    print cjson.encode({'logs': [{'revno': log.revision.number,
 
41
                                  'author': log.author,
 
42
                                  'message': log.message,
 
43
                                  'date': log.date,
 
44
                                  'paths': [(p.path, p.action)
 
45
                                            for p in log.changed_paths]}
 
46
                                 for log in logs]})
104
47
except pysvn.ClientError, e:
105
 
    req.write('<p><b>Error:</b></p>\n')
106
 
    req.write('<pre>%s</pre>\n' % cgi.escape(str(e)))
 
48
    error = e[0]
 
49
 
 
50
    try:
 
51
        code = e[1][0][1]
 
52
        # See subversion/include/svn_error_codes.h.
 
53
        # 155007: WC_NOT_DIRECTORY.
 
54
        # 160013: FS_NOT_FOUND
 
55
        # 200005: UNVERSIONED_RESOURCE
 
56
        if code in (155007, 160013, 200005):
 
57
            error = 'notfound'
 
58
        else:
 
59
            error = '%s (code %d)' % (error, code) 
 
60
    except IndexError:
 
61
        pass
 
62
 
 
63
    print cjson.encode({'error': error})