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

« back to all changes in this revision

Viewing changes to bin/ivle-buildjail

  • Committer: mattgiuca
  • Date: 2008-08-18 12:15:25 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1027
Tutorial: Added new feature - previous attempt viewing. Allows users to see
    code they have previously submitted to tutorials.
    A new button ("View previous attempts") appears on each exercise box.
    This uses the getattempts and getattempt Ajax services checked in
    previously.
Note once again: Students are not (for the moment) able to see deactivated
attempts (this is a conservative approach - the ability to see deactivated
attempts can be turned on by setting HISTORY_ALLOW_INACTIVE = True in
tutorialservice).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
# IVLE - Informatics Virtual Learning Environment
3
 
# Copyright (C) 2009 The University of Melbourne
4
 
#
5
 
# This program is free software; you can redistribute it and/or modify
6
 
# it under the terms of the GNU General Public License as published by
7
 
# the Free Software Foundation; either version 2 of the License, or
8
 
# (at your option) any later version.
9
 
#
10
 
# This program is distributed in the hope that it will be useful,
11
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
# GNU General Public License for more details.
14
 
#
15
 
# You should have received a copy of the GNU General Public License
16
 
# along with this program; if not, write to the Free Software
17
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 
19
 
import optparse
20
 
import os
21
 
import sys
22
 
import shutil
23
 
 
24
 
import ivle.conf
25
 
import ivle.config
26
 
import ivle.jailbuilder.debian
27
 
 
28
 
usage = """usage: %prog [options]
29
 
(requires root)
30
 
Builds or updates the base IVLE jail."""
31
 
 
32
 
conf = ivle.config.Config()
33
 
build_path = ivle.conf.jail_system_build
34
 
 
35
 
# Parse arguments
36
 
parser = optparse.OptionParser(usage)
37
 
parser.add_option("-r", "--recreate",
38
 
    action="store_true", dest="recreate",
39
 
    help='''Completely recreate the jail - don't just update its IVLE code.
40
 
Be warned, this may download hundreds of megabytes!''')
41
 
parser.add_option("-u", "--upgrade",
42
 
    action="store_true", dest="upgrade",
43
 
    help='''Apply any package updates in the jail.''')
44
 
parser.add_option("-m", "--mirror",
45
 
    action="store", dest="apt_mirror",
46
 
    help="Sets the apt mirror used when recreating the jail.")
47
 
(options, args) = parser.parse_args(sys.argv)
48
 
 
49
 
if os.geteuid() != 0:
50
 
    print >> sys.stderr, "Must be root to run buildjail."
51
 
    sys.exit(1)
52
 
 
53
 
if not options.recreate and not os.path.exists(build_path):
54
 
    print >> sys.stderr, "No jail exists -- please rerun with -r."
55
 
    sys.exit(1)
56
 
 
57
 
if options.recreate:
58
 
    # Create the jail and its subdirectories
59
 
    # Note: Other subdirs will be made by copying files
60
 
    if options.apt_mirror is not None:
61
 
        os.environ['MIRROR'] = options.apt_mirror
62
 
 
63
 
    os.system('rm -rf --one-file-system ' + build_path)
64
 
    ivle.jailbuilder.debian.debootstrap_create_jail(conf['jail']['suite'],
65
 
              build_path, mirror=options.apt_mirror)
66
 
 
67
 
    # Add any extra site apt sources.
68
 
    if conf['jail']['extra_sources']:
69
 
        ivle.jailbuilder.debian.mangle_sources_list(build_path,
70
 
                  conf['jail']['extra_sources'])
71
 
 
72
 
    # Add any extra site apt keys.
73
 
    if conf['jail']['extra_keys']:
74
 
        ivle.jailbuilder.debian.apt_add_key(build_path,
75
 
                                            conf['jail']['extra_keys'])
76
 
 
77
 
    ivle.jailbuilder.debian.apt_update_cache(build_path)
78
 
    ivle.jailbuilder.debian.apt_install(build_path,
79
 
                        ['python2.5', 'python-cjson', 'python-svn'])
80
 
 
81
 
    # Install any extra site packages.
82
 
    if conf['jail']['extra_packages']:
83
 
        ivle.jailbuilder.debian.apt_install(build_path,
84
 
                  conf['jail']['extra_packages'])
85
 
 
86
 
    ivle.jailbuilder.debian.apt_clean(build_path)
87
 
 
88
 
if options.upgrade:
89
 
    # Run apt-get update, apt-get upgrade and apt-get clean.
90
 
    ivle.jailbuilder.debian.apt_update_cache(build_path)
91
 
    ivle.jailbuilder.debian.apt_upgrade(build_path)
92
 
    ivle.jailbuilder.debian.apt_clean(build_path)
93
 
 
94
 
# Copy all console and operating system files into the jail
95
 
services_path = os.path.join(ivle.conf.share_path, 'services')
96
 
jail_services_path = os.path.join(build_path, services_path[1:])
97
 
if os.path.exists(jail_services_path):
98
 
    shutil.rmtree(jail_services_path)
99
 
shutil.copytree(services_path, jail_services_path)
100
 
 
101
 
# Also copy the IVLE lib directory into the jail
102
 
# This is necessary for running certain services
103
 
ivle_site_packages = os.path.join(ivle.conf.python_site_packages, 'ivle')
104
 
jail_site_packages = os.path.join(build_path, ivle_site_packages[1:])
105
 
if os.path.exists(jail_site_packages):
106
 
    shutil.rmtree(jail_site_packages)
107
 
shutil.copytree(ivle_site_packages, jail_site_packages)
108
 
 
109
 
# IMPORTANT: ivle/conf/conf.py contains details which could compromise security
110
 
# if left in the jail (such as the DB password). We delete it now! It would be
111
 
# shadowed by the per-user conf.py anyway, but it's best to be safe.
112
 
os.unlink(os.path.join(jail_site_packages, 'conf/conf.py'))
113
 
# XXX: Shouldn't copy the compiled files at all, but compile them in the jail!
114
 
os.unlink(os.path.join(jail_site_packages, 'conf/conf.pyc'))
115
 
 
116
 
if os.spawnvp(os.P_WAIT, 'rsync', ['rsync', '-a', '--delete',
117
 
              build_path + '/', ivle.conf.jail_system]) != 0:
118
 
    print >> sys.stderr, "Jail copying failed."
119
 
    sys.exit(1)
120