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

1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
1
# IVLE - Informatics Virtual Learning Environment
2
# Copyright (C) 2007-2009 The University of Melbourne
830 by wagrant
Add an svnlog app. It nicely displays all log entries for a path,
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18
# Author: William Grant
19
20
import os
21
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
22
import cjson
23
import pysvn
24
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
25
import ivle.conf
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
26
import ivle.date
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
27
import ivle.interpret
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
28
from ivle.webapp.base.xhtml import XHTMLView
1099.1.99 by William Grant
Require that plugins providing media subclass MediaPlugin.
29
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
30
from ivle.webapp.errors import NotFound, BadRequest
31
32
class SubversionLogView(XHTMLView):
33
    template = 'template.html'
34
1099.1.110 by William Grant
Implement an authorization system in the new framework. This breaks the REST
35
    def authorize(self, req):
36
        return req.user is not None
37
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
38
    def populate(self, req, ctx):
1099.1.67 by William Grant
Port ivle.webapp.filesystem.{diff,svnlog}'s media to the new framework.
39
        self.plugin_styles[Plugin] = ['log.css']
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
40
41
        svnlogservice_path = os.path.join(ivle.conf.share_path,
42
                                          'services/svnlogservice')
43
44
        user_jail_dir = os.path.join(ivle.conf.jail_base, req.user.login)
45
        (out, err) = ivle.interpret.execute_raw(req.user, user_jail_dir,
46
                             '/home', svnlogservice_path, [self.path])
47
        assert not err
48
49
        response = cjson.decode(out)
50
        if 'error' in response:
51
            if response['error'] == 'notfound':
52
                raise NotFound()
53
            else:
54
                raise AssertionError('Unknown error from svnlogservice: %s' %
55
                                     response['error'])
56
57
        # No error. We must be safe.
58
        ctx['path'] = self.path
59
        ctx['url'] = ivle.util.make_path(os.path.join('svnlog', self.path))
60
61
        sr = ivle.svn.revision_from_string(
62
                   req.get_fieldstorage().getfirst("r"))
63
        ctx['revno'] = sr.number if sr and \
64
                       sr.kind == pysvn.opt_revision_kind.number else None
65
        ctx['logs'] = response['logs']
66
67
        # Create URLs for each of the versioned files.
68
        # XXX: This scheme only works for stuff/!
69
        for log in ctx['logs']:
70
            log['date'] = ivle.date.make_date_nice(log['date'])
71
            for pathaction in log['paths']:
72
                pathaction.append(ivle.util.make_path(os.path.join('files',
73
                                  ivle.util.split_path(req.path)[0],
74
                                  pathaction[0][1:])) + '?r=%d' % log['revno'])
75
1099.1.99 by William Grant
Require that plugins providing media subclass MediaPlugin.
76
class Plugin(ViewPlugin, MediaPlugin):
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
77
    urls = [
78
        ('/svnlog', SubversionLogView, {'path': ''}),
79
        ('/svnlog/*path', SubversionLogView),
80
    ]
1099.1.67 by William Grant
Port ivle.webapp.filesystem.{diff,svnlog}'s media to the new framework.
81
82
    media = 'media'