~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
1253 by William Grant
Replace SubversionLogView's "Subversion Log" titles with more BrowserView-esque ones.
30
from ivle.webapp.filesystem import make_path_segments
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
31
32
class SubversionLogView(XHTMLView):
33
    template = 'template.html'
1251 by William Grant
Put Subversion diffs and logs in the Files tab.
34
    tab = 'files'
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
35
1099.1.110 by William Grant
Implement an authorization system in the new framework. This breaks the REST
36
    def authorize(self, req):
37
        return req.user is not None
38
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
39
    def populate(self, req, ctx):
1099.1.67 by William Grant
Port ivle.webapp.filesystem.{diff,svnlog}'s media to the new framework.
40
        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
41
1222 by William Grant
Don't use ivle.conf in ivle.webapp.filesystem.svnlog.
42
        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
43
                                          'services/svnlogservice')
44
1222 by William Grant
Don't use ivle.conf in ivle.webapp.filesystem.svnlog.
45
        user_jail_dir = os.path.join(req.config['paths']['jails']['mounts'],
46
                                     req.user.login)
1276 by William Grant
Drop ivle.conf usage from ivle.interpret.
47
        (out, err) = ivle.interpret.execute_raw(req.config,
48
                                                req.user,
49
                                                user_jail_dir,
50
                                                '/home',
51
                                                svnlogservice_path,
52
                                                [self.path]
53
                                                )
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
54
        assert not err
55
56
        response = cjson.decode(out)
57
        if 'error' in response:
58
            if response['error'] == 'notfound':
59
                raise NotFound()
60
            else:
61
                raise AssertionError('Unknown error from svnlogservice: %s' %
62
                                     response['error'])
63
64
        # No error. We must be safe.
1262 by William Grant
Pretty dates in SubversionLogView.
65
        ctx['format_datetime'] = ivle.date.make_date_nice
66
        ctx['format_datetime_short'] = ivle.date.format_datetime_for_paragraph
67
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
68
        ctx['path'] = self.path
1210 by William Grant
Use Request.make_path everywhere.
69
        ctx['url'] = req.make_path(os.path.join('svnlog', self.path))
1257 by William Grant
Fix the 'diff' link in the log viewer to diff, rather than log.
70
        ctx['diffurl'] = req.make_path(os.path.join('diff', self.path))
1291 by William Grant
Fix browser/diff/svnlog titles for paths with trailing slashes.
71
        ctx['title'] = os.path.normpath(self.path).rsplit('/', 1)[-1]
1253 by William Grant
Replace SubversionLogView's "Subversion Log" titles with more BrowserView-esque ones.
72
        ctx['paths'] = make_path_segments(self.path)
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
73
74
        sr = ivle.svn.revision_from_string(
75
                   req.get_fieldstorage().getfirst("r"))
76
        ctx['revno'] = sr.number if sr and \
77
                       sr.kind == pysvn.opt_revision_kind.number else None
78
        ctx['logs'] = response['logs']
79
80
        # Create URLs for each of the versioned files.
81
        # XXX: This scheme only works for stuff/!
82
        for log in ctx['logs']:
83
            for pathaction in log['paths']:
1210 by William Grant
Use Request.make_path everywhere.
84
                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
85
                                  ivle.util.split_path(req.path)[0],
86
                                  pathaction[0][1:])) + '?r=%d' % log['revno'])
87
1099.1.99 by William Grant
Require that plugins providing media subclass MediaPlugin.
88
class Plugin(ViewPlugin, MediaPlugin):
1099.1.54 by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with
89
    urls = [
90
        ('/svnlog', SubversionLogView, {'path': ''}),
91
        ('/svnlog/*path', SubversionLogView),
92
    ]
1099.1.67 by William Grant
Port ivle.webapp.filesystem.{diff,svnlog}'s media to the new framework.
93
94
    media = 'media'