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

« back to all changes in this revision

Viewing changes to setup/util.py

  • Committer: William Grant
  • Date: 2009-02-23 23:47:02 UTC
  • mfrom: (1099.1.211 new-dispatch)
  • Revision ID: grantw@unimelb.edu.au-20090223234702-db4b1llly46ignwo
Merge from lp:~ivle-dev/ivle/new-dispatch.

Pretty much everything changes. Reread the setup docs. Backup your databases.
Every file is now in a different installed location, the configuration system
is rewritten, the dispatch system is rewritten, URLs are different, the
database is different, worksheets and exercises are no longer on the
filesystem, we use a templating engine, jail service protocols are rewritten,
we don't repeat ourselves, we have authorization rewritten, phpBB is gone,
and probably lots of other things that I cannot remember.

This is certainly the biggest commit I have ever made, and hopefully
the largest I ever will.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
__all__ = ['PYTHON_VERSION', 'copy_file_to_jail', 'RunError',
35
35
           'action_runprog', 'action_remove', 'action_rename', 'action_mkdir',
36
36
           'action_copytree', 'action_copylist', 'action_copyfile',
37
 
           'action_symlink', 'action_append', 'action_chown',
 
37
           'action_symlink', 'action_chown',
38
38
           'action_chown_setuid', 'action_chmod_x', 'action_make_private',
39
 
           'query_user', 'filter_mutate', 'get_svn_revision', 'InstallList',
40
 
           'wwwuid']
 
39
           'filter_mutate', 'get_svn_revision', 'InstallList',
 
40
           'make_install_path', 'wwwuid']
41
41
 
42
42
# Determine which Python version (2.4 or 2.5, for example) we are running,
43
43
# and use that as the filename to the Python directory.
195
195
    if not dry:
196
196
        os.symlink(src, dst)
197
197
 
198
 
def action_append(ivle_pth, ivle_www):
199
 
    file = open(ivle_pth, 'a+')
200
 
    file.write(ivle_www + '\n')
201
 
    file.close()
202
 
 
203
198
def action_chown_setuid(file, dry):
204
199
    """Chowns a file to root, and sets the setuid bit on the file.
205
200
    Calling this function requires the euid to be root.
235
230
    if not dry:
236
231
        os.chmod(file, stat.S_IRUSR | stat.S_IWUSR)
237
232
 
238
 
def query_user(default, prompt):
239
 
    """Prompts the user for a string, which is read from a line of stdin.
240
 
    Exits silently if EOF is encountered. Returns the string, with spaces
241
 
    removed from the beginning and end.
242
 
 
243
 
    Returns default if a 0-length line (after spaces removed) was read.
244
 
    """
245
 
    if default is None:
246
 
        # A default of None means the value will be computed specially, so we
247
 
        # can't really tell you what it is
248
 
        defaultstr = "computed"
249
 
    elif isinstance(default, basestring):
250
 
        defaultstr = '"%s"' % default
251
 
    else:
252
 
        defaultstr = repr(default)
253
 
    sys.stdout.write('%s\n    (default: %s)\n>' % (prompt, defaultstr))
254
 
    try:
255
 
        val = sys.stdin.readline()
256
 
    except KeyboardInterrupt:
257
 
        # Ctrl+C
258
 
        sys.stdout.write("\n")
259
 
        sys.exit(1)
260
 
    sys.stdout.write("\n")
261
 
    # If EOF, exit
262
 
    if val == '': sys.exit(1)
263
 
    # If empty line, return default
264
 
    val = val.strip()
265
 
    if val == '': return default
266
 
    return val
267
 
 
268
233
def filter_mutate(function, list):
269
234
    """Like built-in filter, but mutates the given list instead of returning a
270
235
    new one. Returns None."""
292
257
installlist_mimetypes = ['text/x-python', 'text/html',
293
258
    'application/x-javascript', 'application/javascript',
294
259
    'text/css', 'image/png', 'image/gif', 'application/xml']
 
260
# Filenames which will automatically be placed in the list by InstallList.
 
261
whitelist_filenames = ['ivle-spec.conf']
295
262
 
296
263
def build_list_py_files(dir, no_top_level=False):
297
264
    """Builds a list of all py files found in a directory and its
305
272
        filter_mutate(lambda x: x[0] != '.', dirnames)
306
273
        # All *.py files are added to the list
307
274
        pylist += [os.path.join(dirpath, item) for item in filenames
308
 
            if mimetypes.guess_type(item)[0] in installlist_mimetypes]
 
275
            if mimetypes.guess_type(item)[0] in installlist_mimetypes or
 
276
               item in whitelist_filenames]
309
277
    if no_top_level:
310
278
        for i in range(0, len(pylist)):
311
279
            _, pylist[i] = pylist[i].split(os.sep, 1)
312
280
    return pylist
313
281
 
 
282
def make_install_path(rootdir, path):
 
283
    '''Combine an installation root directory and final install path.
 
284
 
 
285
    Normalises path, and joins it to the end of rootdir, removing the leading
 
286
    / to make it relative if required.
 
287
    '''
 
288
    normpath = os.path.normpath(path)
 
289
    if normpath.startswith(os.sep):
 
290
        normpath = normpath[1:]
 
291
    return os.path.join(rootdir, normpath)
 
292
 
314
293
class InstallList(object):
315
 
    # We build two separate lists, by walking www and console
316
 
    list_www = property(lambda self: build_list_py_files('www'))
317
 
 
318
294
    list_ivle_lib = property(lambda self: build_list_py_files('ivle'))
319
295
 
320
296
    list_subjects = property(lambda self: build_list_py_files('subjects',
327
303
        "services/python-console",
328
304
        "services/fileservice",
329
305
        "services/serveservice",
330
 
        "services/interpretservice",
331
306
        "services/usrmgt-server",
332
307
        "services/diffservice",
333
308
        "services/svnlogservice",
 
309
        "services/usrmgt-server", # XXX: Should be in bin/
334
310
    ]
335
311
 
336
312
    list_user_binaries = [
342
318
        "bin/ivle-mountallusers",
343
319
        "bin/ivle-remakeuser",
344
320
        "bin/ivle-showenrolment",
 
321
        "bin/ivle-config",
 
322
        "bin/ivle-createdatadirs",
 
323
        "bin/ivle-buildjail",
345
324
    ]