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

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
# 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
33
import optparse
34
import os
35
import compileall
36
from setuputil import *
37
38
def build(args):
39
    usage = """usage: %prog build [options]
40
(requires root)
41
Compiles all files and sets up a jail template in the source directory.
42
-O is recommended to cause compilation to be optimised.
43
Details:
44
Compiles (GCC) trampoline/trampoline.c to trampoline/trampoline.
813 by William Grant
Merge jails-redux branch. We now use aufs rather than hardlinking tens
45
Compiles (GCC) timount/timount.c to timount/timount.
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
46
Creates jail with system and student packages installed from MIRROR.
47
Copies console/ to a location within the jail.
48
Copies OS programs and files to corresponding locations within the jail
49
  (eg. python and Python libs, ld.so, etc).
50
Generates .pyc or .pyo files for all the IVLE .py files."""
51
52
    # Parse arguments
53
    parser = optparse.OptionParser(usage)
54
    parser.add_option("-n", "--dry",
55
        action="store_true", dest="dry",
56
        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,
57
    parser.add_option("-j", "--rebuildjail",
58
        action="store_true", dest="rebuildjail",
814 by William Grant
setup: Add --norebuildjail option to build, to not re-debootstrap.
59
        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
60
    parser.add_option("-m", "--mirror",
61
        action="store", dest="apt_mirror",
62
        help="Sets the APT mirror used to build the jail.")
63
    (options, args) = parser.parse_args(args)
64
65
    # Call the real function
894 by wagrant
setup: Don't rebuild the jail by default. Pass -j to force a rebuild,
66
    __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
67
894 by wagrant
setup: Don't rebuild the jail by default. Pass -j to force a rebuild,
68
def __build(dry=False,rebuildjail=False,apt_mirror=None):
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
69
    # Importing configuration is a little tricky
70
    sys.path.append(os.pardir)
71
    import install_list
72
73
    # Must be run as root or a dry run  
74
    if dry:
75
        print "Dry run (no actions will be executed)\n"
76
    
77
    if not dry and os.geteuid() != 0:
78
        print >>sys.stderr, "Must be root to run build"
79
        print >>sys.stderr, "(I need to chroot)."
80
        return 1
81
    
1050 by wagrant
setup: Don't give possible options in the top-level usage string.
82
    if not rebuildjail and not os.path.exists('jail'):
83
        print >> sys.stderr, "No jail exists -- please rerun with -j."
84
        return 1
85
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
86
    # Find out the revison number
87
    revnum = get_svn_revision()
88
    print "Building Revision %s"%str(revnum)
89
    if not dry:
90
        vfile = open('BUILD-VERSION','w')
91
        vfile.write(str(revnum) + '\n')
92
        vfile.close()
93
94
    # Compile the trampoline
95
    curdir = os.getcwd()
96
    os.chdir('trampoline')
97
    action_runprog('make', [], dry)
98
    os.chdir(curdir)
99
813 by William Grant
Merge jails-redux branch. We now use aufs rather than hardlinking tens
100
    # Compile timount
101
    curdir = os.getcwd()
102
    os.chdir('timount')
103
    action_runprog('make', [], dry)
104
    os.chdir(curdir)
105
894 by wagrant
setup: Don't rebuild the jail by default. Pass -j to force a rebuild,
106
    if rebuildjail:
814 by William Grant
setup: Add --norebuildjail option to build, to not re-debootstrap.
107
        # Create the jail and its subdirectories
108
        # Note: Other subdirs will be made by copying files
109
        if apt_mirror != None:
110
            os.environ['MIRROR'] = apt_mirror
1071 by matt.giuca
Moved all script files into newly created 'bin' directory (cleanup).
111
        action_runprog('./bin/buildjail.sh', [], dry)
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
112
113
    # Copy all console and operating system files into the jail
1072 by matt.giuca
Renamed scripts to services.
114
    action_copylist(install_list.list_services, 'jail/opt/ivle', dry)
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
115
    
116
    # Chmod the python console
1072 by matt.giuca
Renamed scripts to services.
117
    action_chmod_x('jail/opt/ivle/services/python-console', dry)
118
    action_chmod_x('jail/opt/ivle/services/fileservice', dry)
119
    action_chmod_x('jail/opt/ivle/services/serveservice', dry)
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
120
    
121
    # Also copy the IVLE lib directory into the jail
1072 by matt.giuca
Renamed scripts to services.
122
    # This is necessary for running certain services
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
123
    action_copylist(install_list.list_lib, 'jail/opt/ivle', dry)
124
    # IMPORTANT: The file jail/opt/ivle/lib/conf/conf.py contains details
125
    # which could compromise security if left in the jail (such as the DB
126
    # password).
127
    # The "safe" version is in jailconf.py. Delete conf.py and replace it with
128
    # jailconf.py.
129
    action_copyfile('lib/conf/jailconf.py',
130
        'jail/opt/ivle/lib/conf/conf.py', dry)
131
132
    # Compile .py files into .pyc or .pyo files
133
    compileall.compile_dir('www', quiet=True)
134
    compileall.compile_dir('lib', quiet=True)
1072 by matt.giuca
Renamed scripts to services.
135
    compileall.compile_dir('services', quiet=True)
803 by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should
136
    compileall.compile_dir('jail/opt/ivle/lib', quiet=True)
137
138
    # Set up ivle.pth inside the jail
139
    # Need to set /opt/ivle/lib to be on the import path
140
    ivle_pth = \
141
        "jail/usr/lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION
142
    f = open(ivle_pth, 'w')
143
    f.write('/opt/ivle/lib\n')
144
    f.close()
145
146
    return 0
147