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

413 by mattgiuca
fileservice: Accidentally forgot to add __init__.py. (So last commit was an
1
# IVLE
1099.1.152 by William Grant
Quick port of fileservice to the new framework. It's still very much old-style,
2
# Copyright (C) 2007-2009 The University of Melbourne
413 by mattgiuca
fileservice: Accidentally forgot to add __init__.py. (So last commit was an
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
1099.1.152 by William Grant
Quick port of fileservice to the new framework. It's still very much old-style,
18
# Author: Matt Giuca, Will Grant
19
20
'''Service for accessing a jail's filesystem.
21
22
This application is a wrapper around the library module fileservice, running
23
it through trampoline.
24
25
It receives file handling instructions as requests, performs actions on the
26
student's workspace, and returns directory listings in JSON.
27
28
See the documentation in ivle.fileservice_lib for details.
29
'''
413 by mattgiuca
fileservice: Accidentally forgot to add __init__.py. (So last commit was an
30
421 by mattgiuca
apps/fileservice: Added code to call interpret on the trampoline version of
31
import os.path
32
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
33
import ivle.interpret
1099.1.152 by William Grant
Quick port of fileservice to the new framework. It's still very much old-style,
34
from ivle.webapp.base.views import BaseView
35
from ivle.webapp.base.plugins import ViewPlugin
1294.2.54 by William Grant
Port fileservice.
36
from ivle.webapp import ApplicationRoot
37
1099.1.152 by William Grant
Quick port of fileservice to the new framework. It's still very much old-style,
38
# XXX: Writes to req directly. This is a direct port of the legacy version.
39
#      This needs to be rewritten soon.
40
class FileserviceView(BaseView):
1294.2.60 by William Grant
Move the already-ported filesystem views to use subpaths.
41
    subpath_allowed = True
42
1099.1.152 by William Grant
Quick port of fileservice to the new framework. It's still very much old-style,
43
    def authorize(self, req):
44
        return req.user is not None
45
46
    def render(self, req):
47
        """Handler for the File Services application."""
1294.2.60 by William Grant
Move the already-ported filesystem views to use subpaths.
48
        if len(self.path) == 0:
1099.1.152 by William Grant
Quick port of fileservice to the new framework. It's still very much old-style,
49
            # If no path specified, default to the user's home directory
1210 by William Grant
Use Request.make_path everywhere.
50
            req.throw_redirect(req.make_path(os.path.join('fileservice',
51
                                                          req.user.login)))
1099.1.152 by William Grant
Quick port of fileservice to the new framework. It's still very much old-style,
52
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
53
        interp_object = ivle.interpret.interpreter_objects["cgi-python"]
1223 by William Grant
No more ivle.conf in ivle.webapp.fileservice...
54
        user_jail_dir = os.path.join(req.config['paths']['jails']['mounts'],
55
                                     req.user.login)
56
1080.1.66 by William Grant
ivle.interpret.interpret_file: Take a User object as the owner, not a login.
57
        ivle.interpret.interpret_file(req, req.user, user_jail_dir,
1223 by William Grant
No more ivle.conf in ivle.webapp.fileservice...
58
                                  os.path.join(req.config['paths']['share'],
59
                                               'services/fileservice'),
60
                                  interp_object, gentle=False)
1099.1.152 by William Grant
Quick port of fileservice to the new framework. It's still very much old-style,
61
1294.2.60 by William Grant
Move the already-ported filesystem views to use subpaths.
62
    @property
63
    def path(self):
64
        return os.path.join(*self.subpath) if self.subpath else ''
1294.2.54 by William Grant
Port fileservice.
65
1099.1.152 by William Grant
Quick port of fileservice to the new framework. It's still very much old-style,
66
class Plugin(ViewPlugin):
1294.2.60 by William Grant
Move the already-ported filesystem views to use subpaths.
67
    views = [(ApplicationRoot, 'fileservice', FileserviceView)]