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

« back to all changes in this revision

Viewing changes to ivle/webapp/filesystem/svnlog/__init__.py

ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
    ivle.webapp.filesystem.diff, this involves moving things around and
    making services/svnlogservice return JSON.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# IVLE
2
 
# Copyright (C) 2008 The University of Melbourne
 
1
# IVLE - Informatics Virtual Learning Environment
 
2
# Copyright (C) 2007-2009 The University of Melbourne
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
5
5
# it under the terms of the GNU General Public License as published by
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
17
 
18
 
# App: SVN Log Service
19
18
# Author: William Grant
20
 
# Date: 08/07/2008
21
 
 
22
 
# This is merely a wrapper around the trampolined svnlogservice.
23
19
 
24
20
import os
25
21
 
 
22
import cjson
 
23
import pysvn
 
24
 
26
25
import ivle.conf
 
26
import ivle.date
27
27
import ivle.interpret
28
 
 
29
 
def handle(req):
30
 
    """Handler for Subversion log functionality."""
31
 
    req.styles = ["media/svn/log.css"]
32
 
    req.write_html_head_foot = True
33
 
 
34
 
    if req.path == "":
35
 
        req.throw_redirect(os.path.join(req.uri, req.user.login))
36
 
    interpreter = ivle.interpret.interpreter_objects["cgi-python"]
37
 
    jail_dir = os.path.join(ivle.conf.jail_base, req.user.login)
38
 
    ivle.interpret.interpret_file(req, req.user, jail_dir,
39
 
          os.path.join(ivle.conf.share_path, 'services/svnlogservice'),
40
 
          interpreter)
41
 
 
42
 
 
 
28
from ivle.webapp.base.xhtml import XHTMLView
 
29
from ivle.webapp.base.plugins import BasePlugin
 
30
from ivle.webapp.errors import NotFound, BadRequest
 
31
 
 
32
class SubversionLogView(XHTMLView):
 
33
    template = 'template.html'
 
34
 
 
35
    def populate(self, req, ctx):
 
36
        req.styles = ["/media/svn/log.css"]
 
37
 
 
38
        svnlogservice_path = os.path.join(ivle.conf.share_path,
 
39
                                          'services/svnlogservice')
 
40
 
 
41
        user_jail_dir = os.path.join(ivle.conf.jail_base, req.user.login)
 
42
        (out, err) = ivle.interpret.execute_raw(req.user, user_jail_dir,
 
43
                             '/home', svnlogservice_path, [self.path])
 
44
        assert not err
 
45
 
 
46
        response = cjson.decode(out)
 
47
        if 'error' in response:
 
48
            if response['error'] == 'notfound':
 
49
                raise NotFound()
 
50
            else:
 
51
                raise AssertionError('Unknown error from svnlogservice: %s' %
 
52
                                     response['error'])
 
53
 
 
54
        # No error. We must be safe.
 
55
        ctx['path'] = self.path
 
56
        ctx['url'] = ivle.util.make_path(os.path.join('svnlog', self.path))
 
57
 
 
58
        sr = ivle.svn.revision_from_string(
 
59
                   req.get_fieldstorage().getfirst("r"))
 
60
        ctx['revno'] = sr.number if sr and \
 
61
                       sr.kind == pysvn.opt_revision_kind.number else None
 
62
        ctx['logs'] = response['logs']
 
63
 
 
64
        # Create URLs for each of the versioned files.
 
65
        # XXX: This scheme only works for stuff/!
 
66
        for log in ctx['logs']:
 
67
            log['date'] = ivle.date.make_date_nice(log['date'])
 
68
            for pathaction in log['paths']:
 
69
                pathaction.append(ivle.util.make_path(os.path.join('files',
 
70
                                  ivle.util.split_path(req.path)[0],
 
71
                                  pathaction[0][1:])) + '?r=%d' % log['revno'])
 
72
 
 
73
class Plugin(BasePlugin):
 
74
    urls = [
 
75
        ('/svnlog', SubversionLogView, {'path': ''}),
 
76
        ('/svnlog/*path', SubversionLogView),
 
77
    ]