803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
1 |
# IVLE - Informatics Virtual Learning Environment
|
2 |
# Copyright (C) 2007-2008 The University of Melbourne
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17 |
||
18 |
# Module: setup/build
|
|
19 |
# Author: Matt Giuca, Refactored by David Coles
|
|
20 |
# Date: 02/07/2008
|
|
21 |
||
22 |
import optparse |
|
23 |
import os |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
24 |
import sys |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
25 |
import compileall |
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
26 |
|
27 |
from setup import util |
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
28 |
|
29 |
def build(args): |
|
30 |
usage = """usage: %prog build [options] |
|
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.
|
|
34 |
Details:
|
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
35 |
Compiles (GCC) bin/trampoline/trampoline.c to bin/trampoline/trampoline.
|
36 |
Compiles (GCC) bin/timount/timount.c to bin/timount/timount.
|
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
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."""
|
|
42 |
||
43 |
# Parse arguments
|
|
44 |
parser = optparse.OptionParser(usage) |
|
45 |
parser.add_option("-n", "--dry", |
|
46 |
action="store_true", dest="dry", |
|
47 |
help="Print out the actions but don't do anything.") |
|
894
by wagrant
setup: Don't rebuild the jail by default. Pass -j to force a rebuild, |
48 |
parser.add_option("-j", "--rebuildjail", |
49 |
action="store_true", dest="rebuildjail", |
|
814
by William Grant
setup: Add --norebuildjail option to build, to not re-debootstrap. |
50 |
help="Don't recreate jail/ - just update its IVLE code.") |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
51 |
parser.add_option("-m", "--mirror", |
52 |
action="store", dest="apt_mirror", |
|
53 |
help="Sets the APT mirror used to build the jail.") |
|
54 |
(options, args) = parser.parse_args(args) |
|
55 |
||
56 |
# Call the real function
|
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
57 |
return __build(options.dry, options.rebuildjail, options.apt_mirror) |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
58 |
|
894
by wagrant
setup: Don't rebuild the jail by default. Pass -j to force a rebuild, |
59 |
def __build(dry=False,rebuildjail=False,apt_mirror=None): |
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
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() |
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
63 |
|
64 |
# Must be run as root or a dry run
|
|
65 |
if dry: |
|
66 |
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 |
||
1050
by wagrant
setup: Don't give possible options in the top-level usage string. |
73 |
if not rebuildjail and not os.path.exists('jail'): |
74 |
print >> sys.stderr, "No jail exists -- please rerun with -j." |
|
75 |
return 1 |
|
76 |
||
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
77 |
# Compile the trampoline
|
78 |
curdir = os.getcwd() |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
79 |
os.chdir('bin/trampoline') |
80 |
util.action_runprog('make', [], dry) |
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
81 |
os.chdir(curdir) |
82 |
||
813
by William Grant
Merge jails-redux branch. We now use aufs rather than hardlinking tens |
83 |
# Compile timount
|
84 |
curdir = os.getcwd() |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
85 |
os.chdir('bin/timount') |
86 |
util.action_runprog('make', [], dry) |
|
813
by William Grant
Merge jails-redux branch. We now use aufs rather than hardlinking tens |
87 |
os.chdir(curdir) |
88 |
||
894
by wagrant
setup: Don't rebuild the jail by default. Pass -j to force a rebuild, |
89 |
if rebuildjail: |
814
by William Grant
setup: Add --norebuildjail option to build, to not re-debootstrap. |
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 |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
94 |
util.action_runprog('setup/buildjail.sh', [], dry) |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
95 |
|
96 |
# Copy all console and operating system files into the jail
|
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
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 |
||
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
101 |
# Chmod the python console
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
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 |
||
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
106 |
# Also copy the IVLE lib directory into the jail
|
1072
by matt.giuca
Renamed scripts to services. |
107 |
# This is necessary for running certain services
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
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
|
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
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.
|
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
116 |
util.action_copyfile('ivle/conf/jailconf.py', |
117 |
os.path.join(jail_site_packages, 'ivle/conf/conf.py'), dry) |
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
118 |
|
119 |
# Compile .py files into .pyc or .pyo files
|
|
120 |
compileall.compile_dir('www', quiet=True) |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
121 |
compileall.compile_dir('ivle', quiet=True) |
1072
by matt.giuca
Renamed scripts to services. |
122 |
compileall.compile_dir('services', quiet=True) |
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
123 |
compileall.compile_dir(os.path.join(jail_site_packages, 'ivle'),quiet=True) |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
124 |
|
125 |
return 0 |
|
126 |