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

« back to all changes in this revision

Viewing changes to services/svnlogservice

  • Committer: matt.giuca
  • Date: 2009-01-14 10:10:12 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:branches%2Fstorm:1132
The new ivle.database.User class is now used in Request and usrmgt, which
    means it is now almost universally used in favour of ivle.user.User (now
    deprecated).

Noticeable change: The minor bug where the change to a user object in the
    database is not reflected in the user's session (eg. changing nick doesn't
    update title until log out).

ivle.dispatch:
    Session now contains 'login' (username string) rather than 'user' (full
        ivle.user.User object). This is a unicode string now.

    req.user is now a ivle.database.User object rather than an ivle.user.User
        object. This makes for a whole lot of really subtle differences, but
        largely conforms to the same interface. Note that strings must now all
        be unicode.

    login: Removed use of ivle.db. Now uses User object.

    html: Now handles unicode login and config options.

ivle.db: Removed update_user. Now replaced with Storm model.

ivle.database: Renamed has_cap back to hasCap (saved for later). Fixed small
    unicode bug.

ivle.makeuser.make_svn_auth now takes a store object.

usrmgt-server: Use new User class.

userservice: Now uses User class internally.
    get_user action now returns ISO 8601 date format, rather than a
        time tuple. (Wasn't being used).
    get_user action no longer transmits local_password (small security risk;
        note that it wasn't possible to see this for any user other than
        yourself unless admin).

ivle.util - added function object_to_dict.

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-2009 The University of Melbourne
 
4
# Copyright (C) 2008 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
20
21
# Author: William Grant
 
22
# Date:   08/07/2008
21
23
 
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
 
'''
 
24
# A CGI script for viewing a Subversion log. Used by the svnlog app.
26
25
 
27
26
import os
28
 
import sys
29
 
 
30
 
import cjson
 
27
import time
 
28
import cgi
31
29
import pysvn
32
30
 
 
31
import ivle.cgirequest
 
32
import ivle.util
 
33
import ivle.date
33
34
import ivle.svn
34
35
 
 
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
 
35
100
try:
36
101
    client = pysvn.Client()
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]})
 
102
    logs = client.log(os.path.join('/home', req.path), discover_changed_paths=True)
 
103
    [req.write(pretty_log(log)) for log in logs]
47
104
except pysvn.ClientError, e:
48
 
    error = e[0]
49
 
 
50
 
    try:
51
 
        code = e[1][0][1]
52
 
        # See subversion/include/svn_error_codes.h.
53
 
        # 150000: ERR_ENTRY_NOT_FOUND
54
 
        # 155007: WC_NOT_DIRECTORY.
55
 
        # 160006: FS_NO_SUCH_REVISION
56
 
        # 160013: FS_NOT_FOUND
57
 
        # 200005: UNVERSIONED_RESOURCE
58
 
        if code in (150000, 155007, 160006, 160013, 200005):
59
 
            error = 'notfound'
60
 
        else:
61
 
            error = '%s (code %d)' % (error, code)
62
 
    except IndexError:
63
 
        pass
64
 
 
65
 
    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)))