~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
25
import ivle.date
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
26
import ivle.interpret
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
27
from ivle.webapp.base.xhtml import XHTMLView
1099.1.99 by William Grant
Require that plugins providing media subclass MediaPlugin.
28
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
29
from ivle.webapp.errors import NotFound, BadRequest
30
31
class SubversionLogView(XHTMLView):
32
    template = 'template.html'
33
1099.1.110 by William Grant
Implement an authorization system in the new framework. This breaks the REST
34
    def authorize(self, req):
35
        return req.user is not None
36
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
37
    def populate(self, req, ctx):
1099.1.67 by William Grant
Port ivle.webapp.filesystem.{diff,svnlog}'s media to the new framework.
38
        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
39
1222 by William Grant
Don't use ivle.conf in ivle.webapp.filesystem.svnlog.
40
        svnlogservice_path = os.path.join(req.config['paths']['share'],
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
41
                                          'services/svnlogservice')
42
1222 by William Grant
Don't use ivle.conf in ivle.webapp.filesystem.svnlog.
43
        user_jail_dir = os.path.join(req.config['paths']['jails']['mounts'],
44
                                     req.user.login)
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
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
1210 by William Grant
Use Request.make_path everywhere.
59
        ctx['url'] = req.make_path(os.path.join('svnlog', self.path))
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
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']:
1210 by William Grant
Use Request.make_path everywhere.
72
                pathaction.append(req.make_path(os.path.join('files',
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
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'