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

« back to all changes in this revision

Viewing changes to setup/util.py

Merge setup-stuff.

phpBB is gone, configuration, setup and jail building are completely redone.

Please read doc/setup/install_proc.txt, or you'll not get far.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
           'action_symlink', 'action_append', 'action_chown',
38
38
           'action_chown_setuid', 'action_chmod_x', 'action_make_private',
39
39
           'query_user', 'filter_mutate', 'get_svn_revision', 'InstallList',
40
 
           'wwwuid']
 
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.
235
235
    if not dry:
236
236
        os.chmod(file, stat.S_IRUSR | stat.S_IWUSR)
237
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
 
 
268
238
def filter_mutate(function, list):
269
239
    """Like built-in filter, but mutates the given list instead of returning a
270
240
    new one. Returns None."""
292
262
installlist_mimetypes = ['text/x-python', 'text/html',
293
263
    'application/x-javascript', 'application/javascript',
294
264
    'text/css', 'image/png', 'image/gif', 'application/xml']
 
265
# Filenames which will automatically be placed in the list by InstallList.
 
266
whitelist_filenames = ['ivle-spec.conf']
295
267
 
296
268
def build_list_py_files(dir, no_top_level=False):
297
269
    """Builds a list of all py files found in a directory and its
305
277
        filter_mutate(lambda x: x[0] != '.', dirnames)
306
278
        # All *.py files are added to the list
307
279
        pylist += [os.path.join(dirpath, item) for item in filenames
308
 
            if mimetypes.guess_type(item)[0] in installlist_mimetypes]
 
280
            if mimetypes.guess_type(item)[0] in installlist_mimetypes or
 
281
               item in whitelist_filenames]
309
282
    if no_top_level:
310
283
        for i in range(0, len(pylist)):
311
284
            _, pylist[i] = pylist[i].split(os.sep, 1)
312
285
    return pylist
313
286
 
 
287
def make_install_path(rootdir, path):
 
288
    '''Combine an installation root directory and final install path.
 
289
 
 
290
    Normalises path, and joins it to the end of rootdir, removing the leading
 
291
    / to make it relative if required.
 
292
    '''
 
293
    normpath = os.path.normpath(path)
 
294
    if normpath.startswith(os.sep):
 
295
        normpath = normpath[1:]
 
296
    return os.path.join(rootdir, normpath)
 
297
 
314
298
class InstallList(object):
315
299
    # We build two separate lists, by walking www and console
316
300
    list_www = property(lambda self: build_list_py_files('www'))
330
314
        "services/usrmgt-server",
331
315
        "services/diffservice",
332
316
        "services/svnlogservice",
 
317
        "services/usrmgt-server", # XXX: Should be in bin/
333
318
    ]
334
319
 
335
320
    list_user_binaries = [
341
326
        "bin/ivle-mountallusers",
342
327
        "bin/ivle-remakeuser",
343
328
        "bin/ivle-showenrolment",
 
329
        "bin/ivle-config",
 
330
        "bin/ivle-createdatadirs",
 
331
        "bin/ivle-buildjail",
344
332
    ]