~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 13:26:01 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-20090704132601-ree3krvgipef4uqz
Move the already-ported filesystem views to use subpaths.

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
34
from ivle.webapp import ApplicationRoot
36
35
 
37
 
class DiffFile(object):
38
 
    def __init__(self, root, path):
39
 
        self.root = root
40
 
        self.path = path
41
 
 
42
36
class DiffView(XHTMLView):
43
37
    '''A view to present a nice XHTML Subversion diff from a user's jail.'''
44
38
    template = 'template.html'
45
39
    tab = 'files'
46
40
 
 
41
    subpath_allowed = True
 
42
 
47
43
    def authorize(self, req):
48
44
        return req.user is not None
49
45
 
61
57
        (out, err) = ivle.interpret.execute_raw(req.config, req.user, jail_dir,
62
58
                            '/home', os.path.join(req.config['paths']['share'],
63
59
                                                  'services/diffservice'),
64
 
                            [self.context.path] + revs
 
60
                            [self.path] + revs
65
61
                            )
66
62
        assert not err
67
63
 
81
77
            r'^Index: (.*)\n\=+\n((?:[^I].*\n)*)',re.MULTILINE
82
78
        )
83
79
 
84
 
        ctx['title'] = os.path.normpath(self.context.path).rsplit('/', 1)[-1]
85
 
        ctx['paths'] = make_path_segments(self.context.path)
 
80
        ctx['title'] = os.path.normpath(self.path).rsplit('/', 1)[-1]
 
81
        ctx['paths'] = make_path_segments(self.path)
86
82
 
87
83
        # Create a dict with (name, HTMLdiff) pairs for each non-empty diff.
88
84
        ctx['files'] = dict([(fd[0], genshi.XML(htmlfy_diff(fd[1])))
89
85
                             for fd in diff_matcher.findall(diff)
90
86
                             if fd[1]])
91
87
 
 
88
    @property
 
89
    def path(self):
 
90
        return os.path.join(*self.subpath) if self.subpath else ''
 
91
 
92
92
 
93
93
def htmlfy_diff(difftext):
94
94
    """Adds HTML markup to a udiff string"""
111
111
 
112
112
    return '<pre class="diff">%s</pre>' % output
113
113
 
114
 
def root_to_difffile(root, *path):
115
 
    return DiffFile(root, os.path.join(*path) if path else '')
116
 
 
117
114
class Plugin(ViewPlugin, MediaPlugin):
118
 
    forward_routes = [(ApplicationRoot, 'diff', root_to_difffile, INF)]
119
 
    views = [(DiffFile, '+index', DiffView)]
 
115
    views = [(ApplicationRoot, 'diff', DiffView)]
120
116
 
121
117
    media = 'media'