32
32
root_dir = conf.root_dir
34
class IVLEError(Exception):
36
This is the "standard" exception class for IVLE errors.
37
It is the ONLY exception which should propagate to the top - it will then
38
be displayed to the user as an HTTP error with the given code.
40
All other exceptions are considered IVLE bugs and should not occur
41
(they will display a traceback).
43
This error should not be raised directly. Call req.throw_error.
45
def __init__(self, httpcode, message=None):
46
self.httpcode = httpcode
47
self.message = message
48
self.args = (httpcode, message)
50
class IVLEJailError(Exception):
52
This exception indicates an error that occurred inside an IVLE CGI script
53
inside the jail. It should never be raised directly - only by the
56
Information will be retrieved from it, and then treated as a normal
59
def __init__(self, type_str, message, info):
60
self.type_str = type_str
61
self.message = message
34
64
def make_path(path):
35
65
"""Given a path relative to the IVLE root, makes the path relative to the
36
66
site root using conf.root_dir. This path can be used in URLs sent to the
95
125
return tuple(splitpath)
127
def open_exercise_file(exercisename):
128
"""Given an exercise name, opens the corresponding XML file for reading.
129
Returns None if the exercise file was not found.
130
(For tutorials / worksheets).
132
# First normalise the path
133
exercisename = os.path.normpath(exercisename)
134
# Now if it begins with ".." or separator, then it's illegal
135
if exercisename.startswith("..") or exercisename.startswith(os.sep):
138
exercisefile = os.path.join(conf.exercises_base, exercisename)
141
return open(exercisefile)
142
except (TypeError, IOError): # TypeError if exercisefile == None
97
145
# Initialise mime types library
99
147
for (ext, mimetype) in conf.mimetypes.additional_mime_types.items():
118
166
return filename[filename.rindex('.')+1:].upper() + " file"
119
167
except ValueError:
170
def send_terms_of_service(req):
172
Sends the Terms of Service document to the req object.
173
This consults conf to find out where the TOS is located on disk, and sends
174
that. If it isn't found, it sends a generic message explaining to admins
175
how to create a real one.
178
req.sendfile(conf.tos_path)
181
"""<h1>Terms of Service</h1>
182
<p><b>*** SAMPLE ONLY ***</b></p>
183
<p>This is the text of the IVLE Terms of Service.</p>
184
<p>The administrator should create a license file with an appropriate
185
"Terms of Service" license for your organisation.</p>
186
<h2>Instructions for Administrators</h2>
187
<p>You are seeing this message because you have not configured a Terms of
188
Service document.</p>
189
<p>When you configured IVLE, you specified a path to the Terms of Service
190
document (this is found in <b><tt>lib/conf/conf.py</tt></b> under
191
"<tt>tos_path</tt>").</p>
192
<p>Create a file at this location; an HTML file with the appropriately-worded
194
<p>This should be a normal XHTML file, except it should not contain
195
<tt>html</tt>, <tt>head</tt> or <tt>body</tt> elements - it should
196
just be the contents of a body element (IVLE will wrap it accordingly).</p>
197
<p>This will automatically be used as the license text instead of this
198
placeholder text.</p>