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

« back to all changes in this revision

Viewing changes to scripts/interpretservice

  • Committer: mattgiuca
  • Date: 2008-02-05 01:41:15 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:409
Moved www/conf and www/common to a new directory lib. This separates the "web"
part of IVLE from what is becoming less web oriented (at least from Apache's
standpoint).
Modified setup.py to install this lib directory correctly and write conf in
the right place. Also adds the lib directory to ivle.pth.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
 
3
 
# IVLE - Informatics Virtual Learning Environment
4
 
# Copyright (C) 2007-2008 The University of Melbourne
5
 
#
6
 
# This program is free software; you can redistribute it and/or modify
7
 
# it under the terms of the GNU General Public License as published by
8
 
# the Free Software Foundation; either version 2 of the License, or
9
 
# (at your option) any later version.
10
 
#
11
 
# This program is distributed in the hope that it will be useful,
12
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
# GNU General Public License for more details.
15
 
#
16
 
# You should have received a copy of the GNU General Public License
17
 
# along with this program; if not, write to the Free Software
18
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 
20
 
# Script: interpretservice
21
 
# Author: David Coles
22
 
# Date:   6/3/2007
23
 
 
24
 
# A CGI script for interpreting files.
25
 
 
26
 
import mimetypes
27
 
import os
28
 
import sys
29
 
import conf
30
 
import StringIO
31
 
import urlparse
32
 
import subprocess
33
 
 
34
 
from common import (cgirequest, studpath)
35
 
 
36
 
req = cgirequest.CGIRequest()
37
 
req.install_error_handler()
38
 
 
39
 
# Work out the parts of the URL
40
 
url = urlparse.urlparse(req.path)
41
 
querystr = url[4]
42
 
urlpath = url[2]
43
 
username, _, filename = studpath.url_to_jailpaths(urlpath)
44
 
 
45
 
python = "/usr/bin/python"
46
 
 
47
 
# Everything should be done from the home directory
48
 
os.chdir(os.path.join('/home', username))
49
 
 
50
 
if filename is None:
51
 
    req.throw_error(req.HTTP_NOT_FOUND, "The path specified is invalid.")
52
 
elif not os.access(filename, os.R_OK):
53
 
    req.throw_error(req.HTTP_NOT_FOUND,
54
 
        "The specified file (%s) does not exist." % urlpath)
55
 
else:
56
 
    if os.path.isdir(filename):
57
 
        # 403 Forbidden error for visiting a directory
58
 
        # (Not giving a directory listing, since this can be seen by
59
 
        # the world at large. Directory contents are private).
60
 
        req.throw_error(req.HTTP_FORBIDDEN,
61
 
            "The path specified is a directory.")
62
 
    else:
63
 
        # We'll save on a fork and execute in this python process
64
 
        # Let exceptions blow up normally again
65
 
        sys.excepthook = sys.__excepthook__
66
 
        execfile(filename, {})
67
 
        
68
 
        # Non-Python process should probably use something like
69
 
        # subprocess.call([python, filename])