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

« back to all changes in this revision

Viewing changes to setup/util.py

  • Committer: Matt Giuca
  • Date: 2009-05-26 04:15:23 UTC
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: matt.giuca@gmail.com-20090526041523-hsg5q2enlhvjb5y2
doc/man/architecture.rst: User management server.

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."""
291
256
# Mime types which will automatically be placed in the list by InstallList.
292
257
installlist_mimetypes = ['text/x-python', 'text/html',
293
258
    'application/x-javascript', 'application/javascript',
294
 
    'text/css', 'image/png', 'image/gif', 'application/xml']
 
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']
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',
330
306
        "services/usrmgt-server",
331
307
        "services/diffservice",
332
308
        "services/svnlogservice",
 
309
        "services/usrmgt-server", # XXX: Should be in bin/
333
310
    ]
334
311
 
335
312
    list_user_binaries = [
336
313
        "bin/ivle-enrol",
337
314
        "bin/ivle-enrolallusers",
 
315
        "bin/ivle-fetchsubmissions",
338
316
        "bin/ivle-listusers",
339
317
        "bin/ivle-makeuser",
340
318
        "bin/ivle-marks",
341
319
        "bin/ivle-mountallusers",
342
320
        "bin/ivle-remakeuser",
343
321
        "bin/ivle-showenrolment",
 
322
        "bin/ivle-config",
 
323
        "bin/ivle-createdatadirs",
 
324
        "bin/ivle-buildjail",
 
325
        "bin/ivle-addexercise",
 
326
        "bin/ivle-cloneworksheets",
 
327
        "bin/ivle-refreshfilesystem",
344
328
    ]