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

« back to all changes in this revision

Viewing changes to setup/util.py

[Uber-commit of holiday work because I lacked a local copy of the branch.]

 ivle.makeuser: Don't use jailconf.py as a header for the in-jail conf.py;
     generate the whole thing using string formatting operators and include
     the template inline.

 ivle.makeuser.make_conf_py: XXX the inclusion of ivle.conf.jail_base in
     the jail. It is simply there to placate ivle.studpath, and needs
     to go before we can entirely remove the in-jail config.

 ivle-buildjail:
   - Add. Converted from setup.buildjail.
   - Build the jail in __base_build__ and rsync it to __base__ when
     done, rather than operating only in ./jail
   - Rename --rebuildjail/-j to --recreate/-r, as the whole script
     is now for jail rebuilding. Also add a warning to the usage string about
     the large volume likely to be downloaded.
   - Check existence before removing trees.
   - Don't copy jailconf.py over conf.py in the jail. Also make
     sure that we remove conf.pyc.

 setup.configure:
   - Stop generating jailconf.py at all.
   - Add a jail_system_build setting, defaulting to __base_build__ next to
     the existing __base__.
   - Don't use an OptionParser before calling the real function, as that
     adds options dynamically.

 setup.install:
   - Add an option (-R) to avoid writing out svn revision info to
     $PREFIX/share/ivle/revision.txt.
   - Remove jail-copying things.
   - Install all services to the host, rather than just usrmgt-server. We do
     this so we can build the jail from the host without the source tree.
   - Shuffle some things, and don't install phpBB3 twice.
   - Add a --root argument, to take an alternate root directory to install
     into (as given to autotools in $DESTDIR).

 setup.build:
   - Allow running as non-root.
   - Take a --no-compile option to not byte-compile Python files.

 setup.util:
   - Include usrmgt-server in the list of services.
   - Add make_install_path(), a wrapper around os.path.join() that ensures
     the second path is relative.
   - Install ivle-buildjail with the other binaries.

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',
 
39
           'query_user', 'filter_mutate', 'get_svn_revision', 'InstallList',
40
40
           'make_install_path', 'wwwuid']
41
41
 
42
42
# Determine which Python version (2.4 or 2.5, for example) we are running,
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)
291
323
    return os.path.join(rootdir, normpath)
292
324
 
293
325
class InstallList(object):
 
326
    # We build two separate lists, by walking www and console
 
327
    list_www = property(lambda self: build_list_py_files('www'))
 
328
 
294
329
    list_ivle_lib = property(lambda self: build_list_py_files('ivle'))
295
330
 
296
331
    list_subjects = property(lambda self: build_list_py_files('subjects',
303
338
        "services/python-console",
304
339
        "services/fileservice",
305
340
        "services/serveservice",
 
341
        "services/interpretservice",
306
342
        "services/usrmgt-server",
307
343
        "services/diffservice",
308
344
        "services/svnlogservice",
310
346
    ]
311
347
 
312
348
    list_user_binaries = [
313
 
        "bin/ivle-addexercise",
314
 
        "bin/ivle-adduser",
315
 
        "bin/ivle-buildjail",
316
 
        "bin/ivle-cloneworksheets",
317
 
        "bin/ivle-config",
318
 
        "bin/ivle-createdatadirs",
319
349
        "bin/ivle-enrol",
320
350
        "bin/ivle-enrolallusers",
321
 
        "bin/ivle-fetchsubmissions",
322
351
        "bin/ivle-listusers",
323
 
        "bin/ivle-loadsampledata",
 
352
        "bin/ivle-makeuser",
324
353
        "bin/ivle-marks",
325
354
        "bin/ivle-mountallusers",
326
 
        "bin/ivle-refreshfilesystem",
327
355
        "bin/ivle-remakeuser",
328
356
        "bin/ivle-showenrolment",
 
357
        "bin/ivle-buildjail",
329
358
    ]