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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2009-02-23 23:47:02 UTC
  • mfrom: (1099.1.211 new-dispatch)
  • Revision ID: grantw@unimelb.edu.au-20090223234702-db4b1llly46ignwo
Merge from lp:~ivle-dev/ivle/new-dispatch.

Pretty much everything changes. Reread the setup docs. Backup your databases.
Every file is now in a different installed location, the configuration system
is rewritten, the dispatch system is rewritten, URLs are different, the
database is different, worksheets and exercises are no longer on the
filesystem, we use a templating engine, jail service protocols are rewritten,
we don't repeat ourselves, we have authorization rewritten, phpBB is gone,
and probably lots of other things that I cannot remember.

This is certainly the biggest commit I have ever made, and hopefully
the largest I ever will.

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 ViewPlugin, MediaPlugin
 
30
from ivle.webapp.errors import NotFound, BadRequest
 
31
 
 
32
class SubversionLogView(XHTMLView):
 
33
    template = 'template.html'
 
34
 
 
35
    def authorize(self, req):
 
36
        return req.user is not None
 
37
 
 
38
    def populate(self, req, ctx):
 
39
        self.plugin_styles[Plugin] = ['log.css']
 
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
 
 
76
class Plugin(ViewPlugin, MediaPlugin):
 
77
    urls = [
 
78
        ('/svnlog', SubversionLogView, {'path': ''}),
 
79
        ('/svnlog/*path', SubversionLogView),
 
80
    ]
 
81
 
 
82
    media = 'media'