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

« back to all changes in this revision

Viewing changes to lib/common/util.py

  • Committer: dcoles
  • Date: 2008-07-23 07:38:03 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:944
Special Home Directory: Work to create a special home directory that shows the 
subjects you are enrolled in, the repositories that you have for those subjects 
and aranges the files in a sensible fashion. (See bugtracker [ 2010232 ] Home 
directory: special user interface)

This should also support showing group repositories at a later date.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
        self.message = message
48
48
        self.args = (httpcode, message)
49
49
 
 
50
class IVLEJailError(Exception):
 
51
    """
 
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 
 
54
    interpreter.
 
55
 
 
56
    Information will be retrieved from it, and then treated as a normal
 
57
    error.
 
58
    """
 
59
    def __init__(self, type_str, message, info):
 
60
        self.type_str = type_str
 
61
        self.message = message
 
62
        self.info = info
 
63
 
50
64
def make_path(path):
51
65
    """Given a path relative to the IVLE root, makes the path relative to the
52
66
    site root using conf.root_dir. This path can be used in URLs sent to the
110
124
    else:
111
125
        return tuple(splitpath)
112
126
 
 
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).
 
131
    """
 
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):
 
136
        exercisefile = None
 
137
    else:
 
138
        exercisefile = os.path.join(conf.exercises_base, exercisename)
 
139
 
 
140
    try:
 
141
        return open(exercisefile)
 
142
    except (TypeError, IOError):    # TypeError if exercisefile == None
 
143
        return None
 
144
 
113
145
# Initialise mime types library
114
146
mimetypes.init()
115
147
for (ext, mimetype) in conf.mimetypes.additional_mime_types.items():
134
166
                return filename[filename.rindex('.')+1:].upper() + " file"
135
167
            except ValueError:
136
168
                return "File"
 
169
 
 
170
def send_terms_of_service(req):
 
171
    """
 
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.
 
176
    """
 
177
    try:
 
178
        req.sendfile(conf.tos_path)
 
179
    except IOError:
 
180
        req.write(
 
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
 
193
license.</p>
 
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>
 
199
""")