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

« back to all changes in this revision

Viewing changes to setup/build.py

  • Committer: stevenbird
  • Date: 2008-02-19 21:17:21 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:512
Renaming of problems to exercises (initial commit).
Fix up module naming (exercises sometimes called tutorials).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
45
 
Creates jail with system and student packages installed from MIRROR.
46
 
Copies console/ to a location within the jail.
47
 
Copies OS programs and files to corresponding locations within the jail
48
 
  (eg. python and Python libs, ld.so, etc).
49
 
Generates .pyc or .pyo files for all the IVLE .py files."""
50
 
 
51
 
    # Parse arguments
52
 
    parser = optparse.OptionParser(usage)
53
 
    parser.add_option("-n", "--dry",
54
 
        action="store_true", dest="dry",
55
 
        help="Print out the actions but don't do anything.")
56
 
    parser.add_option("-m", "--mirror",
57
 
        action="store", dest="apt_mirror",
58
 
        help="Sets the APT mirror used to build the jail.")
59
 
    (options, args) = parser.parse_args(args)
60
 
 
61
 
    # Call the real function
62
 
    __build(options.dry, options.apt_mirror)
63
 
 
64
 
def __build(dry=False,apt_mirror=None):
65
 
    # Importing configuration is a little tricky
66
 
    sys.path.append(os.pardir)
67
 
    import install_list
68
 
 
69
 
    # Must be run as root or a dry run  
70
 
    if dry:
71
 
        print "Dry run (no actions will be executed)\n"
72
 
    
73
 
    if not dry and os.geteuid() != 0:
74
 
        print >>sys.stderr, "Must be root to run build"
75
 
        print >>sys.stderr, "(I need to chroot)."
76
 
        return 1
77
 
    
78
 
    # Find out the revison number
79
 
    revnum = get_svn_revision()
80
 
    print "Building Revision %s"%str(revnum)
81
 
    if not dry:
82
 
        vfile = open('BUILD-VERSION','w')
83
 
        vfile.write(str(revnum) + '\n')
84
 
        vfile.close()
85
 
 
86
 
    # Compile the trampoline
87
 
    curdir = os.getcwd()
88
 
    os.chdir('trampoline')
89
 
    action_runprog('make', [], dry)
90
 
    os.chdir(curdir)
91
 
 
92
 
    # Create the jail and its subdirectories
93
 
    # Note: Other subdirs will be made by copying files
94
 
    if apt_mirror != None:
95
 
        os.environ['MIRROR'] = apt_mirror
96
 
    action_runprog('./buildjail.sh', [], dry)
97
 
 
98
 
    # Copy all console and operating system files into the jail
99
 
    action_copylist(install_list.list_scripts, 'jail/opt/ivle', dry)
100
 
    
101
 
    # Chmod the python console
102
 
    action_chmod_x('jail/opt/ivle/scripts/python-console', dry)
103
 
    action_chmod_x('jail/opt/ivle/scripts/fileservice', dry)
104
 
    action_chmod_x('jail/opt/ivle/scripts/serveservice', dry)
105
 
    
106
 
    # Also copy the IVLE lib directory into the jail
107
 
    # This is necessary for running certain scripts
108
 
    action_copylist(install_list.list_lib, 'jail/opt/ivle', dry)
109
 
    # IMPORTANT: The file jail/opt/ivle/lib/conf/conf.py contains details
110
 
    # which could compromise security if left in the jail (such as the DB
111
 
    # password).
112
 
    # The "safe" version is in jailconf.py. Delete conf.py and replace it with
113
 
    # jailconf.py.
114
 
    action_copyfile('lib/conf/jailconf.py',
115
 
        'jail/opt/ivle/lib/conf/conf.py', dry)
116
 
 
117
 
    # Compile .py files into .pyc or .pyo files
118
 
    compileall.compile_dir('www', quiet=True)
119
 
    compileall.compile_dir('lib', quiet=True)
120
 
    compileall.compile_dir('scripts', quiet=True)
121
 
    compileall.compile_dir('jail/opt/ivle/lib', quiet=True)
122
 
 
123
 
    # Set up ivle.pth inside the jail
124
 
    # Need to set /opt/ivle/lib to be on the import path
125
 
    ivle_pth = \
126
 
        "jail/usr/lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION
127
 
    f = open(ivle_pth, 'w')
128
 
    f.write('/opt/ivle/lib\n')
129
 
    f.close()
130
 
 
131
 
    return 0
132