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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2009-07-04 12:39:51 UTC
  • mto: (1294.4.2 ui-the-third)
  • mto: This revision was merged to the branch mainline in revision 1353.
  • Revision ID: grantw@unimelb.edu.au-20090704123951-xx2tomehfaofpgzu
Port the diff views.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
32
32
from ivle.webapp.errors import NotFound, BadRequest
33
33
from ivle.webapp.filesystem import make_path_segments
 
34
from ivle.webapp.urls import INF
 
35
from ivle.webapp import ApplicationRoot
 
36
 
 
37
class DiffFile(object):
 
38
    def __init__(self, root, path):
 
39
        self.root = root
 
40
        self.path = path
34
41
 
35
42
class DiffView(XHTMLView):
36
43
    '''A view to present a nice XHTML Subversion diff from a user's jail.'''
37
44
    template = 'template.html'
38
45
    tab = 'files'
39
46
 
40
 
    def __init__(self, req, path):
41
 
        self.path = path
42
 
 
43
47
    def authorize(self, req):
44
48
        return req.user is not None
45
49
 
57
61
        (out, err) = ivle.interpret.execute_raw(req.config, req.user, jail_dir,
58
62
                            '/home', os.path.join(req.config['paths']['share'],
59
63
                                                  'services/diffservice'),
60
 
                            [self.path] + revs
 
64
                            [self.context.path] + revs
61
65
                            )
62
66
        assert not err
63
67
 
77
81
            r'^Index: (.*)\n\=+\n((?:[^I].*\n)*)',re.MULTILINE
78
82
        )
79
83
 
80
 
        ctx['title'] = os.path.normpath(self.path).rsplit('/', 1)[-1]
81
 
        ctx['paths'] = make_path_segments(self.path)
 
84
        ctx['title'] = os.path.normpath(self.context.path).rsplit('/', 1)[-1]
 
85
        ctx['paths'] = make_path_segments(self.context.path)
82
86
 
83
87
        # Create a dict with (name, HTMLdiff) pairs for each non-empty diff.
84
88
        ctx['files'] = dict([(fd[0], genshi.XML(htmlfy_diff(fd[1])))
107
111
 
108
112
    return '<pre class="diff">%s</pre>' % output
109
113
 
 
114
def root_to_difffile(root, *path):
 
115
    return DiffFile(root, os.path.join(*path) if path else '')
 
116
 
110
117
class Plugin(ViewPlugin, MediaPlugin):
111
 
    '''Registration class for diff components.'''
112
 
    urls = [
113
 
        ('diff/', DiffView, {'path': ''}),
114
 
        ('diff/*(path)', DiffView),
115
 
    ]
 
118
    forward_routes = [(ApplicationRoot, 'diff', root_to_difffile, INF)]
 
119
    views = [(DiffFile, '+index', DiffView)]
116
120
 
117
121
    media = 'media'