~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.conf
34
import ivle.interpret
35
import ivle.util
1099.1.152 by William Grant
Quick port of fileservice to the new framework. It's still very much old-style,
36
from ivle.webapp.base.views import BaseView
37
from ivle.webapp.base.plugins import ViewPlugin
421 by mattgiuca
apps/fileservice: Added code to call interpret on the trampoline version of
38
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
39
fileservice_path = os.path.join(ivle.conf.share_path, 'services/fileservice')
413 by mattgiuca
fileservice: Accidentally forgot to add __init__.py. (So last commit was an
40
1099.1.152 by William Grant
Quick port of fileservice to the new framework. It's still very much old-style,
41
# XXX: Writes to req directly. This is a direct port of the legacy version.
42
#      This needs to be rewritten soon.
43
44
class FileserviceView(BaseView):
45
    def __init__(self, req, path):
46
        # XXX: Still depends on req.path internally.
47
        self.path = path
48
49
    def authorize(self, req):
50
        return req.user is not None
51
52
    def render(self, req):
53
        """Handler for the File Services application."""
54
        if len(self.path) == 0:
55
            # If no path specified, default to the user's home directory
56
            req.throw_redirect(ivle.util.make_path(os.path.join('fileservice',
57
                                                           req.user.login)))
58
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
59
        interp_object = ivle.interpret.interpreter_objects["cgi-python"]
60
        user_jail_dir = os.path.join(ivle.conf.jail_base, req.user.login)
1080.1.66 by William Grant
ivle.interpret.interpret_file: Take a User object as the owner, not a login.
61
        ivle.interpret.interpret_file(req, req.user, user_jail_dir,
843 by wagrant
Give interpret_file a gentle mode (on by default, to avoid change in
62
            fileservice_path, 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,
63
64
class Plugin(ViewPlugin):
65
    urls = [
66
        ('fileservice/*path', FileserviceView),
67
        ('fileservice', FileserviceView, {'path': ''}),
68
    ]