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

« back to all changes in this revision

Viewing changes to setup/build.py

  • Committer: mattgiuca
  • Date: 2008-07-15 09:18:02 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:877
pulldown_subj/__init__.py: Added "enrol_user" function which pulls down a user
    and also enrols them in the database.
Added script enrolallusers.py which scriptulously performs automatic
enrolments of all users in the system, similar to remakeallusers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
# Author: Matt Giuca, Refactored by David Coles
20
20
# Date:   02/07/2008
21
21
 
 
22
# setup/build.py
 
23
# Compiles all files and sets up a jail template in the source directory.
 
24
# Details:
 
25
# Compiles (GCC) trampoline/trampoline.c to trampoline/trampoline.
 
26
# Creates jail/.
 
27
# Creates standard subdirs inside the jail, eg bin, opt, home, tmp.
 
28
# Copies console/ to a location within the jail.
 
29
# Copies OS programs and files to corresponding locations within the jail
 
30
#   (eg. python and Python libs, ld.so, etc).
 
31
# Generates .pyc files for all the IVLE .py files.
 
32
 
22
33
import optparse
23
34
import os
24
 
import sys
25
35
import compileall
26
 
 
27
 
from setup import util
 
36
from setuputil import *
28
37
 
29
38
def build(args):
30
39
    usage = """usage: %prog build [options]
32
41
Compiles all files and sets up a jail template in the source directory.
33
42
-O is recommended to cause compilation to be optimised.
34
43
Details:
35
 
Compiles (GCC) bin/trampoline/trampoline.c to bin/trampoline/trampoline.
36
 
Compiles (GCC) bin/timount/timount.c to bin/timount/timount.
 
44
Compiles (GCC) trampoline/trampoline.c to trampoline/trampoline.
 
45
Compiles (GCC) timount/timount.c to timount/timount.
37
46
Creates jail with system and student packages installed from MIRROR.
38
47
Copies console/ to a location within the jail.
39
48
Copies OS programs and files to corresponding locations within the jail
45
54
    parser.add_option("-n", "--dry",
46
55
        action="store_true", dest="dry",
47
56
        help="Print out the actions but don't do anything.")
48
 
    parser.add_option("-j", "--rebuildjail",
49
 
        action="store_true", dest="rebuildjail",
 
57
    parser.add_option("-J", "--norebuildjail",
 
58
        action="store_true", dest="norebuildjail",
50
59
        help="Don't recreate jail/ - just update its IVLE code.")
51
60
    parser.add_option("-m", "--mirror",
52
61
        action="store", dest="apt_mirror",
54
63
    (options, args) = parser.parse_args(args)
55
64
 
56
65
    # Call the real function
57
 
    return __build(options.dry, options.rebuildjail, options.apt_mirror)
 
66
    __build(options.dry, options.norebuildjail, options.apt_mirror)
58
67
 
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")
62
 
    install_list = util.InstallList()
 
68
def __build(dry=False,norebuildjail=False,apt_mirror=None):
 
69
    # Importing configuration is a little tricky
 
70
    sys.path.append(os.pardir)
 
71
    import install_list
63
72
 
64
73
    # Must be run as root or a dry run  
65
74
    if dry:
70
79
        print >>sys.stderr, "(I need to chroot)."
71
80
        return 1
72
81
    
73
 
    if not rebuildjail and not os.path.exists('jail'):
74
 
        print >> sys.stderr, "No jail exists -- please rerun with -j."
75
 
        return 1
 
82
    # Find out the revison number
 
83
    revnum = get_svn_revision()
 
84
    print "Building Revision %s"%str(revnum)
 
85
    if not dry:
 
86
        vfile = open('BUILD-VERSION','w')
 
87
        vfile.write(str(revnum) + '\n')
 
88
        vfile.close()
76
89
 
77
90
    # Compile the trampoline
78
91
    curdir = os.getcwd()
79
 
    os.chdir('bin/trampoline')
80
 
    util.action_runprog('make', [], dry)
 
92
    os.chdir('trampoline')
 
93
    action_runprog('make', [], dry)
81
94
    os.chdir(curdir)
82
95
 
83
96
    # Compile timount
84
97
    curdir = os.getcwd()
85
 
    os.chdir('bin/timount')
86
 
    util.action_runprog('make', [], dry)
 
98
    os.chdir('timount')
 
99
    action_runprog('make', [], dry)
87
100
    os.chdir(curdir)
88
101
 
89
 
    if rebuildjail:
 
102
    if not norebuildjail:
90
103
        # Create the jail and its subdirectories
91
104
        # Note: Other subdirs will be made by copying files
92
105
        if apt_mirror != None:
93
106
            os.environ['MIRROR'] = apt_mirror
94
 
        util.action_runprog('setup/buildjail.sh', [], dry)
 
107
        action_runprog('./buildjail.sh', [], dry)
95
108
 
96
109
    # 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
 
 
 
110
    action_copylist(install_list.list_scripts, 'jail/opt/ivle', dry)
 
111
    
101
112
    # 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
 
 
 
113
    action_chmod_x('jail/opt/ivle/scripts/python-console', dry)
 
114
    action_chmod_x('jail/opt/ivle/scripts/fileservice', dry)
 
115
    action_chmod_x('jail/opt/ivle/scripts/serveservice', dry)
 
116
    
106
117
    # 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
 
118
    # This is necessary for running certain scripts
 
119
    action_copylist(install_list.list_lib, 'jail/opt/ivle', dry)
 
120
    # IMPORTANT: The file jail/opt/ivle/lib/conf/conf.py contains details
112
121
    # which could compromise security if left in the jail (such as the DB
113
122
    # password).
114
123
    # The "safe" version is in jailconf.py. Delete conf.py and replace it with
115
124
    # jailconf.py.
116
 
    util.action_copyfile('ivle/conf/jailconf.py',
117
 
        os.path.join(jail_site_packages, 'ivle/conf/conf.py'), dry)
 
125
    action_copyfile('lib/conf/jailconf.py',
 
126
        'jail/opt/ivle/lib/conf/conf.py', dry)
118
127
 
119
128
    # Compile .py files into .pyc or .pyo files
120
129
    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)
 
130
    compileall.compile_dir('lib', quiet=True)
 
131
    compileall.compile_dir('scripts', quiet=True)
 
132
    compileall.compile_dir('jail/opt/ivle/lib', quiet=True)
 
133
 
 
134
    # Set up ivle.pth inside the jail
 
135
    # Need to set /opt/ivle/lib to be on the import path
 
136
    ivle_pth = \
 
137
        "jail/usr/lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION
 
138
    f = open(ivle_pth, 'w')
 
139
    f.write('/opt/ivle/lib\n')
 
140
    f.close()
124
141
 
125
142
    return 0
126
143