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

« back to all changes in this revision

Viewing changes to setup/util.py

  • Committer: me at id
  • Date: 2009-01-15 03:02:36 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:branches%2Fstorm:1150
ivle.makeuser.make_jail: Just take an ivle.database.User, rather than some
    attributes.

services/usrmgt-server: Give make_jail a User.

bin/ivle-remakeuser: Rewrite to use ivle.database.User.

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_chown',
 
37
           'action_symlink', 'action_append', 'action_chown',
38
38
           'action_chown_setuid', 'action_chmod_x', 'action_make_private',
39
 
           'filter_mutate', 'get_svn_revision', 'InstallList',
40
 
           'make_install_path', 'wwwuid']
 
39
           'query_user', 'filter_mutate', 'get_svn_revision', 'InstallList',
 
40
           '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
 
198
203
def action_chown_setuid(file, dry):
199
204
    """Chowns a file to root, and sets the setuid bit on the file.
200
205
    Calling this function requires the euid to be root.
230
235
    if not dry:
231
236
        os.chmod(file, stat.S_IRUSR | stat.S_IWUSR)
232
237
 
 
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
 
233
268
def filter_mutate(function, list):
234
269
    """Like built-in filter, but mutates the given list instead of returning a
235
270
    new one. Returns None."""
256
291
# Mime types which will automatically be placed in the list by InstallList.
257
292
installlist_mimetypes = ['text/x-python', 'text/html',
258
293
    'application/x-javascript', 'application/javascript',
259
 
    'text/css', 'image/png', 'image/gif', 'application/xml', 'text/plain']
260
 
# Filenames which will automatically be placed in the list by InstallList.
261
 
whitelist_filenames = ['ivle-spec.conf']
 
294
    'text/css', 'image/png', 'image/gif', 'application/xml']
262
295
 
263
296
def build_list_py_files(dir, no_top_level=False):
264
297
    """Builds a list of all py files found in a directory and its
272
305
        filter_mutate(lambda x: x[0] != '.', dirnames)
273
306
        # All *.py files are added to the list
274
307
        pylist += [os.path.join(dirpath, item) for item in filenames
275
 
            if mimetypes.guess_type(item)[0] in installlist_mimetypes or
276
 
               item in whitelist_filenames]
 
308
            if mimetypes.guess_type(item)[0] in installlist_mimetypes]
277
309
    if no_top_level:
278
310
        for i in range(0, len(pylist)):
279
311
            _, pylist[i] = pylist[i].split(os.sep, 1)
280
312
    return pylist
281
313
 
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
 
 
293
314
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
 
294
318
    list_ivle_lib = property(lambda self: build_list_py_files('ivle'))
295
319
 
296
320
    list_subjects = property(lambda self: build_list_py_files('subjects',
303
327
        "services/python-console",
304
328
        "services/fileservice",
305
329
        "services/serveservice",
 
330
        "services/interpretservice",
306
331
        "services/usrmgt-server",
307
332
        "services/diffservice",
308
333
        "services/svnlogservice",
309
 
        "services/usrmgt-server", # XXX: Should be in bin/
310
334
    ]
311
335
 
312
336
    list_user_binaries = [
318
342
        "bin/ivle-mountallusers",
319
343
        "bin/ivle-remakeuser",
320
344
        "bin/ivle-showenrolment",
321
 
        "bin/ivle-config",
322
 
        "bin/ivle-createdatadirs",
323
 
        "bin/ivle-buildjail",
324
 
        "bin/ivle-addexercise",
325
 
        "bin/ivle-cloneworksheets",
326
345
    ]