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

« back to all changes in this revision

Viewing changes to setup/install.py

  • Committer: William Grant
  • Date: 2009-01-13 01:36:15 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1123
Merge setup-refactor branch. This completely breaks existing installations;
every path (both filesystem and Python) has changed. Do not upgrade without
knowing what you are doing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
# Author: Matt Giuca, Refactored by David Coles
20
20
# Date:   03/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
 
 
33
22
import optparse
34
23
import os
35
 
from setuputil import *
 
24
import sys
 
25
 
 
26
from setup import util
36
27
 
37
28
def install(args):
38
29
    usage = """usage: %prog install [options]
39
30
(Requires root)
40
31
Create target install directory ($target).
41
32
Create $target/bin.
42
 
Copy trampoline/trampoline to $target/bin.
43
 
Copy timount/timount to $target/bin.
 
33
Copy bin/trampoline/trampoline to $target/bin.
 
34
Copy bin/timount/timount to $target/bin.
44
35
chown and chmod the installed trampoline.
45
36
Copy www/ to $target.
46
37
Copy jail/ to jail_system directory (unless --nojail specified).
61
52
    (options, args) = parser.parse_args(args)
62
53
 
63
54
    # Call the real function
64
 
    __install(options.dry, options.nojail, options.nosubjects)
 
55
    return __install(options.dry, options.nojail, options.nosubjects)
65
56
 
66
57
def __install(dry=False,nojail=False,nosubjects=False):
67
 
    # Importing configuration is a little tricky
68
 
    sys.path.append('lib')
69
 
    import conf.conf
70
 
    import install_list
 
58
    # We need to import the one in the working copy, not in the system path.
 
59
    confmodule = __import__("ivle/conf/conf")
 
60
    install_list = util.InstallList()
71
61
 
72
62
    # Pull the required varibles out of the config
73
 
    ivle_install_dir = conf.conf.ivle_install_dir
74
 
    jail_base = conf.conf.jail_base
75
 
    jail_system = conf.conf.jail_system
76
 
    subjects_base = conf.conf.subjects_base
77
 
    exercises_base = conf.conf.exercises_base
 
63
    lib_path = confmodule.lib_path
 
64
    share_path = confmodule.share_path
 
65
    bin_path = confmodule.bin_path
 
66
    python_site_packages = confmodule.python_site_packages
 
67
    jail_base = confmodule.jail_base
 
68
    jail_system = confmodule.jail_system
 
69
    subjects_base = confmodule.subjects_base
 
70
    exercises_base = confmodule.exercises_base
78
71
 
79
72
    # Must be run as root or a dry run  
80
73
    if dry:
84
77
        print >>sys.stderr, "Must be root to run build"
85
78
        print >>sys.stderr, "(I need to chown)."
86
79
        return 1
87
 
    
88
 
    # Create the target (install) directory
89
 
    action_mkdir(ivle_install_dir, dry)
90
 
 
91
 
    # Create bin and copy the compiled files there
92
 
    action_mkdir(os.path.join(ivle_install_dir, 'bin'), dry)
93
 
    tramppath = os.path.join(ivle_install_dir, 'bin/trampoline')
94
 
    action_copyfile('trampoline/trampoline', tramppath, dry)
 
80
 
 
81
    # Make some directories for data.
 
82
    util.action_mkdir(confmodule.log_path, dry)
 
83
    util.action_mkdir(confmodule.data_path, dry)
 
84
    util.action_mkdir(confmodule.jail_base, dry)
 
85
    util.action_mkdir(confmodule.jail_src_base, dry)
 
86
    util.action_mkdir(confmodule.content_path, dry)
 
87
    util.action_mkdir(confmodule.notices_path, dry)
 
88
    util.action_mkdir(os.path.join(confmodule.data_path, 'sessions'), dry)
 
89
    util.action_mkdir(confmodule.svn_path, dry)
 
90
    util.action_mkdir(confmodule.svn_repo_path, dry)
 
91
    util.action_mkdir(os.path.join(confmodule.svn_repo_path, 'users'), dry)
 
92
    util.action_mkdir(os.path.join(confmodule.svn_repo_path, 'groups'), dry)
 
93
 
 
94
    util.action_chown(confmodule.log_path, util.wwwuid, util.wwwuid, dry)
 
95
    util.action_chown(os.path.join(confmodule.data_path, 'sessions'),
 
96
                      util.wwwuid, util.wwwuid, dry)
 
97
    util.action_chown(os.path.join(confmodule.svn_repo_path, 'users'),
 
98
                      util.wwwuid, util.wwwuid, dry)
 
99
    util.action_chown(os.path.join(confmodule.svn_repo_path, 'groups'),
 
100
                      util.wwwuid, util.wwwuid, dry)
 
101
 
 
102
    # Create lib and copy the compiled files there
 
103
    util.action_mkdir(lib_path, dry)
 
104
 
 
105
    tramppath = os.path.join(lib_path, 'trampoline')
 
106
    util.action_copyfile('bin/trampoline/trampoline', tramppath, dry)
95
107
    # chown trampoline to root and set setuid bit
96
 
    action_chown_setuid(tramppath, dry)
 
108
    util.action_chown_setuid(tramppath, dry)
97
109
 
98
 
    timountpath = os.path.join(ivle_install_dir, 'bin/timount')
99
 
    action_copyfile('timount/timount', timountpath, dry)
 
110
    timountpath = os.path.join(lib_path, 'timount')
 
111
    util.action_copyfile('bin/timount/timount', timountpath, dry)
100
112
 
101
113
    # Create a services directory to put the usrmgt-server in.
102
 
    action_mkdir(os.path.join(ivle_install_dir, 'services'), dry)
103
 
    usrmgtpath = os.path.join(ivle_install_dir, 'services/usrmgt-server')
104
 
    action_copyfile('services/usrmgt-server', usrmgtpath, dry)
105
 
    action_chmod_x(usrmgtpath, dry)
 
114
    util.action_mkdir(os.path.join(share_path, 'services'), dry)
 
115
 
 
116
    usrmgtpath = os.path.join(share_path, 'services/usrmgt-server')
 
117
    util.action_copyfile('services/usrmgt-server', usrmgtpath, dry)
 
118
    util.action_chmod_x(usrmgtpath, dry)
 
119
 
 
120
    # Copy the user-executable binaries using the list.
 
121
    util.action_copylist(install_list.list_user_binaries, bin_path, dry,
 
122
                         onlybasename=True)
106
123
 
107
124
    # Copy the www and lib directories using the list
108
 
    action_copylist(install_list.list_www, ivle_install_dir, dry)
109
 
    action_copylist(install_list.list_lib, ivle_install_dir, dry)
 
125
    util.action_copylist(install_list.list_www, share_path, dry)
 
126
    util.action_copylist(install_list.list_ivle_lib, python_site_packages, dry)
110
127
    
111
128
    # Make the config file private
112
 
    configpath = os.path.join(ivle_install_dir, 'lib/conf/conf.py')
113
 
    action_make_private(configpath, dry)
 
129
    # XXX Get rid of lib
 
130
    configpath = os.path.join(python_site_packages, 'ivle/conf/conf.py')
 
131
    util.action_make_private(configpath, dry)
114
132
 
115
133
    # Copy the php directory
116
134
    forum_dir = "www/php/phpBB3"
117
 
    forum_path = os.path.join(ivle_install_dir, forum_dir)
118
 
    action_copytree(forum_dir, forum_path, dry)
 
135
    forum_path = os.path.join(share_path, forum_dir)
 
136
    util.action_copytree(forum_dir, forum_path, dry)
119
137
    print "chown -R www-data:www-data %s" % forum_path
120
138
    if not dry:
121
139
        os.system("chown -R www-data:www-data %s" % forum_path)
124
142
        # Copy the local jail directory built by the build action
125
143
        # to the jail_system directory (it will be used to help build
126
144
        # all the students' jails).
127
 
        action_copytree('jail', jail_system, dry)
 
145
        util.action_copytree('jail', jail_system, dry)
 
146
 
128
147
    if not nosubjects:
129
148
        # Copy the subjects and exercises directories across
130
 
        action_copylist(install_list.list_subjects, subjects_base, dry,
 
149
        util.action_mkdir(subjects_base, dry)
 
150
        util.action_copylist(install_list.list_subjects, subjects_base, dry,
131
151
            srcdir="./subjects")
132
 
        action_copylist(install_list.list_exercises, exercises_base, dry,
 
152
        util.action_mkdir(exercises_base, dry)
 
153
        util.action_copylist(install_list.list_exercises, exercises_base, dry,
133
154
            srcdir="./exercises")
134
155
 
135
 
    # Append IVLE path to ivle.pth in python site packages
136
 
    # (Unless it's already there)
137
 
    ivle_pth = os.path.join(sys.prefix,
138
 
        "lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION)
139
 
    ivle_www = os.path.join(ivle_install_dir, "www")
140
 
    ivle_lib = os.path.join(ivle_install_dir, "lib")
141
 
    write_ivle_pth = True
142
 
    write_ivle_lib_pth = True
 
156
    # XXX We shouldn't have ivle.pth at all any more.
 
157
    # We may still need the www packages to be importable.
 
158
    # Anything from www that is needed from the outside should go to lib.
 
159
    ivle_pth = os.path.join(python_site_packages, "ivle.pth")
143
160
    try:
144
 
        file = open(ivle_pth, 'r')
145
 
        for line in file:
146
 
            if line.strip() == ivle_www:
147
 
                write_ivle_pth = False
148
 
            elif line.strip() == ivle_lib:
149
 
                write_ivle_lib_pth = False
 
161
        file = open(ivle_pth, 'w')
 
162
        file.write(os.path.join(share_path, "www"))
150
163
        file.close()
151
164
    except (IOError, OSError):
152
165
        pass
153
 
    if write_ivle_pth:
154
 
        action_append(ivle_pth, ivle_www)
155
 
    if write_ivle_lib_pth:
156
 
        action_append(ivle_pth, ivle_lib)
157
 
 
158
166
 
159
167
    # Create the ivle working revision record file
160
 
    action_mkdir(os.path.join(ivle_install_dir, 'version'), dry)
161
 
    ivle_revision_record_file = os.path.join(ivle_install_dir, 'version/ivle-revision.txt')
 
168
    ivle_revision_record_file = os.path.join(share_path, 'ivle-revision.txt')
162
169
    if not dry:
163
170
        try:
164
171
            conf = open(ivle_revision_record_file, "w")
165
172
 
166
 
            conf.write( "# IVLE code revision listing generated by running 'svn status -v ..' from " + os.getcwd() + "\n#\n\n")
 
173
            conf.write("""# SVN revision r%d
 
174
# Source tree location: %s
 
175
# Modified files:
 
176
""" % (util.get_svn_revision(), os.getcwd()))
167
177
 
168
178
            conf.close()
169
179
        except IOError, (errno, strerror):
170
180
            print "IO error(%s): %s" % (errno, strerror)
171
181
            sys.exit(1)
172
182
 
173
 
        os.system("svn status -v . >> %s" % ivle_revision_record_file)
 
183
        os.system("svn status . >> %s" % ivle_revision_record_file)
174
184
 
175
185
    print "Wrote IVLE code revision status to %s" % ivle_revision_record_file
176
186