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 |
1294.2.102
by William Grant
Replace the breadcrumb-h1 with proper breadcrumbs throughout the filesystem views. |
30 |
from ivle.webapp.filesystem import make_path_breadcrumbs |
1294.2.58
by William Grant
svnlog ported... |
31 |
from ivle.webapp import ApplicationRoot |
32 |
||
1099.1.54
by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with |
33 |
class SubversionLogView(XHTMLView): |
34 |
template = 'template.html' |
|
1251
by William Grant
Put Subversion diffs and logs in the Files tab. |
35 |
tab = 'files' |
1373
by William Grant
Improve the diff/log breadcrumbs. |
36 |
breadcrumb_text = 'Files' |
1099.1.54
by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with |
37 |
|
1294.2.60
by William Grant
Move the already-ported filesystem views to use subpaths. |
38 |
subpath_allowed = True |
39 |
||
1099.1.110
by William Grant
Implement an authorization system in the new framework. This breaks the REST |
40 |
def authorize(self, req): |
41 |
return req.user is not None |
|
42 |
||
1099.1.54
by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with |
43 |
def populate(self, req, ctx): |
1099.1.67
by William Grant
Port ivle.webapp.filesystem.{diff,svnlog}'s media to the new framework. |
44 |
self.plugin_styles[Plugin] = ['log.css'] |
1326.1.3
by David Coles
Add UI to allow updating to a particulalr revision from svnlog. |
45 |
self.plugin_scripts = { |
46 |
'ivle.webapp.filesystem.browser': ['browser.js'], |
|
47 |
Plugin: ['log.js'], |
|
48 |
}
|
|
49 |
self.scripts_init = ['log_init'] |
|
1099.1.54
by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with |
50 |
|
1222
by William Grant
Don't use ivle.conf in ivle.webapp.filesystem.svnlog. |
51 |
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 |
52 |
'services/svnlogservice') |
53 |
||
1222
by William Grant
Don't use ivle.conf in ivle.webapp.filesystem.svnlog. |
54 |
user_jail_dir = os.path.join(req.config['paths']['jails']['mounts'], |
55 |
req.user.login) |
|
1276
by William Grant
Drop ivle.conf usage from ivle.interpret. |
56 |
(out, err) = ivle.interpret.execute_raw(req.config, |
57 |
req.user, |
|
58 |
user_jail_dir, |
|
59 |
'/home', |
|
60 |
svnlogservice_path, |
|
1294.2.60
by William Grant
Move the already-ported filesystem views to use subpaths. |
61 |
[self.path] |
1276
by William Grant
Drop ivle.conf usage from ivle.interpret. |
62 |
)
|
1099.1.54
by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with |
63 |
assert not err |
64 |
||
65 |
response = cjson.decode(out) |
|
66 |
if 'error' in response: |
|
67 |
if response['error'] == 'notfound': |
|
68 |
raise NotFound() |
|
69 |
else: |
|
70 |
raise AssertionError('Unknown error from svnlogservice: %s' % |
|
71 |
response['error']) |
|
72 |
||
73 |
# No error. We must be safe.
|
|
1262
by William Grant
Pretty dates in SubversionLogView. |
74 |
ctx['format_datetime'] = ivle.date.make_date_nice |
75 |
ctx['format_datetime_short'] = ivle.date.format_datetime_for_paragraph |
|
76 |
||
1294.2.60
by William Grant
Move the already-ported filesystem views to use subpaths. |
77 |
ctx['path'] = self.path |
78 |
ctx['url'] = req.make_path(os.path.join('svnlog', self.path)) |
|
79 |
ctx['diffurl'] = req.make_path(os.path.join('diff', self.path)) |
|
80 |
ctx['title'] = os.path.normpath(self.path).rsplit('/', 1)[-1] |
|
1373
by William Grant
Improve the diff/log breadcrumbs. |
81 |
self.extra_breadcrumbs = make_path_breadcrumbs(req, self.subpath) |
82 |
self.extra_breadcrumbs.append(SubversionLogBreadcrumb()) |
|
1099.1.54
by William Grant
ivle.webapp.filesystem.svnlog: Port www/apps/svnlog to new framework. As with |
83 |
|
84 |
sr = ivle.svn.revision_from_string( |
|
85 |
req.get_fieldstorage().getfirst("r")) |
|
86 |
ctx['revno'] = sr.number if sr and \ |
|
87 |
sr.kind == pysvn.opt_revision_kind.number else None |
|
88 |
ctx['logs'] = response['logs'] |
|
89 |
||
90 |
# Create URLs for each of the versioned files.
|
|
91 |
# XXX: This scheme only works for stuff/!
|
|
92 |
for log in ctx['logs']: |
|
93 |
for pathaction in log['paths']: |
|
1210
by William Grant
Use Request.make_path everywhere. |
94 |
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 |
95 |
ivle.util.split_path(req.path)[0], |
96 |
pathaction[0][1:])) + '?r=%d' % log['revno']) |
|
97 |
||
1294.2.60
by William Grant
Move the already-ported filesystem views to use subpaths. |
98 |
@property
|
99 |
def path(self): |
|
100 |
return os.path.join(*self.subpath) if self.subpath else '' |
|
1294.2.58
by William Grant
svnlog ported... |
101 |
|
1373
by William Grant
Improve the diff/log breadcrumbs. |
102 |
|
103 |
class SubversionLogBreadcrumb(object): |
|
104 |
text = 'Subversion Log' |
|
105 |
||
106 |
||
1099.1.99
by William Grant
Require that plugins providing media subclass MediaPlugin. |
107 |
class Plugin(ViewPlugin, MediaPlugin): |
1294.2.60
by William Grant
Move the already-ported filesystem views to use subpaths. |
108 |
views = [(ApplicationRoot, 'svnlog', SubversionLogView)] |
1099.1.67
by William Grant
Port ivle.webapp.filesystem.{diff,svnlog}'s media to the new framework. |
109 |
|
110 |
media = 'media' |