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

« back to all changes in this revision

Viewing changes to setup/build.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:
29
29
def build(args):
30
30
    usage = """usage: %prog build [options]
31
31
(requires root)
32
 
Compiles all files and sets up a jail template in the source directory.
33
 
-O is recommended to cause compilation to be optimised.
 
32
Compiles platform-specific code, and optionally Python too.
34
33
Details:
35
34
Compiles (GCC) bin/trampoline/trampoline.c to bin/trampoline/trampoline.
36
35
Compiles (GCC) bin/timount/timount.c to bin/timount/timount.
37
 
Creates jail with system and student packages installed from MIRROR.
38
 
Copies console/ to a location within the jail.
39
 
Copies OS programs and files to corresponding locations within the jail
40
 
  (eg. python and Python libs, ld.so, etc).
41
 
Generates .pyc or .pyo files for all the IVLE .py files."""
 
36
Optionally generates .pyc files for all the IVLE .py files."""
42
37
 
43
38
    # Parse arguments
44
39
    parser = optparse.OptionParser(usage)
45
40
    parser.add_option("-n", "--dry",
46
41
        action="store_true", dest="dry",
47
42
        help="Print out the actions but don't do anything.")
48
 
    parser.add_option("-j", "--rebuildjail",
49
 
        action="store_true", dest="rebuildjail",
50
 
        help="Don't recreate jail/ - just update its IVLE code.")
51
 
    parser.add_option("-m", "--mirror",
52
 
        action="store", dest="apt_mirror",
53
 
        help="Sets the APT mirror used to build the jail.")
 
43
    parser.add_option("--no-compile",
 
44
        action="store_true", dest="nocompile",
 
45
        help="Don't byte-compile .py files.")
 
46
    parser.add_option("-t", "--trampoline-uids",
 
47
        action="store", dest="tuids", default="33",
 
48
        help="Comma-separated list of UIDs allowed to use trampoline. "
 
49
             "(default: 33)")
54
50
    (options, args) = parser.parse_args(args)
55
51
 
56
52
    # Call the real function
57
 
    return __build(options.dry, options.rebuildjail, options.apt_mirror)
 
53
    return __build(options.dry, options.nocompile, options.tuids)
58
54
 
59
 
def __build(dry=False,rebuildjail=False,apt_mirror=None):
60
 
    # We need to import the one in the working copy, not in the system path.
61
 
    confmodule = __import__("ivle/conf/conf")
 
55
def __build(dry=False, no_compile=None, tuids=None):
62
56
    install_list = util.InstallList()
63
57
 
64
 
    # Must be run as root or a dry run  
65
58
    if dry:
66
59
        print "Dry run (no actions will be executed)\n"
67
 
    
68
 
    if not dry and os.geteuid() != 0:
69
 
        print >>sys.stderr, "Must be root to run build"
70
 
        print >>sys.stderr, "(I need to chroot)."
71
 
        return 1
72
 
    
73
 
    if not rebuildjail and not os.path.exists('jail'):
74
 
        print >> sys.stderr, "No jail exists -- please rerun with -j."
75
 
        return 1
 
60
 
 
61
    # Create trampoline configuration.
 
62
    conf_hfile = os.path.join(os.getcwd(), "bin/trampoline/conf.h")
 
63
    conf_h = open(conf_hfile, "w")
 
64
 
 
65
    conf_h.write("""/* IVLE Configuration File
 
66
 * conf.h
 
67
 * Administrator settings required by trampoline.
 
68
 * Note: trampoline will have to be rebuilt in order for changes to this file
 
69
 * to take effect.
 
70
 */
 
71
 
 
72
#define IVLE_AUFS_JAILS
 
73
 
 
74
/* Which user IDs are allowed to run the trampoline.
 
75
 * This list should be limited to the web server user.
 
76
 * (Note that root is an implicit member of this list).
 
77
 */
 
78
static const int allowed_uids[] = { %s };
 
79
""" % tuids)
 
80
    conf_h.close()
76
81
 
77
82
    # Compile the trampoline
78
83
    curdir = os.getcwd()
86
91
    util.action_runprog('make', [], dry)
87
92
    os.chdir(curdir)
88
93
 
89
 
    if rebuildjail:
90
 
        # Create the jail and its subdirectories
91
 
        # Note: Other subdirs will be made by copying files
92
 
        if apt_mirror != None:
93
 
            os.environ['MIRROR'] = apt_mirror
94
 
        util.action_runprog('setup/buildjail.sh', [], dry)
95
 
 
96
 
    # Copy all console and operating system files into the jail
97
 
    jail_share = os.path.join('jail', confmodule.share_path[1:])
98
 
    jail_services = os.path.join(jail_share, 'services')
99
 
    util.action_copylist(install_list.list_services, jail_share, dry)
100
 
 
101
 
    # Chmod the python console
102
 
    util.action_chmod_x(os.path.join(jail_services, 'python-console'), dry)
103
 
    util.action_chmod_x(os.path.join(jail_services, 'fileservice'), dry)
104
 
    util.action_chmod_x(os.path.join(jail_services, 'serveservice'), dry)
105
 
 
106
 
    # Also copy the IVLE lib directory into the jail
107
 
    # This is necessary for running certain services
108
 
    jail_site_packages = os.path.join('jail',
109
 
                                      confmodule.python_site_packages[1:])
110
 
    util.action_copylist(install_list.list_ivle_lib, jail_site_packages, dry)
111
 
    # IMPORTANT: ivle/conf/conf.py contains details
112
 
    # which could compromise security if left in the jail (such as the DB
113
 
    # password).
114
 
    # The "safe" version is in jailconf.py. Delete conf.py and replace it with
115
 
    # jailconf.py.
116
 
    util.action_copyfile('ivle/conf/jailconf.py',
117
 
        os.path.join(jail_site_packages, 'ivle/conf/conf.py'), dry)
118
 
 
119
94
    # Compile .py files into .pyc or .pyo files
120
 
    compileall.compile_dir('www', quiet=True)
121
 
    compileall.compile_dir('ivle', quiet=True)
122
 
    compileall.compile_dir('services', quiet=True)
123
 
    compileall.compile_dir(os.path.join(jail_site_packages, 'ivle'),quiet=True)
 
95
    if not no_compile:
 
96
        compileall.compile_dir('ivle', quiet=True)
 
97
        compileall.compile_dir('services', quiet=True)
124
98
 
125
99
    return 0
126
100