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

97 by mattgiuca
Moved template.py and setup.py to better places.
1
#!/usr/bin/env python
2
# IVLE - Informatics Virtual Learning Environment
3
# Copyright (C) 2007-2008 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
# Module: setup
20
# Author: Matt Giuca
21
# Date:   12/12/2007
22
23
# This is a command-line application, for use by the administrator.
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
24
# This program configures, builds and installs IVLE in three separate steps.
25
# It is called with at least one argument, which specifies which operation to
26
# take.
27
118 by mattgiuca
setup.py: Added copytree and copylist actions.
28
# setup.py listmake (for developer use only)
29
# Recurses through the source tree and builds a list of all files which should
30
# be copied upon installation. This should be run by the developer before
31
# cutting a distribution, and the listfile it generates should be included in
32
# the distribution, avoiding the administrator having to run it.
33
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
34
# setup.py conf [args]
35
# Configures IVLE with machine-specific details, most notably, various paths.
36
# Either prompts the administrator for these details or accepts them as
37
# command-line args.
38
# Creates www/conf/conf.py and trampoline/conf.h.
39
40
# setup.py build
41
# Compiles all files and sets up a jail template in the source directory.
42
# Details:
43
# Compiles (GCC) trampoline/trampoline.c to trampoline/trampoline.
44
# Creates jail/.
45
# Creates standard subdirs inside the jail, eg bin, opt, home, tmp.
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 files for all the IVLE .py files.
50
51
# setup.py install [--nojail] [--dry|n]
52
# (Requires root)
53
# Create target install directory ($target).
54
# Create $target/bin.
55
# Copy trampoline/trampoline to $target/bin.
56
# chown and chmod the installed trampoline.
57
# Copy www/ to $target.
58
# Copy jail/ to jails template directory (unless --nojail specified).
97 by mattgiuca
Moved template.py and setup.py to better places.
59
60
import os
119 by mattgiuca
setup.py: Added install action. Completely works!
61
import stat
118 by mattgiuca
setup.py: Added copytree and copylist actions.
62
import shutil
97 by mattgiuca
Moved template.py and setup.py to better places.
63
import sys
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
64
import getopt
107 by mattgiuca
setup.py: Added "action" functions which encapsulate calling OS functions.
65
import string
66
import errno
117 by mattgiuca
setup.py: listmake uses mimetypes to select all files with certain mime types,
67
import mimetypes
116 by mattgiuca
setup.py: mkdir now properly obeys "dry".
68
import compileall
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
69
import getopt
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
70
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
71
# Import modules from the website is tricky since they're in the www
72
# directory.
73
sys.path.append(os.path.join(os.getcwd(), 'www'))
74
import conf
75
import common.makeuser
76
251 by mattgiuca
setup.py: Worked the "files to copy into jail" out into a separate list
77
# Operating system files to copy over into the jail.
78
# These will be copied from the given place on the OS file system into the
79
# same place within the jail.
80
JAIL_FILES = [
81
    '/lib/ld-linux.so.2',
82
    '/lib/tls/i686/cmov/libc.so.6',
83
    '/lib/tls/i686/cmov/libdl.so.2',
84
    '/lib/tls/i686/cmov/libm.so.6',
85
    '/lib/tls/i686/cmov/libpthread.so.0',
86
    '/lib/tls/i686/cmov/libutil.so.1',
253 by mattgiuca
setup.py: chmods python-console when building.
87
    '/etc/ld.so.conf',
88
    '/etc/ld.so.cache',
89
    # These 2 files do not exist in Ubuntu
90
    #'/etc/ld.so.preload',
91
    #'/etc/ld.so.nohwcap',
92
    # UNIX commands
93
    '/usr/bin/strace',
94
    '/bin/ls',
95
    '/bin/echo',
96
    # Needed by python
251 by mattgiuca
setup.py: Worked the "files to copy into jail" out into a separate list
97
    '/usr/bin/python2.5',
253 by mattgiuca
setup.py: chmods python-console when building.
98
    # Needed by matplotlib
99
    '/usr/lib/i686/cmov/libssl.so.0.9.8',
100
    '/usr/lib/i686/cmov/libcrypto.so.0.9.8',
101
    '/lib/tls/i686/cmov/libnsl.so.1',
102
    '/usr/lib/libz.so.1',
103
    '/usr/lib/atlas/liblapack.so.3',
104
    '/usr/lib/atlas/libblas.so.3',
105
    '/usr/lib/libg2c.so.0',
106
    '/usr/lib/libstdc++.so.6',
107
    '/usr/lib/libfreetype.so.6',
108
    '/usr/lib/libpng12.so.0',
109
    '/usr/lib/libBLT.2.4.so.8.4',
110
    '/usr/lib/libtk8.4.so.0',
111
    '/usr/lib/libtcl8.4.so.0',
112
    '/usr/lib/tcl8.4/init.tcl',
113
    '/usr/lib/libX11.so.6',
114
    '/usr/lib/libXau.so.6',
115
    '/usr/lib/libXdmcp.so.6',
116
    '/lib/libgcc_s.so.1',
117
    '/etc/matplotlibrc',
251 by mattgiuca
setup.py: Worked the "files to copy into jail" out into a separate list
118
]
119
# Symlinks to make within the jail. Src mapped to dst.
120
JAIL_LINKS = {
121
    'python2.5': 'jail/usr/bin/python',
122
}
123
# Trees to copy. Src mapped to dst (these will be passed to action_copytree).
124
JAIL_COPYTREES = {
125
    '/usr/lib/python2.5': 'jail/usr/lib/python2.5',
253 by mattgiuca
setup.py: chmods python-console when building.
126
    '/usr/share/matplotlib': 'jail/usr/share/matplotlib',
127
    '/etc/ld.so.conf.d': 'jail/etc/ld.so.conf.d',
251 by mattgiuca
setup.py: Worked the "files to copy into jail" out into a separate list
128
}
129
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
130
# Try importing existing conf, but if we can't just set up defaults
131
# The reason for this is that these settings are used by other phases
132
# of setup besides conf, so we need to know them.
133
# Also this allows you to hit Return to accept the existing value.
134
try:
135
    confmodule = __import__("www/conf/conf")
195 by mattgiuca
Configuration: Moved "default_app" setting from conf/conf.py to conf/apps.py.
136
    try:
137
        root_dir = confmodule.root_dir
138
    except:
139
        root_dir = "/ivle"
140
    try:
141
        ivle_install_dir = confmodule.ivle_install_dir
142
    except:
143
        ivle_install_dir = "/opt/ivle"
144
    try:
259 by mattgiuca
setup.py: Added a new config variable "public_host", which lets the admin set
145
        public_host = confmodule.public_host
146
    except:
147
        public_host = "public.localhost"
148
    try:
195 by mattgiuca
Configuration: Moved "default_app" setting from conf/conf.py to conf/apps.py.
149
        jail_base = confmodule.jail_base
150
    except:
151
        jail_base = "/home/informatics/jails"
287 by mattgiuca
setup.py: Added new conf.py variable: subjects_base. This is for storing the
152
    try:
153
        subjects_base = confmodule.subjects_base
154
    except:
155
        subjects_base = "/home/informatics/subjects"
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
156
except ImportError:
157
    # Just set reasonable defaults
158
    root_dir = "/ivle"
159
    ivle_install_dir = "/opt/ivle"
259 by mattgiuca
setup.py: Added a new config variable "public_host", which lets the admin set
160
    public_host = "public.localhost"
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
161
    jail_base = "/home/informatics/jails"
287 by mattgiuca
setup.py: Added new conf.py variable: subjects_base. This is for storing the
162
    subjects_base = "/home/informatics/subjects"
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
163
# Always defaults
164
allowed_uids = "0"
165
118 by mattgiuca
setup.py: Added copytree and copylist actions.
166
# Try importing install_list, but don't fail if we can't, because listmake can
167
# function without it.
168
try:
169
    import install_list
170
except:
171
    pass
172
117 by mattgiuca
setup.py: listmake uses mimetypes to select all files with certain mime types,
173
# Mime types which will automatically be placed in the list by listmake.
174
# Note that listmake is not intended to be run by the final user (the system
175
# administrator who installs this), so the developers can customize the list
176
# as necessary, and include it in the distribution.
177
listmake_mimetypes = ['text/x-python', 'text/html',
178
    'application/x-javascript', 'application/javascript',
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
179
    'text/css', 'image/png', 'application/xml']
117 by mattgiuca
setup.py: listmake uses mimetypes to select all files with certain mime types,
180
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
181
# Main function skeleton from Guido van Rossum
182
# http://www.artima.com/weblogs/viewpost.jsp?thread=4829
183
184
def main(argv=None):
185
    if argv is None:
186
        argv = sys.argv
187
188
    # Print the opening spiel including the GPL notice
189
190
    print """IVLE - Informatics Virtual Learning Environment Setup
97 by mattgiuca
Moved template.py and setup.py to better places.
191
Copyright (C) 2007-2008 The University of Melbourne
192
IVLE comes with ABSOLUTELY NO WARRANTY.
193
This is free software, and you are welcome to redistribute it
194
under certain conditions. See LICENSE.txt for details.
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
195
196
IVLE Setup
197
"""
198
199
    # First argument is the name of the setup operation
200
    try:
201
        operation = argv[1]
202
    except IndexError:
203
        # Print usage message and exit
204
        help([])
205
        return 1
206
131 by mattgiuca
setup.py:
207
    # Disallow run as root unless installing
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
208
    if (operation != 'install' and operation != 'updatejails'
209
        and os.geteuid() == 0):
131 by mattgiuca
setup.py:
210
        print >>sys.stderr, "I do not want to run this stage as root."
211
        print >>sys.stderr, "Please run as a normal user."
212
        return 1
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
213
    # Call the requested operation's function
214
    try:
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
215
        oper_func = {
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
216
            'help' : help,
217
            'conf' : conf,
218
            'build' : build,
219
            'listmake' : listmake,
220
            'install' : install,
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
221
            'updatejails' : updatejails,
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
222
        }[operation]
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
223
    except KeyError:
224
        print >>sys.stderr, (
225
            """Invalid operation '%s'. Try python setup.py help."""
226
            % operation)
129 by mattgiuca
setup.py: Minor fix, exits cleanly if arguments are invalid.
227
        return 1
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
228
    return oper_func(argv[2:])
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
229
230
# Operation functions
231
232
def help(args):
233
    if args == []:
234
        print """Usage: python setup.py operation [args]
235
Operation (and args) can be:
236
    help [operation]
131 by mattgiuca
setup.py:
237
    listmake (developer use only)
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
238
    conf [args]
239
    build
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
240
    install [--nojail] [--nosubjects] [-n|--dry]
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
241
"""
242
        return 1
243
    elif len(args) != 1:
244
        print """Usage: python setup.py help [operation]"""
245
        return 2
246
    else:
247
        operation = args[0]
248
249
    if operation == 'help':
250
        print """python setup.py help [operation]
251
Prints the usage message or detailed help on an operation, then exits."""
118 by mattgiuca
setup.py: Added copytree and copylist actions.
252
    elif operation == 'listmake':
253
        print """python setup.py listmake
254
(For developer use only)
255
Recurses through the source tree and builds a list of all files which should
256
be copied upon installation. This should be run by the developer before
257
cutting a distribution, and the listfile it generates should be included in
258
the distribution, avoiding the administrator having to run it."""
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
259
    elif operation == 'conf':
260
        print """python setup.py conf [args]
261
Configures IVLE with machine-specific details, most notably, various paths.
262
Either prompts the administrator for these details or accepts them as
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
263
command-line args. Will be interactive only if there are no arguments given.
264
Takes defaults from existing conf file if it exists.
133 by mattgiuca
setup.py: Now allows IVLE to be installed over itself, in order to allow
265
266
To run IVLE out of the source directory (allowing development without having
267
to rebuild/install), just provide ivle_install_dir as the IVLE trunk
268
directory, and run build/install one time.
269
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
270
Creates www/conf/conf.py and trampoline/conf.h.
133 by mattgiuca
setup.py: Now allows IVLE to be installed over itself, in order to allow
271
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
272
Args are:
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
273
    --root_dir
274
    --ivle_install_dir
259 by mattgiuca
setup.py: Added a new config variable "public_host", which lets the admin set
275
    --public_host
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
276
    --jail_base
287 by mattgiuca
setup.py: Added new conf.py variable: subjects_base. This is for storing the
277
    --subjects_base
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
278
    --allowed_uids
279
As explained in the interactive prompt or conf.py.
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
280
"""
281
    elif operation == 'build':
118 by mattgiuca
setup.py: Added copytree and copylist actions.
282
        print """python -O setup.py build [--dry|-n]
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
283
Compiles all files and sets up a jail template in the source directory.
116 by mattgiuca
setup.py: mkdir now properly obeys "dry".
284
-O is recommended to cause compilation to be optimised.
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
285
Details:
286
Compiles (GCC) trampoline/trampoline.c to trampoline/trampoline.
287
Creates jail/.
288
Creates standard subdirs inside the jail, eg bin, opt, home, tmp.
289
Copies console/ to a location within the jail.
290
Copies OS programs and files to corresponding locations within the jail
291
  (eg. python and Python libs, ld.so, etc).
118 by mattgiuca
setup.py: Added copytree and copylist actions.
292
Generates .pyc or .pyo files for all the IVLE .py files.
293
294
--dry | -n  Print out the actions but don't do anything."""
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
295
    elif operation == 'install':
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
296
        print """sudo python setup.py install [--nojail] [--nosubjects][--dry|-n]
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
297
(Requires root)
298
Create target install directory ($target).
299
Create $target/bin.
300
Copy trampoline/trampoline to $target/bin.
301
chown and chmod the installed trampoline.
302
Copy www/ to $target.
303
Copy jail/ to jails template directory (unless --nojail specified).
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
304
Copy subjects/ to subjects directory (unless --nosubjects specified).
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
305
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
306
--nojail        Do not copy the jail.
307
--nosubjects    Do not copy the subjects.
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
308
--dry | -n  Print out the actions but don't do anything."""
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
309
    elif operation == 'updatejails':
310
        print """sudo python setup.py updatejails [--dry|-n]
311
(Requires root)
312
Copy jail/ to each subdirectory in jails directory.
313
314
--dry | -n  Print out the actions but don't do anything."""
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
315
    else:
316
        print >>sys.stderr, (
317
            """Invalid operation '%s'. Try python setup.py help."""
318
            % operation)
319
    return 1
320
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
321
def listmake(args):
322
    # We build two separate lists, by walking www and console
323
    list_www = build_list_py_files('www')
324
    list_console = build_list_py_files('console')
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
325
    list_subjects = build_list_py_files('subjects', no_top_level=True)
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
326
    # Make sure that the files generated by conf are in the list
327
    # (since listmake is typically run before conf)
328
    if "www/conf/conf.py" not in list_www:
329
        list_www.append("www/conf/conf.py")
117 by mattgiuca
setup.py: listmake uses mimetypes to select all files with certain mime types,
330
    # Make sure that console/python-console is in the list
331
    if "console/python-console" not in list_console:
332
        list_console.append("console/python-console")
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
333
    # Write these out to a file
334
    cwd = os.getcwd()
335
    # the files that will be created/overwritten
336
    listfile = os.path.join(cwd, "install_list.py")
337
338
    try:
339
        file = open(listfile, "w")
340
341
        file.write("""# IVLE Configuration File
342
# install_list.py
117 by mattgiuca
setup.py: listmake uses mimetypes to select all files with certain mime types,
343
# Provides lists of all files to be installed by `setup.py install' from
344
# certain directories.
116 by mattgiuca
setup.py: mkdir now properly obeys "dry".
345
# Note that any files with the given filename plus 'c' or 'o' (that is,
346
# compiled .pyc or .pyo files) will be copied as well.
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
347
117 by mattgiuca
setup.py: listmake uses mimetypes to select all files with certain mime types,
348
# List of all installable files in www directory.
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
349
list_www = """)
350
        writelist_pretty(file, list_www)
351
        file.write("""
117 by mattgiuca
setup.py: listmake uses mimetypes to select all files with certain mime types,
352
# List of all installable files in console directory.
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
353
list_console = """)
354
        writelist_pretty(file, list_console)
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
355
        file.write("""
356
# List of all installable files in subjects directory.
357
# This is to install sample subjects and material.
358
list_subjects = """)
359
        writelist_pretty(file, list_subjects)
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
360
361
        file.close()
362
    except IOError, (errno, strerror):
363
        print "IO error(%s): %s" % (errno, strerror)
364
        sys.exit(1)
365
366
    print "Successfully wrote install_list.py"
367
368
    print
369
    print ("You may modify the set of installable files before cutting the "
370
            "distribution:")
371
    print listfile
372
    print
373
374
    return 0
375
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
376
def build_list_py_files(dir, no_top_level=False):
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
377
    """Builds a list of all py files found in a directory and its
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
378
    subdirectories. Returns this as a list of strings.
379
    no_top_level=True means the file paths will not include the top-level
380
    directory.
381
    """
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
382
    pylist = []
383
    for (dirpath, dirnames, filenames) in os.walk(dir):
384
        # Exclude directories beginning with a '.' (such as '.svn')
385
        filter_mutate(lambda x: x[0] != '.', dirnames)
386
        # All *.py files are added to the list
387
        pylist += [os.path.join(dirpath, item) for item in filenames
117 by mattgiuca
setup.py: listmake uses mimetypes to select all files with certain mime types,
388
            if mimetypes.guess_type(item)[0] in listmake_mimetypes]
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
389
    if no_top_level:
390
        for i in range(0, len(pylist)):
391
            _, pylist[i] = pylist[i].split(os.sep, 1)
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
392
    return pylist
393
394
def writelist_pretty(file, list):
395
    """Writes a list one element per line, to a file."""
396
    if list == []:
397
        file.write("[]\n")
398
    else:
399
        file.write('[\n')
400
        for elem in list:
401
            file.write('    %s,\n' % repr(elem))
402
        file.write(']\n')
403
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
404
def conf(args):
287 by mattgiuca
setup.py: Added new conf.py variable: subjects_base. This is for storing the
405
    global root_dir, ivle_install_dir, jail_base, subjects_base
406
    global public_host, allowed_uids
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
407
    # Set up some variables
408
409
    cwd = os.getcwd()
410
    # the files that will be created/overwritten
411
    conffile = os.path.join(cwd, "www/conf/conf.py")
412
    conf_hfile = os.path.join(cwd, "trampoline/conf.h")
413
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
414
    # Get command-line arguments to avoid asking questions.
415
416
    (opts, args) = getopt.gnu_getopt(args, "", ['root_dir=',
417
                    'ivle_install_dir=', 'jail_base=', 'allowed_uids='])
418
419
    if args != []:
420
        print >>sys.stderr, "Invalid arguments:", string.join(args, ' ')
421
        return 2
422
423
    if opts == []:
424
        # Interactive mode. Prompt the user for all the values.
425
426
        print """This tool will create the following files:
100 by mattgiuca
setup.py: Added a new config variable, ivle_install_dir.
427
    %s
428
    %s
97 by mattgiuca
Moved template.py and setup.py to better places.
429
prompting you for details about your configuration. The file will be
430
overwritten if it already exists. It will *not* install or deploy IVLE.
431
432
Please hit Ctrl+C now if you do not wish to do this.
100 by mattgiuca
setup.py: Added a new config variable, ivle_install_dir.
433
""" % (conffile, conf_hfile)
97 by mattgiuca
Moved template.py and setup.py to better places.
434
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
435
        # Get information from the administrator
436
        # If EOF is encountered at any time during the questioning, just exit
437
        # silently
97 by mattgiuca
Moved template.py and setup.py to better places.
438
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
439
        root_dir = query_user(root_dir,
440
        """Root directory where IVLE is located (in URL space):""")
441
        ivle_install_dir = query_user(ivle_install_dir,
442
        'Root directory where IVLE will be installed (on the local file '
443
        'system):')
444
        jail_base = query_user(jail_base,
445
        """Root directory where the jails (containing user files) are stored
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
446
(on the local file system):""")
287 by mattgiuca
setup.py: Added new conf.py variable: subjects_base. This is for storing the
447
        subjects_base = query_user(subjects_base,
448
        """Root directory where the subject directories (containing worksheets
449
and other per-subject files) are stored (on the local file system):""")
259 by mattgiuca
setup.py: Added a new config variable "public_host", which lets the admin set
450
        public_host = query_user(public_host,
451
        """Hostname which will cause the server to go into "public mode",
452
providing login-free access to student's published work:""")
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
453
        allowed_uids = query_user(allowed_uids,
454
        """UID of the web server process which will run IVLE.
112 by mattgiuca
setup.py: A few comment changes.
455
Only this user may execute the trampoline. May specify multiple users as
456
a comma-separated list.
457
    (eg. "1002,78")""")
110 by mattgiuca
setup.py: Added to trampoline/conf.h an "allowed_uids" array. Asks the user
458
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
459
    else:
460
        opts = dict(opts)
461
        # Non-interactive mode. Parse the options.
462
        if '--root_dir' in opts:
463
            root_dir = opts['--root_dir']
464
        if '--ivle_install_dir' in opts:
465
            ivle_install_dir = opts['--ivle_install_dir']
466
        if '--jail_base' in opts:
467
            jail_base = opts['--jail_base']
287 by mattgiuca
setup.py: Added new conf.py variable: subjects_base. This is for storing the
468
        if '--subjects_base' in opts:
469
            jail_base = opts['--subjects_base']
259 by mattgiuca
setup.py: Added a new config variable "public_host", which lets the admin set
470
        if '--public_host' in opts:
471
            public_host = opts['--public_host']
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
472
        if '--allowed_uids' in opts:
473
            allowed_uids = opts['--allowed_uids']
474
110 by mattgiuca
setup.py: Added to trampoline/conf.h an "allowed_uids" array. Asks the user
475
    # Error handling on input values
476
    try:
112 by mattgiuca
setup.py: A few comment changes.
477
        allowed_uids = map(int, allowed_uids.split(','))
110 by mattgiuca
setup.py: Added to trampoline/conf.h an "allowed_uids" array. Asks the user
478
    except ValueError:
112 by mattgiuca
setup.py: A few comment changes.
479
        print >>sys.stderr, (
480
        "Invalid UID list (%s).\n"
481
        "Must be a comma-separated list of integers." % allowed_uids)
110 by mattgiuca
setup.py: Added to trampoline/conf.h an "allowed_uids" array. Asks the user
482
        return 1
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
483
484
    # Write www/conf/conf.py
485
486
    try:
487
        conf = open(conffile, "w")
488
489
        conf.write("""# IVLE Configuration File
97 by mattgiuca
Moved template.py and setup.py to better places.
490
# conf.py
491
# Miscellaneous application settings
492
493
494
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
495
# with this).
496
# eg. "/" or "/ivle".
100 by mattgiuca
setup.py: Added a new config variable, ivle_install_dir.
497
root_dir = "%s"
498
499
# In the local file system, where IVLE is actually installed.
500
# This directory should contain the "www" and "bin" directories.
501
ivle_install_dir = "%s"
97 by mattgiuca
Moved template.py and setup.py to better places.
502
259 by mattgiuca
setup.py: Added a new config variable "public_host", which lets the admin set
503
# The server goes into "public mode" if the browser sends a request with this
504
# host. This is for security reasons - we only serve public student files on a
505
# separate domain to the main IVLE site.
506
# Public mode does not use cookies, and serves only public content.
507
# Private mode (normal mode) requires login, and only serves files relevant to
508
# the logged-in user.
509
public_host = "%s"
510
97 by mattgiuca
Moved template.py and setup.py to better places.
511
# In the local file system, where are the student/user file spaces located.
512
# The user jails are expected to be located immediately in subdirectories of
513
# this location.
106 by mattgiuca
Renamed "student_dir" to "jail_base" across the suite.
514
jail_base = "%s"
287 by mattgiuca
setup.py: Added new conf.py variable: subjects_base. This is for storing the
515
516
# In the local file system, where are the per-subject file spaces located.
517
# The individual subject directories are expected to be located immediately
518
# in subdirectories of this location.
519
subjects_base = "%s"
520
""" % (root_dir, ivle_install_dir, public_host, jail_base, subjects_base))
110 by mattgiuca
setup.py: Added to trampoline/conf.h an "allowed_uids" array. Asks the user
521
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
522
        conf.close()
523
    except IOError, (errno, strerror):
524
        print "IO error(%s): %s" % (errno, strerror)
525
        sys.exit(1)
526
527
    print "Successfully wrote www/conf/conf.py"
528
529
    # Write trampoline/conf.h
530
531
    try:
532
        conf = open(conf_hfile, "w")
533
534
        conf.write("""/* IVLE Configuration File
100 by mattgiuca
setup.py: Added a new config variable, ivle_install_dir.
535
 * conf.h
536
 * Administrator settings required by trampoline.
537
 * Note: trampoline will have to be rebuilt in order for changes to this file
538
 * to take effect.
539
 */
540
541
/* In the local file system, where are the jails located.
542
 * The trampoline does not allow the creation of a jail anywhere besides
543
 * jail_base or a subdirectory of jail_base.
544
 */
545
static const char* jail_base = "%s";
110 by mattgiuca
setup.py: Added to trampoline/conf.h an "allowed_uids" array. Asks the user
546
547
/* Which user IDs are allowed to run the trampoline.
548
 * This list should be limited to the web server user.
549
 * (Note that root is an implicit member of this list).
550
 */
112 by mattgiuca
setup.py: A few comment changes.
551
static const int allowed_uids[] = { %s };
552
""" % (jail_base, repr(allowed_uids)[1:-1]))
100 by mattgiuca
setup.py: Added a new config variable, ivle_install_dir.
553
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
554
        conf.close()
555
    except IOError, (errno, strerror):
556
        print "IO error(%s): %s" % (errno, strerror)
557
        sys.exit(1)
558
559
    print "Successfully wrote trampoline/conf.h"
560
561
    print
562
    print "You may modify the configuration at any time by editing"
563
    print conffile
564
    print conf_hfile
565
    print
566
    return 0
567
568
def build(args):
121 by mattgiuca
setup: build and install now read command line options
569
    # Get "dry" variable from command line
570
    (opts, args) = getopt.gnu_getopt(args, "n", ['dry'])
571
    opts = dict(opts)
572
    dry = '-n' in opts or '--dry' in opts
573
574
    if dry:
575
        print "Dry run (no actions will be executed\n"
107 by mattgiuca
setup.py: Added "action" functions which encapsulate calling OS functions.
576
577
    # Compile the trampoline
578
    action_runprog('gcc', ['-Wall', '-o', 'trampoline/trampoline',
579
        'trampoline/trampoline.c'], dry)
580
581
    # Create the jail and its subdirectories
122 by mattgiuca
setup.py: build action now copies all operating system files into the jail.
582
    # Note: Other subdirs will be made by copying files
116 by mattgiuca
setup.py: mkdir now properly obeys "dry".
583
    action_mkdir('jail', dry)
584
    action_mkdir('jail/home', dry)
585
    action_mkdir('jail/tmp', dry)
107 by mattgiuca
setup.py: Added "action" functions which encapsulate calling OS functions.
586
122 by mattgiuca
setup.py: build action now copies all operating system files into the jail.
587
    # Copy all console and operating system files into the jail
118 by mattgiuca
setup.py: Added copytree and copylist actions.
588
    action_copylist(install_list.list_console, 'jail/opt/ivle', dry)
122 by mattgiuca
setup.py: build action now copies all operating system files into the jail.
589
    copy_os_files_jail(dry)
253 by mattgiuca
setup.py: chmods python-console when building.
590
    # Chmod the python console
591
    action_chmod_x('jail/opt/ivle/console/python-console', dry)
592
    
118 by mattgiuca
setup.py: Added copytree and copylist actions.
593
116 by mattgiuca
setup.py: mkdir now properly obeys "dry".
594
    # Compile .py files into .pyc or .pyo files
595
    compileall.compile_dir('www', quiet=True)
596
    compileall.compile_dir('console', quiet=True)
107 by mattgiuca
setup.py: Added "action" functions which encapsulate calling OS functions.
597
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
598
    return 0
599
122 by mattgiuca
setup.py: build action now copies all operating system files into the jail.
600
def copy_os_files_jail(dry):
601
    """Copies necessary Operating System files from their usual locations
602
    into the jail/ directory of the cwd."""
603
    # Currently source paths are configured for Ubuntu.
251 by mattgiuca
setup.py: Worked the "files to copy into jail" out into a separate list
604
    for filename in JAIL_FILES:
605
        copy_file_to_jail(filename, dry)
606
    for src, dst in JAIL_LINKS.items():
607
        action_symlink(src, dst, dry)
608
    for src, dst in JAIL_COPYTREES.items():
609
        action_copytree(src, dst, dry)
122 by mattgiuca
setup.py: build action now copies all operating system files into the jail.
610
611
def copy_file_to_jail(src, dry):
612
    """Copies a single file from an absolute location into the same location
613
    within the jail. src must begin with a '/'. The jail will be located
614
    in a 'jail' subdirectory of the current path."""
615
    action_copyfile(src, 'jail' + src, dry)
616
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
617
def install(args):
121 by mattgiuca
setup: build and install now read command line options
618
    # Get "dry" and "nojail" variables from command line
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
619
    (opts, args) = getopt.gnu_getopt(args, "n",
620
        ['dry', 'nojail', 'nosubjects'])
121 by mattgiuca
setup: build and install now read command line options
621
    opts = dict(opts)
622
    dry = '-n' in opts or '--dry' in opts
623
    nojail = '--nojail' in opts
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
624
    nosubjects = '--nosubjects' in opts
121 by mattgiuca
setup: build and install now read command line options
625
626
    if dry:
627
        print "Dry run (no actions will be executed\n"
119 by mattgiuca
setup.py: Added install action. Completely works!
628
629
    if not dry and os.geteuid() != 0:
630
        print >>sys.stderr, "Must be root to run install"
631
        print >>sys.stderr, "(I need to chown some files)."
632
        return 1
633
634
    # Create the target (install) directory
635
    action_mkdir(ivle_install_dir, dry)
636
637
    # Create bin and copy the compiled files there
638
    action_mkdir(os.path.join(ivle_install_dir, 'bin'), dry)
639
    tramppath = os.path.join(ivle_install_dir, 'bin/trampoline')
640
    action_copyfile('trampoline/trampoline', tramppath, dry)
641
    # chown trampoline to root and set setuid bit
642
    action_chown_setuid(tramppath, dry)
643
644
    # Copy the www directory using the list
645
    action_copylist(install_list.list_www, ivle_install_dir, dry)
646
647
    if not nojail:
648
        # Copy the local jail directory built by the build action
649
        # to the jails template directory (it will be used as a template
650
        # for all the students' jails).
651
        action_copytree('jail', os.path.join(jail_base, 'template'), dry)
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
652
    if not nosubjects:
653
        # Copy the subjects directory across
654
        action_copylist(install_list.list_subjects, subjects_base, dry,
655
            srcdir="./subjects")
119 by mattgiuca
setup.py: Added install action. Completely works!
656
256 by mattgiuca
Changed the way IVLE's path is loaded into Python's sys.path. Now a file
657
    # Append IVLE path to ivle.pth in python site packages
658
    # (Unless it's already there)
659
    ivle_pth = os.path.join(sys.prefix,
660
        "lib/python2.5/site-packages/ivle.pth")
661
    ivle_www = os.path.join(ivle_install_dir, "www")
662
    write_ivle_pth = True
663
    try:
664
        file = open(ivle_pth, 'r')
665
        for line in file:
666
            if line.strip() == ivle_www:
667
                write_ivle_pth = False
668
                break
669
    except (IOError, OSError):
670
        pass
671
    if write_ivle_pth:
672
        action_append(ivle_pth, ivle_www)
673
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
674
    return 0
675
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
676
def updatejails(args):
677
    # Get "dry" variable from command line
678
    (opts, args) = getopt.gnu_getopt(args, "n", ['dry'])
679
    opts = dict(opts)
680
    dry = '-n' in opts or '--dry' in opts
681
682
    if dry:
683
        print "Dry run (no actions will be executed\n"
684
685
    if not dry and os.geteuid() != 0:
686
        print >>sys.stderr, "Must be root to run install"
687
        print >>sys.stderr, "(I need to chown some files)."
688
        return 1
689
690
    # Update the template jail directory in case it hasn't been installed
691
    # recently.
692
    action_copytree('jail', os.path.join(jail_base, 'template'), dry)
693
694
    # Re-link all the files in all students jails.
695
    for dir in os.listdir(jail_base):
696
        if dir == 'template': continue
697
        # First back up the student's home directory
698
        temp_home = os.tmpnam()
699
        action_rename(os.path.join(jail_base, dir, 'home'), temp_home, dry)
700
        # Delete the student's jail and relink the jail files
701
        action_linktree(os.path.join(jail_base, 'template'),
702
            os.path.join(jail_base, dir), dry)
703
        # Restore the student's home directory
704
        action_rename(temp_home, os.path.join(jail_base, dir, 'home'), dry)
705
        # Set up the user's home directory just in case they don't have a
706
        # directory for this yet
707
        action_mkdir(os.path.join(jail_base, dir, 'home', dir), dry)
708
709
    return 0
710
107 by mattgiuca
setup.py: Added "action" functions which encapsulate calling OS functions.
711
# The actions call Python os functions but print actions and handle dryness.
712
# May still throw os exceptions if errors occur.
713
108 by mattgiuca
setup.py: Added RunError class. action_runprog now throws a RunError if the
714
class RunError:
715
    """Represents an error when running a program (nonzero return)."""
716
    def __init__(self, prog, retcode):
717
        self.prog = prog
718
        self.retcode = retcode
719
    def __str__(self):
720
        return str(self.prog) + " returned " + repr(self.retcode)
721
107 by mattgiuca
setup.py: Added "action" functions which encapsulate calling OS functions.
722
def action_runprog(prog, args, dry):
723
    """Runs a unix program. Searches in $PATH. Synchronous (waits for the
724
    program to return). Runs in the current environment. First prints the
725
    action as a "bash" line.
726
108 by mattgiuca
setup.py: Added RunError class. action_runprog now throws a RunError if the
727
    Throws a RunError with a retcode of the return value of the program,
728
    if the program did not return 0.
729
107 by mattgiuca
setup.py: Added "action" functions which encapsulate calling OS functions.
730
    prog: String. Name of the program. (No path required, if in $PATH).
731
    args: [String]. Arguments to the program.
732
    dry: Bool. If True, prints but does not execute.
733
    """
734
    print prog, string.join(args, ' ')
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
735
    if dry: return
736
    ret = os.spawnvp(os.P_WAIT, prog, args)
737
    if ret != 0:
738
        raise RunError(prog, ret)
107 by mattgiuca
setup.py: Added "action" functions which encapsulate calling OS functions.
739
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
740
def action_rename(src, dst, dry):
741
    """Calls rename. Deletes the target if it already exists."""
742
    if os.access(dst, os.F_OK):
743
        print "rm -r", dst
744
        if not dry:
745
            shutil.rmtree(dst, True)
746
    print "mv ", src, dst
747
    if dry: return
748
    try:
749
        os.rename(src, dst)
750
    except OSError, (err, msg):
751
        if err != errno.EEXIST:
752
            raise
753
116 by mattgiuca
setup.py: mkdir now properly obeys "dry".
754
def action_mkdir(path, dry):
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
755
    """Calls mkdir. Silently ignored if the directory already exists.
756
    Creates all parent directories as necessary."""
757
    print "mkdir -p", path
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
758
    if dry: return
107 by mattgiuca
setup.py: Added "action" functions which encapsulate calling OS functions.
759
    try:
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
760
        os.makedirs(path)
107 by mattgiuca
setup.py: Added "action" functions which encapsulate calling OS functions.
761
    except OSError, (err, msg):
762
        if err != errno.EEXIST:
763
            raise
764
118 by mattgiuca
setup.py: Added copytree and copylist actions.
765
def action_copytree(src, dst, dry):
766
    """Copies an entire directory tree. Symlinks are seen as normal files and
767
    copies of the entire file (not the link) are made. Creates all parent
768
    directories as necessary.
769
770
    See shutil.copytree."""
771
    if os.access(dst, os.F_OK):
772
        print "rm -r", dst
773
        if not dry:
774
            shutil.rmtree(dst, True)
775
    print "cp -r", src, dst
776
    if dry: return
132 by mattgiuca
setup.py: File copying is more robust - preserves symlinks and permissions
777
    shutil.copytree(src, dst, True)
118 by mattgiuca
setup.py: Added copytree and copylist actions.
778
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
779
def action_linktree(src, dst, dry):
780
    """Hard-links an entire directory tree. Same as copytree but the created
781
    files are hard-links not actual copies. Removes the existing destination.
782
    """
783
    if os.access(dst, os.F_OK):
784
        print "rm -r", dst
785
        if not dry:
786
            shutil.rmtree(dst, True)
787
    print "<cp with hardlinks> -r", src, dst
788
    if dry: return
789
    common.makeuser.linktree(src, dst)
790
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
791
def action_copylist(srclist, dst, dry, srcdir="."):
118 by mattgiuca
setup.py: Added copytree and copylist actions.
792
    """Copies all files in a list to a new location. The files in the list
793
    are read relative to the current directory, and their destinations are the
794
    same paths relative to dst. Creates all parent directories as necessary.
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
795
    srcdir is "." by default, can be overridden.
118 by mattgiuca
setup.py: Added copytree and copylist actions.
796
    """
797
    for srcfile in srclist:
798
        dstfile = os.path.join(dst, srcfile)
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
799
        srcfile = os.path.join(srcdir, srcfile)
118 by mattgiuca
setup.py: Added copytree and copylist actions.
800
        dstdir = os.path.split(dstfile)[0]
801
        if not os.path.isdir(dstdir):
802
            action_mkdir(dstdir, dry)
803
        print "cp -f", srcfile, dstfile
804
        if not dry:
133 by mattgiuca
setup.py: Now allows IVLE to be installed over itself, in order to allow
805
            try:
806
                shutil.copyfile(srcfile, dstfile)
807
                shutil.copymode(srcfile, dstfile)
808
            except shutil.Error:
809
                pass
118 by mattgiuca
setup.py: Added copytree and copylist actions.
810
119 by mattgiuca
setup.py: Added install action. Completely works!
811
def action_copyfile(src, dst, dry):
812
    """Copies one file to a new location. Creates all parent directories
813
    as necessary.
814
    """
815
    dstdir = os.path.split(dst)[0]
816
    if not os.path.isdir(dstdir):
817
        action_mkdir(dstdir, dry)
818
    print "cp -f", src, dst
819
    if not dry:
133 by mattgiuca
setup.py: Now allows IVLE to be installed over itself, in order to allow
820
        try:
821
            shutil.copyfile(src, dst)
822
            shutil.copymode(src, dst)
823
        except shutil.Error:
824
            pass
119 by mattgiuca
setup.py: Added install action. Completely works!
825
122 by mattgiuca
setup.py: build action now copies all operating system files into the jail.
826
def action_symlink(src, dst, dry):
827
    """Creates a symlink in a given location. Creates all parent directories
828
    as necessary.
829
    """
830
    dstdir = os.path.split(dst)[0]
831
    if not os.path.isdir(dstdir):
832
        action_mkdir(dstdir, dry)
131 by mattgiuca
setup.py:
833
    # Delete existing file
834
    if os.path.exists(dst):
835
        os.remove(dst)
836
    print "ln -fs", src, dst
122 by mattgiuca
setup.py: build action now copies all operating system files into the jail.
837
    if not dry:
838
        os.symlink(src, dst)
839
256 by mattgiuca
Changed the way IVLE's path is loaded into Python's sys.path. Now a file
840
def action_append(ivle_pth, ivle_www):
841
    file = open(ivle_pth, 'a+')
842
    file.write(ivle_www + '\n')
843
    file.close()
844
119 by mattgiuca
setup.py: Added install action. Completely works!
845
def action_chown_setuid(file, dry):
846
    """Chowns a file to root, and sets the setuid bit on the file.
847
    Calling this function requires the euid to be root.
848
    The actual mode of path is set to: rws--s--s
849
    """
850
    print "chown root:root", file
851
    if not dry:
852
        os.chown(file, 0, 0)
853
    print "chmod a+xs", file
854
    print "chmod u+rw", file
855
    if not dry:
856
        os.chmod(file, stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
857
            | stat.S_ISUID | stat.S_IRUSR | stat.S_IWUSR)
858
253 by mattgiuca
setup.py: chmods python-console when building.
859
def action_chmod_x(file, dry):
860
    """Chmod +xs a file (sets execute permission)."""
861
    print "chmod u+rwx", file
862
    if not dry:
863
        os.chmod(file, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR)
864
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
865
def query_user(default, prompt):
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
866
    """Prompts the user for a string, which is read from a line of stdin.
867
    Exits silently if EOF is encountered. Returns the string, with spaces
868
    removed from the beginning and end.
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
869
870
    Returns default if a 0-length line (after spaces removed) was read.
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
871
    """
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
872
    sys.stdout.write('%s\n    (default: "%s")\n>' % (prompt, default))
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
873
    try:
874
        val = sys.stdin.readline()
875
    except KeyboardInterrupt:
876
        # Ctrl+C
877
        sys.stdout.write("\n")
878
        sys.exit(1)
879
    sys.stdout.write("\n")
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
880
    # If EOF, exit
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
881
    if val == '': sys.exit(1)
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
882
    # If empty line, return default
883
    val = val.strip()
884
    if val == '': return default
885
    return val
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
886
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
887
def filter_mutate(function, list):
888
    """Like built-in filter, but mutates the given list instead of returning a
889
    new one. Returns None."""
890
    i = len(list)-1
891
    while i >= 0:
892
        # Delete elements which do not match
893
        if not function(list[i]):
894
            del list[i]
895
        i -= 1
896
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
897
if __name__ == "__main__":
898
    sys.exit(main())