~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
316 by drtomc
setup.py - name the configuration command "config" to bring it into line with
34
# setup.py config [args]
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
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.
409 by mattgiuca
Moved www/conf and www/common to a new directory lib. This separates the "web"
38
# Creates lib/conf/conf.py and trampoline/conf.h.
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
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.
755 by dcoles
Added support for an incremental rebuild of all the users jails.
58
# Copy jail/ to jails __staging__ 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
671 by dcoles
forum: Now uses a unique secret generated at './setup config' time for shared secret
70
import hashlib
71
import uuid
746 by dcoles
Setup: During Build the system will now indicate what revision is being built
72
import pysvn
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
73
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
74
# Import modules from the website is tricky since they're in the www
75
# directory.
409 by mattgiuca
Moved www/conf and www/common to a new directory lib. This separates the "web"
76
sys.path.append(os.path.join(os.getcwd(), 'lib'))
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
77
import conf
78
import common.makeuser
79
317 by mattgiuca
doc/dependencies: Added dependency on matplotlib.
80
# Determine which Python version (2.4 or 2.5, for example) we are running,
81
# and use that as the filename to the Python directory.
82
# Just get the first 3 characters of sys.version.
83
PYTHON_VERSION = sys.version[0:3]
84
358 by mattgiuca
setup.py: Gutted out the config options code. It was getting so there were
85
class ConfigOption:
86
    """A configuration option; one of the things written to conf.py."""
87
    def __init__(self, option_name, default, prompt, comment):
88
        """Creates a configuration option.
89
        option_name: Name of the variable in conf.py. Also name of the
90
            command-line argument to setup.py conf.
91
        default: Default value for this variable.
92
        prompt: (Short) string presented during the interactive prompt in
93
            setup.py conf.
94
        comment: (Long) comment string stored in conf.py. Each line of this
95
            string should begin with a '#'.
96
        """
97
        self.option_name = option_name
98
        self.default = default
99
        self.prompt = prompt
100
        self.comment = comment
101
102
# Configuration options, defaults and descriptions
103
config_options = []
485 by mattgiuca
setup.py: Changed the defaut root_dir from "/ivle" to "/".
104
config_options.append(ConfigOption("root_dir", "/",
358 by mattgiuca
setup.py: Gutted out the config options code. It was getting so there were
105
    """Root directory where IVLE is located (in URL space):""",
106
    """
107
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
108
# with this).
109
# eg. "/" or "/ivle"."""))
110
config_options.append(ConfigOption("ivle_install_dir", "/opt/ivle",
111
    'Root directory where IVLE will be installed (on the local file '
112
    'system):',
113
    """
114
# In the local file system, where IVLE is actually installed.
115
# This directory should contain the "www" and "bin" directories."""))
116
config_options.append(ConfigOption("jail_base", "/home/informatics/jails",
530 by mattgiuca
setup.py:
117
    """Location of Directories
118
=======================
119
Root directory where the jails (containing user files) are stored
358 by mattgiuca
setup.py: Gutted out the config options code. It was getting so there were
120
(on the local file system):""",
121
    """
122
# In the local file system, where are the student/user file spaces located.
123
# The user jails are expected to be located immediately in subdirectories of
124
# this location."""))
125
config_options.append(ConfigOption("subjects_base",
126
    "/home/informatics/subjects",
127
    """Root directory where the subject directories (containing worksheets
128
and other per-subject files) are stored (on the local file system):""",
129
    """
130
# In the local file system, where are the per-subject file spaces located.
131
# The individual subject directories are expected to be located immediately
132
# in subdirectories of this location."""))
515 by stevenbird
Propagated "problem" -> "exercise" nomenclature change.
133
config_options.append(ConfigOption("exercises_base",
134
    "/home/informatics/exercises",
135
    """Root directory where the exercise directories (containing
136
subject-independent exercise sheets) are stored (on the local file
395 by mattgiuca
Tutorial: split subjects directory into subjects and problems.
137
system):""",
138
    """
515 by stevenbird
Propagated "problem" -> "exercise" nomenclature change.
139
# In the local file system, where are the subject-independent exercise sheet
395 by mattgiuca
Tutorial: split subjects directory into subjects and problems.
140
# file spaces located."""))
673 by mattgiuca
Rebuilt the way Terms of Service are displayed:
141
config_options.append(ConfigOption("tos_path",
142
    "/home/informatics/tos.html",
143
    """Location where the Terms of Service document is stored (on the local
144
    file system):""",
145
    """
146
# In the local file system, where is the Terms of Service document located."""))
712 by mattgiuca
setup: Added config option "motd_path" to hold the path for message-of-the-day
147
config_options.append(ConfigOption("motd_path",
148
    "/home/informatics/motd.html",
149
    """Location where the Message of the Day document is stored (on the local
150
    file system):""",
151
    """
152
# In the local file system, where is the Message of the Day document
153
# located. This is an HTML file (just the body fragment), which will
154
# be displayed on the login page. It is optional."""))
358 by mattgiuca
setup.py: Gutted out the config options code. It was getting so there were
155
config_options.append(ConfigOption("public_host", "public.localhost",
156
    """Hostname which will cause the server to go into "public mode",
157
providing login-free access to student's published work:""",
158
    """
159
# The server goes into "public mode" if the browser sends a request with this
160
# host. This is for security reasons - we only serve public student files on a
161
# separate domain to the main IVLE site.
162
# Public mode does not use cookies, and serves only public content.
163
# Private mode (normal mode) requires login, and only serves files relevant to
164
# the logged-in user."""))
165
config_options.append(ConfigOption("allowed_uids", "33",
166
    """UID of the web server process which will run IVLE.
167
Only this user may execute the trampoline. May specify multiple users as
168
a comma-separated list.
169
    (eg. "1002,78")""",
170
    """
171
# The User-ID of the web server process which will run IVLE, and any other
172
# users who are allowed to run the trampoline. This is stores as a string of
173
# comma-separated integers, simply because it is not used within Python, only
174
# used by the setup program to write to conf.h (see setup.py config)."""))
359 by mattgiuca
setup.py: Added config options for database settings.
175
config_options.append(ConfigOption("db_host", "localhost",
176
    """PostgreSQL Database config
177
==========================
178
Hostname of the DB server:""",
179
    """
180
### PostgreSQL Database config ###
181
# Database server hostname"""))
182
config_options.append(ConfigOption("db_port", "5432",
183
    """Port of the DB server:""",
184
    """
185
# Database server port"""))
363 by mattgiuca
setup.py: Added new config option - "database name"
186
config_options.append(ConfigOption("db_dbname", "ivle",
187
    """Database name:""",
188
    """
189
# Database name"""))
624 by dcoles
forum: Removed the subsilver2 style and phpBB installer
190
config_options.append(ConfigOption("db_forumdbname", "ivle_forum",
191
    """Forum Database name:""",
192
    """
193
# Forum Database name"""))
359 by mattgiuca
setup.py: Added config options for database settings.
194
config_options.append(ConfigOption("db_user", "postgres",
195
    """Username for DB server login:""",
196
    """
197
# Database username"""))
198
config_options.append(ConfigOption("db_password", "",
199
    """Password for DB server login:
409 by mattgiuca
Moved www/conf and www/common to a new directory lib. This separates the "web"
200
    (Caution: This password is stored in plaintext in lib/conf/conf.py)""",
359 by mattgiuca
setup.py: Added config options for database settings.
201
    """
202
# Database password"""))
531 by mattgiuca
www/auth: Split authenticate.py into 3 modules: autherror and ldap_auth.
203
config_options.append(ConfigOption("auth_modules", "ldap_auth",
530 by mattgiuca
setup.py:
204
    """Authentication config
205
=====================
206
Comma-separated list of authentication modules. Only "ldap" is available
207
by default.""",
208
    """
209
# Comma-separated list of authentication modules.
210
# These refer to importable Python modules in the www/auth directory.
211
# Modules "ldap" and "guest" are available in the source tree, but
212
# other modules may be plugged in to auth against organisation-specific
213
# auth backends."""))
510 by mattgiuca
setup.py: Added 2 new config options for the LDAP authentication server.
214
config_options.append(ConfigOption("ldap_url", "ldaps://www.example.com",
530 by mattgiuca
setup.py:
215
    """(LDAP options are only relevant if "ldap" is included in the list of
216
auth modules).
217
URL for LDAP authentication server:""",
510 by mattgiuca
setup.py: Added 2 new config options for the LDAP authentication server.
218
    """
219
# URL for LDAP authentication server"""))
220
config_options.append(ConfigOption("ldap_format_string",
221
    "uid=%s,ou=users,o=example",
222
    """Format string for LDAP auth request:
223
    (Must contain a single "%s" for the user's login name)""",
224
    """
225
# Format string for LDAP auth request
226
# (Must contain a single "%s" for the user's login name)"""))
522 by drtomc
Add quite a lot of stuff to get usrmgt happening.
227
config_options.append(ConfigOption("svn_addr", "http://svn.localhost/",
530 by mattgiuca
setup.py:
228
    """Subversion config
229
=================
230
The base url for accessing subversion repositories:""",
522 by drtomc
Add quite a lot of stuff to get usrmgt happening.
231
    """
232
# The base url for accessing subversion repositories."""))
460 by drtomc
setup.py: Add a bunch of config stuff we need.
233
config_options.append(ConfigOption("svn_conf", "/opt/ivle/svn/svn.conf",
234
    """The location of the subversion configuration file used by apache
235
to host the user repositories:""",
236
    """
237
# The location of the subversion configuration file used by
238
# apache to host the user repositories."""))
467 by drtomc
makeuser: Add some of the helper functions for activating users.
239
config_options.append(ConfigOption("svn_repo_path", "/home/informatics/repositories",
240
    """The root directory for the subversion repositories:""",
241
    """
242
# The root directory for the subversion repositories."""))
460 by drtomc
setup.py: Add a bunch of config stuff we need.
243
config_options.append(ConfigOption("svn_auth_ivle", "/opt/ivle/svn/ivle.auth",
244
    """The location of the password file used to authenticate users
245
of the subversion repository from the ivle server:""",
246
    """
247
# The location of the password file used to authenticate users
248
# of the subversion repository from the ivle server."""))
249
config_options.append(ConfigOption("svn_auth_local", "/opt/ivle/svn/local.auth",
250
    """The location of the password file used to authenticate local users
251
of the subversion repository:""",
252
    """
253
# The location of the password file used to authenticate local users
254
# of the subversion repository."""))
255
config_options.append(ConfigOption("usrmgt_host", "localhost",
530 by mattgiuca
setup.py:
256
    """User Management Server config
257
============================
258
The hostname where the usrmgt-server runs:""",
460 by drtomc
setup.py: Add a bunch of config stuff we need.
259
    """
260
# The hostname where the usrmgt-server runs."""))
261
config_options.append(ConfigOption("usrmgt_port", "2178",
262
    """The port where the usrmgt-server runs:""",
263
    """
264
# The port where the usrmgt-server runs."""))
265
config_options.append(ConfigOption("usrmgt_magic", "",
266
    """The password for the usrmgt-server:""",
267
    """
268
# The password for the usrmgt-server."""))
358 by mattgiuca
setup.py: Gutted out the config options code. It was getting so there were
269
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
270
# Try importing existing conf, but if we can't just set up defaults
271
# The reason for this is that these settings are used by other phases
272
# of setup besides conf, so we need to know them.
273
# Also this allows you to hit Return to accept the existing value.
274
try:
409 by mattgiuca
Moved www/conf and www/common to a new directory lib. This separates the "web"
275
    confmodule = __import__("lib/conf/conf")
358 by mattgiuca
setup.py: Gutted out the config options code. It was getting so there were
276
    for opt in config_options:
277
        try:
278
            globals()[opt.option_name] = confmodule.__dict__[opt.option_name]
279
        except:
280
            globals()[opt.option_name] = opt.default
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
281
except ImportError:
282
    # Just set reasonable defaults
358 by mattgiuca
setup.py: Gutted out the config options code. It was getting so there were
283
    for opt in config_options:
284
        globals()[opt.option_name] = opt.default
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
285
118 by mattgiuca
setup.py: Added copytree and copylist actions.
286
# Try importing install_list, but don't fail if we can't, because listmake can
287
# function without it.
288
try:
289
    import install_list
290
except:
291
    pass
292
117 by mattgiuca
setup.py: listmake uses mimetypes to select all files with certain mime types,
293
# Mime types which will automatically be placed in the list by listmake.
294
# Note that listmake is not intended to be run by the final user (the system
295
# administrator who installs this), so the developers can customize the list
296
# as necessary, and include it in the distribution.
297
listmake_mimetypes = ['text/x-python', 'text/html',
298
    'application/x-javascript', 'application/javascript',
568 by mattgiuca
setup.py: Added "image/gif" to types which listmake copies over.
299
    'text/css', 'image/png', 'image/gif', 'application/xml']
117 by mattgiuca
setup.py: listmake uses mimetypes to select all files with certain mime types,
300
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
301
# Main function skeleton from Guido van Rossum
302
# http://www.artima.com/weblogs/viewpost.jsp?thread=4829
303
304
def main(argv=None):
305
    if argv is None:
306
        argv = sys.argv
307
308
    # Print the opening spiel including the GPL notice
309
310
    print """IVLE - Informatics Virtual Learning Environment Setup
97 by mattgiuca
Moved template.py and setup.py to better places.
311
Copyright (C) 2007-2008 The University of Melbourne
312
IVLE comes with ABSOLUTELY NO WARRANTY.
313
This is free software, and you are welcome to redistribute it
314
under certain conditions. See LICENSE.txt for details.
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
315
316
IVLE Setup
317
"""
318
319
    # First argument is the name of the setup operation
320
    try:
321
        operation = argv[1]
322
    except IndexError:
323
        # Print usage message and exit
324
        help([])
325
        return 1
326
131 by mattgiuca
setup.py:
327
    # Disallow run as root unless installing
797 by dcoles
Setup: Addition of an automatic jail builder. This means we no longer are
328
    if (operation != 'install' and operation != 'updatejails' and operation != 
329
    'build'
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
330
        and os.geteuid() == 0):
131 by mattgiuca
setup.py:
331
        print >>sys.stderr, "I do not want to run this stage as root."
332
        print >>sys.stderr, "Please run as a normal user."
333
        return 1
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
334
    # Call the requested operation's function
335
    try:
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
336
        oper_func = {
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
337
            'help' : help,
316 by drtomc
setup.py - name the configuration command "config" to bring it into line with
338
            'config' : conf,
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
339
            'build' : build,
340
            'listmake' : listmake,
341
            'install' : install,
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
342
            'updatejails' : updatejails,
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
343
        }[operation]
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
344
    except KeyError:
345
        print >>sys.stderr, (
346
            """Invalid operation '%s'. Try python setup.py help."""
347
            % operation)
129 by mattgiuca
setup.py: Minor fix, exits cleanly if arguments are invalid.
348
        return 1
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
349
    return oper_func(argv[2:])
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
350
351
# Operation functions
352
353
def help(args):
354
    if args == []:
355
        print """Usage: python setup.py operation [args]
356
Operation (and args) can be:
357
    help [operation]
131 by mattgiuca
setup.py:
358
    listmake (developer use only)
316 by drtomc
setup.py - name the configuration command "config" to bring it into line with
359
    config [args]
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
360
    build
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
361
    install [--nojail] [--nosubjects] [-n|--dry]
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
362
"""
363
        return 1
364
    elif len(args) != 1:
365
        print """Usage: python setup.py help [operation]"""
366
        return 2
367
    else:
368
        operation = args[0]
369
370
    if operation == 'help':
371
        print """python setup.py help [operation]
372
Prints the usage message or detailed help on an operation, then exits."""
118 by mattgiuca
setup.py: Added copytree and copylist actions.
373
    elif operation == 'listmake':
374
        print """python setup.py listmake
375
(For developer use only)
376
Recurses through the source tree and builds a list of all files which should
377
be copied upon installation. This should be run by the developer before
378
cutting a distribution, and the listfile it generates should be included in
379
the distribution, avoiding the administrator having to run it."""
316 by drtomc
setup.py - name the configuration command "config" to bring it into line with
380
    elif operation == 'config':
381
        print """python setup.py config [args]
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
382
Configures IVLE with machine-specific details, most notably, various paths.
383
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!
384
command-line args. Will be interactive only if there are no arguments given.
385
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
386
387
To run IVLE out of the source directory (allowing development without having
388
to rebuild/install), just provide ivle_install_dir as the IVLE trunk
389
directory, and run build/install one time.
390
409 by mattgiuca
Moved www/conf and www/common to a new directory lib. This separates the "web"
391
Creates lib/conf/conf.py and trampoline/conf.h.
133 by mattgiuca
setup.py: Now allows IVLE to be installed over itself, in order to allow
392
358 by mattgiuca
setup.py: Gutted out the config options code. It was getting so there were
393
Args are:"""
394
        for opt in config_options:
395
            print "    --" + opt.option_name
396
        print """As explained in the interactive prompt or conf.py.
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
397
"""
398
    elif operation == 'build':
118 by mattgiuca
setup.py: Added copytree and copylist actions.
399
        print """python -O setup.py build [--dry|-n]
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
400
Compiles all files and sets up a jail template in the source directory.
116 by mattgiuca
setup.py: mkdir now properly obeys "dry".
401
-O is recommended to cause compilation to be optimised.
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
402
Details:
403
Compiles (GCC) trampoline/trampoline.c to trampoline/trampoline.
404
Creates jail/.
405
Creates standard subdirs inside the jail, eg bin, opt, home, tmp.
406
Copies console/ to a location within the jail.
407
Copies OS programs and files to corresponding locations within the jail
408
  (eg. python and Python libs, ld.so, etc).
118 by mattgiuca
setup.py: Added copytree and copylist actions.
409
Generates .pyc or .pyo files for all the IVLE .py files.
410
411
--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
412
    elif operation == 'install':
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
413
        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
414
(Requires root)
415
Create target install directory ($target).
416
Create $target/bin.
417
Copy trampoline/trampoline to $target/bin.
418
chown and chmod the installed trampoline.
419
Copy www/ to $target.
755 by dcoles
Added support for an incremental rebuild of all the users jails.
420
Copy jail/ to jails __staging__ directory (unless --nojail specified).
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
421
Copy subjects/ to subjects directory (unless --nosubjects specified).
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
422
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
423
--nojail        Do not copy the jail.
515 by stevenbird
Propagated "problem" -> "exercise" nomenclature change.
424
--nosubjects    Do not copy the subjects and exercises directories.
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
425
--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
426
    elif operation == 'updatejails':
427
        print """sudo python setup.py updatejails [--dry|-n]
428
(Requires root)
429
Copy jail/ to each subdirectory in jails directory.
430
431
--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
432
    else:
433
        print >>sys.stderr, (
434
            """Invalid operation '%s'. Try python setup.py help."""
435
            % operation)
436
    return 1
437
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
438
def listmake(args):
439
    # We build two separate lists, by walking www and console
440
    list_www = build_list_py_files('www')
409 by mattgiuca
Moved www/conf and www/common to a new directory lib. This separates the "web"
441
    list_lib = build_list_py_files('lib')
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
442
    list_subjects = build_list_py_files('subjects', no_top_level=True)
515 by stevenbird
Propagated "problem" -> "exercise" nomenclature change.
443
    list_exercises = build_list_py_files('exercises', no_top_level=True)
477 by mattgiuca
setup.py: Fixed creation of "scripts" directory in listmake.
444
    list_scripts = [
445
        "scripts/python-console",
446
        "scripts/fileservice",
657 by drtomc
serve: use the trampoline to serve all files.
447
        "scripts/serveservice",
477 by mattgiuca
setup.py: Fixed creation of "scripts" directory in listmake.
448
        "scripts/usrmgt-server",
562 by dcoles
Added new app: Diff (SVN diff application)
449
        "scripts/diffservice",
477 by mattgiuca
setup.py: Fixed creation of "scripts" directory in listmake.
450
    ]
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
451
    # Make sure that the files generated by conf are in the list
452
    # (since listmake is typically run before conf)
409 by mattgiuca
Moved www/conf and www/common to a new directory lib. This separates the "web"
453
    if "lib/conf/conf.py" not in list_lib:
427 by mattgiuca
setup.py: Fix (put conf.py in wrong list in listmake)
454
        list_lib.append("lib/conf/conf.py")
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
455
    # Write these out to a file
456
    cwd = os.getcwd()
457
    # the files that will be created/overwritten
458
    listfile = os.path.join(cwd, "install_list.py")
459
460
    try:
461
        file = open(listfile, "w")
462
463
        file.write("""# IVLE Configuration File
464
# install_list.py
117 by mattgiuca
setup.py: listmake uses mimetypes to select all files with certain mime types,
465
# Provides lists of all files to be installed by `setup.py install' from
466
# certain directories.
116 by mattgiuca
setup.py: mkdir now properly obeys "dry".
467
# Note that any files with the given filename plus 'c' or 'o' (that is,
468
# compiled .pyc or .pyo files) will be copied as well.
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
469
117 by mattgiuca
setup.py: listmake uses mimetypes to select all files with certain mime types,
470
# List of all installable files in www directory.
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
471
list_www = """)
472
        writelist_pretty(file, list_www)
473
        file.write("""
409 by mattgiuca
Moved www/conf and www/common to a new directory lib. This separates the "web"
474
# List of all installable files in lib directory.
475
list_lib = """)
476
        writelist_pretty(file, list_lib)
477
        file.write("""
418 by mattgiuca
Renamed trunk/console to trunk/scripts. We are now able to put more scripts in
478
# List of all installable files in scripts directory.
479
list_scripts = """)
480
        writelist_pretty(file, list_scripts)
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
481
        file.write("""
482
# List of all installable files in subjects directory.
483
# This is to install sample subjects and material.
484
list_subjects = """)
485
        writelist_pretty(file, list_subjects)
395 by mattgiuca
Tutorial: split subjects directory into subjects and problems.
486
        file.write("""
515 by stevenbird
Propagated "problem" -> "exercise" nomenclature change.
487
# List of all installable files in exercises directory.
395 by mattgiuca
Tutorial: split subjects directory into subjects and problems.
488
# This is to install sample exercise material.
515 by stevenbird
Propagated "problem" -> "exercise" nomenclature change.
489
list_exercises = """)
490
        writelist_pretty(file, list_exercises)
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
491
492
        file.close()
493
    except IOError, (errno, strerror):
494
        print "IO error(%s): %s" % (errno, strerror)
495
        sys.exit(1)
496
497
    print "Successfully wrote install_list.py"
498
499
    print
500
    print ("You may modify the set of installable files before cutting the "
501
            "distribution:")
502
    print listfile
503
    print
504
505
    return 0
506
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
507
def build_list_py_files(dir, no_top_level=False):
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
508
    """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
509
    subdirectories. Returns this as a list of strings.
510
    no_top_level=True means the file paths will not include the top-level
511
    directory.
512
    """
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
513
    pylist = []
514
    for (dirpath, dirnames, filenames) in os.walk(dir):
515
        # Exclude directories beginning with a '.' (such as '.svn')
516
        filter_mutate(lambda x: x[0] != '.', dirnames)
517
        # All *.py files are added to the list
518
        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,
519
            if mimetypes.guess_type(item)[0] in listmake_mimetypes]
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
520
    if no_top_level:
521
        for i in range(0, len(pylist)):
522
            _, pylist[i] = pylist[i].split(os.sep, 1)
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
523
    return pylist
524
525
def writelist_pretty(file, list):
526
    """Writes a list one element per line, to a file."""
527
    if list == []:
528
        file.write("[]\n")
529
    else:
530
        file.write('[\n')
531
        for elem in list:
532
            file.write('    %s,\n' % repr(elem))
533
        file.write(']\n')
534
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
535
def conf(args):
487 by mattgiuca
setup.py: Added code to convert usrmgt_port into an int before writing to conf
536
    global db_port, usrmgt_port
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
537
    # Set up some variables
538
539
    cwd = os.getcwd()
540
    # the files that will be created/overwritten
409 by mattgiuca
Moved www/conf and www/common to a new directory lib. This separates the "web"
541
    conffile = os.path.join(cwd, "lib/conf/conf.py")
433 by mattgiuca
setup.py: Conf now writes another file, lib/conf/jailconf.py. This file is a
542
    jailconffile = os.path.join(cwd, "lib/conf/jailconf.py")
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
543
    conf_hfile = os.path.join(cwd, "trampoline/conf.h")
624 by dcoles
forum: Removed the subsilver2 style and phpBB installer
544
    phpBBconffile = os.path.join(cwd, "www/php/phpBB3/config.php")
688 by apeel
setup.py now creates the /etc/init.d script for usrmgr-server, and install_proc.txt has instructions on installing it.
545
    usrmgtserver_initdfile = os.path.join(cwd, "doc/setup/usrmgt-server.init")
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
546
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
547
    # Get command-line arguments to avoid asking questions.
548
364 by mattgiuca
setup.py: Fixed config command-line args (forgot to make general).
549
    optnames = []
550
    for opt in config_options:
551
        optnames.append(opt.option_name + "=")
552
    (opts, args) = getopt.gnu_getopt(args, "", optnames)
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
553
554
    if args != []:
555
        print >>sys.stderr, "Invalid arguments:", string.join(args, ' ')
556
        return 2
557
558
    if opts == []:
559
        # Interactive mode. Prompt the user for all the values.
560
561
        print """This tool will create the following files:
100 by mattgiuca
setup.py: Added a new config variable, ivle_install_dir.
562
    %s
563
    %s
433 by mattgiuca
setup.py: Conf now writes another file, lib/conf/jailconf.py. This file is a
564
    %s
671 by dcoles
forum: Now uses a unique secret generated at './setup config' time for shared secret
565
    %s
688 by apeel
setup.py now creates the /etc/init.d script for usrmgr-server, and install_proc.txt has instructions on installing it.
566
    %s
97 by mattgiuca
Moved template.py and setup.py to better places.
567
prompting you for details about your configuration. The file will be
568
overwritten if it already exists. It will *not* install or deploy IVLE.
569
570
Please hit Ctrl+C now if you do not wish to do this.
688 by apeel
setup.py now creates the /etc/init.d script for usrmgr-server, and install_proc.txt has instructions on installing it.
571
""" % (conffile, jailconffile, conf_hfile, phpBBconffile, usrmgtserver_initdfile)
97 by mattgiuca
Moved template.py and setup.py to better places.
572
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
573
        # Get information from the administrator
574
        # If EOF is encountered at any time during the questioning, just exit
575
        # silently
97 by mattgiuca
Moved template.py and setup.py to better places.
576
358 by mattgiuca
setup.py: Gutted out the config options code. It was getting so there were
577
        for opt in config_options:
578
            globals()[opt.option_name] = \
579
                query_user(globals()[opt.option_name], opt.prompt)
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
580
    else:
581
        opts = dict(opts)
582
        # Non-interactive mode. Parse the options.
358 by mattgiuca
setup.py: Gutted out the config options code. It was getting so there were
583
        for opt in config_options:
584
            if '--' + opt.option_name in opts:
585
                globals()[opt.option_name] = opts['--' + opt.option_name]
120 by mattgiuca
setup.py: Added command-line argument mode for conf. This completely works!
586
110 by mattgiuca
setup.py: Added to trampoline/conf.h an "allowed_uids" array. Asks the user
587
    # Error handling on input values
588
    try:
358 by mattgiuca
setup.py: Gutted out the config options code. It was getting so there were
589
        allowed_uids_list = map(int, allowed_uids.split(','))
110 by mattgiuca
setup.py: Added to trampoline/conf.h an "allowed_uids" array. Asks the user
590
    except ValueError:
112 by mattgiuca
setup.py: A few comment changes.
591
        print >>sys.stderr, (
592
        "Invalid UID list (%s).\n"
593
        "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
594
        return 1
364 by mattgiuca
setup.py: Fixed config command-line args (forgot to make general).
595
    try:
596
        db_port = int(db_port)
597
        if db_port < 0 or db_port >= 65536: raise ValueError()
598
    except ValueError:
599
        print >>sys.stderr, (
600
        "Invalid DB port (%s).\n"
601
        "Must be an integer between 0 and 65535." % repr(db_port))
602
        return 1
487 by mattgiuca
setup.py: Added code to convert usrmgt_port into an int before writing to conf
603
    try:
604
        usrmgt_port = int(usrmgt_port)
605
        if usrmgt_port < 0 or usrmgt_port >= 65536: raise ValueError()
606
    except ValueError:
607
        print >>sys.stderr, (
608
        "Invalid user management port (%s).\n"
609
        "Must be an integer between 0 and 65535." % repr(usrmgt_port))
610
        return 1
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
611
671 by dcoles
forum: Now uses a unique secret generated at './setup config' time for shared secret
612
    # Generate the forum secret
613
    forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
614
409 by mattgiuca
Moved www/conf and www/common to a new directory lib. This separates the "web"
615
    # Write lib/conf/conf.py
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
616
617
    try:
618
        conf = open(conffile, "w")
619
620
        conf.write("""# IVLE Configuration File
97 by mattgiuca
Moved template.py and setup.py to better places.
621
# conf.py
622
# Miscellaneous application settings
623
358 by mattgiuca
setup.py: Gutted out the config options code. It was getting so there were
624
""")
625
        for opt in config_options:
364 by mattgiuca
setup.py: Fixed config command-line args (forgot to make general).
626
            conf.write('%s\n%s = %s\n' % (opt.comment, opt.option_name,
627
                repr(globals()[opt.option_name])))
110 by mattgiuca
setup.py: Added to trampoline/conf.h an "allowed_uids" array. Asks the user
628
671 by dcoles
forum: Now uses a unique secret generated at './setup config' time for shared secret
629
	# Add the forum secret to the config file (regenerated each config)
630
        conf.write('forum_secret = "%s"\n' % (forum_secret))
631
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
632
        conf.close()
633
    except IOError, (errno, strerror):
634
        print "IO error(%s): %s" % (errno, strerror)
635
        sys.exit(1)
636
409 by mattgiuca
Moved www/conf and www/common to a new directory lib. This separates the "web"
637
    print "Successfully wrote lib/conf/conf.py"
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
638
433 by mattgiuca
setup.py: Conf now writes another file, lib/conf/jailconf.py. This file is a
639
    # Write conf/jailconf.py
640
641
    try:
642
        conf = open(jailconffile, "w")
643
644
        # In the "in-jail" version of conf, we don't need MOST of the details
645
        # (it would be a security risk to have them here).
646
        # So we just write root_dir, and jail_base is "/".
647
        # (jail_base being "/" means "jail-relative" paths are relative to "/"
648
        # when inside the jail.)
649
        conf.write("""# IVLE Configuration File
650
# conf.py
651
# Miscellaneous application settings
652
# (User jail version)
653
654
655
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
656
# with this).
657
# eg. "/" or "/ivle".
658
root_dir = %s
659
660
# In the local file system, where are the student/user file spaces located.
661
# The user jails are expected to be located immediately in subdirectories of
662
# this location.
663
jail_base = '/'
435 by drtomc
setup.py: Fix a couple of jail config glitches.
664
665
# The hostname for serving publicly accessible pages
666
public_host = %s
667
""" % (repr(root_dir),repr(public_host)))
433 by mattgiuca
setup.py: Conf now writes another file, lib/conf/jailconf.py. This file is a
668
669
        conf.close()
670
    except IOError, (errno, strerror):
671
        print "IO error(%s): %s" % (errno, strerror)
672
        sys.exit(1)
673
674
    print "Successfully wrote lib/conf/jailconf.py"
675
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
676
    # Write trampoline/conf.h
677
678
    try:
679
        conf = open(conf_hfile, "w")
680
681
        conf.write("""/* IVLE Configuration File
100 by mattgiuca
setup.py: Added a new config variable, ivle_install_dir.
682
 * conf.h
683
 * Administrator settings required by trampoline.
684
 * Note: trampoline will have to be rebuilt in order for changes to this file
685
 * to take effect.
686
 */
687
688
/* In the local file system, where are the jails located.
689
 * The trampoline does not allow the creation of a jail anywhere besides
690
 * jail_base or a subdirectory of jail_base.
691
 */
692
static const char* jail_base = "%s";
110 by mattgiuca
setup.py: Added to trampoline/conf.h an "allowed_uids" array. Asks the user
693
694
/* Which user IDs are allowed to run the trampoline.
695
 * This list should be limited to the web server user.
696
 * (Note that root is an implicit member of this list).
697
 */
112 by mattgiuca
setup.py: A few comment changes.
698
static const int allowed_uids[] = { %s };
433 by mattgiuca
setup.py: Conf now writes another file, lib/conf/jailconf.py. This file is a
699
""" % (repr(jail_base)[1:-1], repr(allowed_uids_list)[1:-1]))
700
    # Note: The above uses PYTHON reprs, not C reprs
701
    # However they should be the same with the exception of the outer
702
    # characters, which are stripped off and replaced
100 by mattgiuca
setup.py: Added a new config variable, ivle_install_dir.
703
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
704
        conf.close()
705
    except IOError, (errno, strerror):
706
        print "IO error(%s): %s" % (errno, strerror)
707
        sys.exit(1)
708
709
    print "Successfully wrote trampoline/conf.h"
710
624 by dcoles
forum: Removed the subsilver2 style and phpBB installer
711
    # Write www/php/phpBB3/config.php
712
713
    try:
714
        conf = open(phpBBconffile, "w")
715
        
716
        # php-pg work around
717
        if db_host == 'localhost':
718
            forumdb_host = '127.0.0.1'
719
        else:
720
            forumdb_host = db_host
721
722
        conf.write( """<?php
723
// phpBB 3.0.x auto-generated configuration file
724
// Do not change anything in this file!
725
$dbms = 'postgres';
726
$dbhost = '""" + forumdb_host + """';
727
$dbport = '""" + str(db_port) + """';
728
$dbname = '""" + db_forumdbname + """';
729
$dbuser = '""" + db_user + """';
730
$dbpasswd = '""" + db_password + """';
731
732
$table_prefix = 'phpbb_';
733
$acm_type = 'file';
734
$load_extensions = '';
735
@define('PHPBB_INSTALLED', true);
736
// @define('DEBUG', true);
737
//@define('DEBUG_EXTRA', true);
671 by dcoles
forum: Now uses a unique secret generated at './setup config' time for shared secret
738
739
$forum_secret = '""" + forum_secret +"""';
624 by dcoles
forum: Removed the subsilver2 style and phpBB installer
740
?>"""   )
741
    
742
        conf.close()
743
    except IOError, (errno, strerror):
744
        print "IO error(%s): %s" % (errno, strerror)
745
        sys.exit(1)
746
747
    print "Successfully wrote www/php/phpBB3/config.php"
748
688 by apeel
setup.py now creates the /etc/init.d script for usrmgr-server, and install_proc.txt has instructions on installing it.
749
    # Write lib/conf/usrmgt-server.init
750
751
    try:
752
        conf = open(usrmgtserver_initdfile, "w")
753
754
        conf.write( '''#! /bin/sh
755
756
# Works for Ubuntu. Check before using on other distributions
757
758
### BEGIN INIT INFO
759
# Provides:          usrmgt-server
760
# Required-Start:    $syslog $networking $urandom
761
# Required-Stop:     $syslog
762
# Default-Start:     2 3 4 5
763
# Default-Stop:      1
764
# Short-Description: IVLE user management server
765
# Description:       Daemon connecting to the IVLE user management database.
766
### END INIT INFO
767
768
PATH=/sbin:/bin:/usr/sbin:/usr/bin
769
DESC="IVLE user management server"
770
NAME=usrmgt-server
771
DAEMON=/opt/ivle/scripts/$NAME
772
DAEMON_ARGS="''' + str(usrmgt_port) + ''' ''' + usrmgt_magic + '''"
773
PIDFILE=/var/run/$NAME.pid
774
SCRIPTNAME=/etc/init.d/usrmgt-server
775
776
# Exit if the daemon does not exist 
777
test -f $DAEMON || exit 0
778
779
# Load the VERBOSE setting and other rcS variables
780
[ -f /etc/default/rcS ] && . /etc/default/rcS
781
782
# Define LSB log_* functions.
783
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
784
. /lib/lsb/init-functions
785
786
#
787
# Function that starts the daemon/service
788
#
789
do_start()
790
{
791
	# Return
792
	#   0 if daemon has been started
793
	#   1 if daemon was already running
794
	#   2 if daemon could not be started
795
	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
796
		|| return 1
797
	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
798
		$DAEMON_ARGS \
799
		|| return 2
800
	# Add code here, if necessary, that waits for the process to be ready
801
	# to handle requests from services started subsequently which depend
802
	# on this one.  As a last resort, sleep for some time.
803
}
804
805
#
806
# Function that stops the daemon/service
807
#
808
do_stop()
809
{
810
	# Return
811
	#   0 if daemon has been stopped
812
	#   1 if daemon was already stopped
813
	#   2 if daemon could not be stopped
814
	#   other if a failure occurred
815
	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
816
	RETVAL="$?"
817
	[ "$RETVAL" = 2 ] && return 2
818
	# Wait for children to finish too if this is a daemon that forks
819
	# and if the daemon is only ever run from this initscript.
820
	# If the above conditions are not satisfied then add some other code
821
	# that waits for the process to drop all resources that could be
822
	# needed by services started subsequently.  A last resort is to
823
	# sleep for some time.
824
	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
825
	[ "$?" = 2 ] && return 2
826
	# Many daemons don't delete their pidfiles when they exit.
827
	rm -f $PIDFILE
828
	return "$RETVAL"
829
}
830
831
#
832
# Function that sends a SIGHUP to the daemon/service
833
#
834
do_reload() {
835
	#
836
	# If the daemon can reload its configuration without
837
	# restarting (for example, when it is sent a SIGHUP),
838
	# then implement that here.
839
	#
840
	start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
841
	return 0
842
}
843
844
case "$1" in
845
  start)
846
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
847
	do_start
848
	case "$?" in
849
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
850
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
851
	esac
852
	;;
853
  stop)
854
	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
855
	do_stop
856
	case "$?" in
857
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
858
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
859
	esac
860
	;;
861
  #reload|force-reload)
862
	#
863
	# If do_reload() is not implemented then leave this commented out
864
	# and leave 'force-reload' as an alias for 'restart'.
865
	#
866
	#log_daemon_msg "Reloading $DESC" "$NAME"
867
	#do_reload
868
	#log_end_msg $?
869
	#;;
870
  restart|force-reload)
871
	#
872
	# If the "reload" option is implemented then remove the
873
	# 'force-reload' alias
874
	#
875
	log_daemon_msg "Restarting $DESC" "$NAME"
876
	do_stop
877
	case "$?" in
878
	  0|1)
879
		do_start
880
		case "$?" in
881
			0) log_end_msg 0 ;;
882
			1) log_end_msg 1 ;; # Old process is still running
883
			*) log_end_msg 1 ;; # Failed to start
884
		esac
885
		;;
886
	  *)
887
	  	# Failed to stop
888
		log_end_msg 1
889
		;;
890
	esac
891
	;;
892
  *)
893
	#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
894
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
895
	exit 3
896
	;;
897
esac
898
899
:
900
''')
901
        
902
        conf.close()
903
    except IOError, (errno, strerror):
904
        print "IO error(%s): %s" % (errno, strerror)
905
        sys.exit(1)
906
907
    # fix permissions as the file contains the database password
908
    try:
909
        os.chmod('doc/setup/usrmgt-server.init', 0600)
910
    except OSError, (errno, strerror):
911
        print "WARNING: Couldn't chmod doc/setup/usrmgt-server.init:"
912
        print "OS error(%s): %s" % (errno, strerror)
913
914
    print "Successfully wrote lib/conf/usrmgt-server.init"
915
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
916
    print
917
    print "You may modify the configuration at any time by editing"
918
    print conffile
433 by mattgiuca
setup.py: Conf now writes another file, lib/conf/jailconf.py. This file is a
919
    print jailconffile
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
920
    print conf_hfile
624 by dcoles
forum: Removed the subsilver2 style and phpBB installer
921
    print phpBBconffile
688 by apeel
setup.py now creates the /etc/init.d script for usrmgr-server, and install_proc.txt has instructions on installing it.
922
    print usrmgtserver_initdfile
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
923
    print
924
    return 0
925
926
def build(args):
121 by mattgiuca
setup: build and install now read command line options
927
    # Get "dry" variable from command line
928
    (opts, args) = getopt.gnu_getopt(args, "n", ['dry'])
929
    opts = dict(opts)
930
    dry = '-n' in opts or '--dry' in opts
931
932
    if dry:
933
        print "Dry run (no actions will be executed\n"
746 by dcoles
Setup: During Build the system will now indicate what revision is being built
934
    
797 by dcoles
Setup: Addition of an automatic jail builder. This means we no longer are
935
    if not dry and os.geteuid() != 0:
936
        print >>sys.stderr, "Must be root to run build"
937
        print >>sys.stderr, "(I need to chroot)."
938
        return 1
939
    
746 by dcoles
Setup: During Build the system will now indicate what revision is being built
940
    # Find out the revison number
941
    revnum = get_svn_revision()
942
    print "Building Revision %s"%str(revnum)
943
    if not dry:
944
        vfile = open('BUILD-VERSION','w')
945
        vfile.write(str(revnum) + '\n')
946
        vfile.close()
107 by mattgiuca
setup.py: Added "action" functions which encapsulate calling OS functions.
947
948
    # Compile the trampoline
349 by mattgiuca
setup.py: Changed so instead of directly calling gcc on the trampoline, calls
949
    curdir = os.getcwd()
950
    os.chdir('trampoline')
951
    action_runprog('make', [], dry)
952
    os.chdir(curdir)
107 by mattgiuca
setup.py: Added "action" functions which encapsulate calling OS functions.
953
954
    # Create the jail and its subdirectories
122 by mattgiuca
setup.py: build action now copies all operating system files into the jail.
955
    # Note: Other subdirs will be made by copying files
797 by dcoles
Setup: Addition of an automatic jail builder. This means we no longer are
956
    action_runprog('./buildjail.sh', [], dry)
547 by dcoles
settup.py: Added nss libaries and /etc files needed for resolving hostnames.
957
122 by mattgiuca
setup.py: build action now copies all operating system files into the jail.
958
    # Copy all console and operating system files into the jail
418 by mattgiuca
Renamed trunk/console to trunk/scripts. We are now able to put more scripts in
959
    action_copylist(install_list.list_scripts, 'jail/opt/ivle', dry)
253 by mattgiuca
setup.py: chmods python-console when building.
960
    # Chmod the python console
418 by mattgiuca
Renamed trunk/console to trunk/scripts. We are now able to put more scripts in
961
    action_chmod_x('jail/opt/ivle/scripts/python-console', dry)
962
    action_chmod_x('jail/opt/ivle/scripts/fileservice', dry)
657 by drtomc
serve: use the trampoline to serve all files.
963
    action_chmod_x('jail/opt/ivle/scripts/serveservice', dry)
253 by mattgiuca
setup.py: chmods python-console when building.
964
    
422 by mattgiuca
setup.py: Needs to copy the "lib" directory into the jail. Now does this and
965
    # Also copy the IVLE lib directory into the jail
966
    # This is necessary for running certain scripts
967
    action_copylist(install_list.list_lib, 'jail/opt/ivle', dry)
433 by mattgiuca
setup.py: Conf now writes another file, lib/conf/jailconf.py. This file is a
968
    # IMPORTANT: The file jail/opt/ivle/lib/conf/conf.py contains details
969
    # which could compromise security if left in the jail (such as the DB
970
    # password).
971
    # The "safe" version is in jailconf.py. Delete conf.py and replace it with
972
    # jailconf.py.
435 by drtomc
setup.py: Fix a couple of jail config glitches.
973
    action_copyfile('lib/conf/jailconf.py',
433 by mattgiuca
setup.py: Conf now writes another file, lib/conf/jailconf.py. This file is a
974
        'jail/opt/ivle/lib/conf/conf.py', dry)
118 by mattgiuca
setup.py: Added copytree and copylist actions.
975
116 by mattgiuca
setup.py: mkdir now properly obeys "dry".
976
    # Compile .py files into .pyc or .pyo files
977
    compileall.compile_dir('www', quiet=True)
422 by mattgiuca
setup.py: Needs to copy the "lib" directory into the jail. Now does this and
978
    compileall.compile_dir('lib', quiet=True)
433 by mattgiuca
setup.py: Conf now writes another file, lib/conf/jailconf.py. This file is a
979
    compileall.compile_dir('scripts', quiet=True)
422 by mattgiuca
setup.py: Needs to copy the "lib" directory into the jail. Now does this and
980
    compileall.compile_dir('jail/opt/ivle/lib', quiet=True)
981
982
    # Set up ivle.pth inside the jail
983
    # Need to set /opt/ivle/lib to be on the import path
984
    ivle_pth = \
985
        "jail/usr/lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION
986
    f = open(ivle_pth, 'w')
987
    f.write('/opt/ivle/lib\n')
988
    f.close()
107 by mattgiuca
setup.py: Added "action" functions which encapsulate calling OS functions.
989
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
990
    return 0
991
122 by mattgiuca
setup.py: build action now copies all operating system files into the jail.
992
def copy_file_to_jail(src, dry):
993
    """Copies a single file from an absolute location into the same location
994
    within the jail. src must begin with a '/'. The jail will be located
995
    in a 'jail' subdirectory of the current path."""
996
    action_copyfile(src, 'jail' + src, dry)
997
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
998
def install(args):
121 by mattgiuca
setup: build and install now read command line options
999
    # Get "dry" and "nojail" variables from command line
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
1000
    (opts, args) = getopt.gnu_getopt(args, "n",
1001
        ['dry', 'nojail', 'nosubjects'])
121 by mattgiuca
setup: build and install now read command line options
1002
    opts = dict(opts)
1003
    dry = '-n' in opts or '--dry' in opts
1004
    nojail = '--nojail' in opts
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
1005
    nosubjects = '--nosubjects' in opts
121 by mattgiuca
setup: build and install now read command line options
1006
1007
    if dry:
1008
        print "Dry run (no actions will be executed\n"
119 by mattgiuca
setup.py: Added install action. Completely works!
1009
1010
    if not dry and os.geteuid() != 0:
1011
        print >>sys.stderr, "Must be root to run install"
1012
        print >>sys.stderr, "(I need to chown some files)."
1013
        return 1
1014
1015
    # Create the target (install) directory
1016
    action_mkdir(ivle_install_dir, dry)
1017
1018
    # Create bin and copy the compiled files there
1019
    action_mkdir(os.path.join(ivle_install_dir, 'bin'), dry)
1020
    tramppath = os.path.join(ivle_install_dir, 'bin/trampoline')
1021
    action_copyfile('trampoline/trampoline', tramppath, dry)
1022
    # chown trampoline to root and set setuid bit
1023
    action_chown_setuid(tramppath, dry)
1024
528 by drtomc
usrmgt-server: robustify svn url handling a bit.
1025
    # Create a scripts directory to put the usrmgt-server in.
1026
    action_mkdir(os.path.join(ivle_install_dir, 'scripts'), dry)
1027
    usrmgtpath = os.path.join(ivle_install_dir, 'scripts/usrmgt-server')
1028
    action_copyfile('scripts/usrmgt-server', usrmgtpath, dry)
1029
    action_chmod_x(usrmgtpath, dry)
1030
409 by mattgiuca
Moved www/conf and www/common to a new directory lib. This separates the "web"
1031
    # Copy the www and lib directories using the list
119 by mattgiuca
setup.py: Added install action. Completely works!
1032
    action_copylist(install_list.list_www, ivle_install_dir, dry)
409 by mattgiuca
Moved www/conf and www/common to a new directory lib. This separates the "web"
1033
    action_copylist(install_list.list_lib, ivle_install_dir, dry)
524 by dcoles
forum: Changed setup to just copy the phpBB directory (probbaly can be made
1034
    
1035
    # Copy the php directory
681 by dcoles
setup.py: chown the phpBB3 directory to www-data for correct permissions
1036
    forum_dir = "www/php/phpBB3"
1037
    forum_path = os.path.join(ivle_install_dir, forum_dir)
1038
    action_copytree(forum_dir, forum_path, dry)
1039
    print "chown -R www-data:www-data %s" % forum_path
1040
    if not dry:
1041
        os.system("chown -R www-data:www-data %s" % forum_path)
119 by mattgiuca
setup.py: Added install action. Completely works!
1042
1043
    if not nojail:
1044
        # Copy the local jail directory built by the build action
755 by dcoles
Added support for an incremental rebuild of all the users jails.
1045
        # to the jails __staging__ directory (it will be used to help build
1046
        # all the students' jails).
1047
        action_copytree('jail', os.path.join(jail_base, '__staging__'), dry)
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
1048
    if not nosubjects:
515 by stevenbird
Propagated "problem" -> "exercise" nomenclature change.
1049
        # Copy the subjects and exercises directories across
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
1050
        action_copylist(install_list.list_subjects, subjects_base, dry,
1051
            srcdir="./subjects")
515 by stevenbird
Propagated "problem" -> "exercise" nomenclature change.
1052
        action_copylist(install_list.list_exercises, exercises_base, dry,
1053
            srcdir="./exercises")
119 by mattgiuca
setup.py: Added install action. Completely works!
1054
256 by mattgiuca
Changed the way IVLE's path is loaded into Python's sys.path. Now a file
1055
    # Append IVLE path to ivle.pth in python site packages
1056
    # (Unless it's already there)
1057
    ivle_pth = os.path.join(sys.prefix,
317 by mattgiuca
doc/dependencies: Added dependency on matplotlib.
1058
        "lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION)
256 by mattgiuca
Changed the way IVLE's path is loaded into Python's sys.path. Now a file
1059
    ivle_www = os.path.join(ivle_install_dir, "www")
409 by mattgiuca
Moved www/conf and www/common to a new directory lib. This separates the "web"
1060
    ivle_lib = os.path.join(ivle_install_dir, "lib")
256 by mattgiuca
Changed the way IVLE's path is loaded into Python's sys.path. Now a file
1061
    write_ivle_pth = True
409 by mattgiuca
Moved www/conf and www/common to a new directory lib. This separates the "web"
1062
    write_ivle_lib_pth = True
256 by mattgiuca
Changed the way IVLE's path is loaded into Python's sys.path. Now a file
1063
    try:
1064
        file = open(ivle_pth, 'r')
1065
        for line in file:
1066
            if line.strip() == ivle_www:
1067
                write_ivle_pth = False
409 by mattgiuca
Moved www/conf and www/common to a new directory lib. This separates the "web"
1068
            elif line.strip() == ivle_lib:
1069
                write_ivle_lib_pth = False
1070
        file.close()
256 by mattgiuca
Changed the way IVLE's path is loaded into Python's sys.path. Now a file
1071
    except (IOError, OSError):
1072
        pass
1073
    if write_ivle_pth:
1074
        action_append(ivle_pth, ivle_www)
409 by mattgiuca
Moved www/conf and www/common to a new directory lib. This separates the "web"
1075
    if write_ivle_lib_pth:
1076
        action_append(ivle_pth, ivle_lib)
256 by mattgiuca
Changed the way IVLE's path is loaded into Python's sys.path. Now a file
1077
781 by apeel
install now creates a file ivle_install_dir/version/ivle-revision.txt
1078
1079
    # Create the ivle working revision record file
1080
    action_mkdir(os.path.join(ivle_install_dir, 'version'), dry)
1081
    ivle_revision_record_file = os.path.join(ivle_install_dir, 'version/ivle-revision.txt')
1082
    if not dry:
1083
        try:
1084
            conf = open(ivle_revision_record_file, "w")
1085
1086
            conf.write( "# IVLE code revision listing generated by running 'svn status -v ..' from " + os.getcwd() + "\n#\n\n")
1087
1088
            conf.close()
1089
        except IOError, (errno, strerror):
1090
            print "IO error(%s): %s" % (errno, strerror)
1091
            sys.exit(1)
1092
1093
        os.system("svn status -v .. >> %s" % ivle_revision_record_file)
1094
1095
    print "Wrote IVLE code revision status to %s" % ivle_revision_record_file
1096
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
1097
    return 0
1098
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
1099
def updatejails(args):
1100
    # Get "dry" variable from command line
1101
    (opts, args) = getopt.gnu_getopt(args, "n", ['dry'])
1102
    opts = dict(opts)
1103
    dry = '-n' in opts or '--dry' in opts
1104
1105
    if dry:
1106
        print "Dry run (no actions will be executed\n"
1107
1108
    if not dry and os.geteuid() != 0:
1109
        print >>sys.stderr, "Must be root to run install"
1110
        print >>sys.stderr, "(I need to chown some files)."
1111
        return 1
1112
755 by dcoles
Added support for an incremental rebuild of all the users jails.
1113
    # Update the staging jail directory in case it hasn't been installed
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
1114
    # recently.
755 by dcoles
Added support for an incremental rebuild of all the users jails.
1115
    action_copytree('jail', os.path.join(jail_base, '__staging__'), dry)
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
1116
1117
    # Re-link all the files in all students jails.
1118
    for dir in os.listdir(jail_base):
755 by dcoles
Added support for an incremental rebuild of all the users jails.
1119
        if dir == '__staging__': continue
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
1120
        # First back up the student's home directory
1121
        temp_home = os.tmpnam()
1122
        action_rename(os.path.join(jail_base, dir, 'home'), temp_home, dry)
1123
        # Delete the student's jail and relink the jail files
755 by dcoles
Added support for an incremental rebuild of all the users jails.
1124
        action_linktree(os.path.join(jail_base, '__staging__'),
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
1125
            os.path.join(jail_base, dir), dry)
1126
        # Restore the student's home directory
1127
        action_rename(temp_home, os.path.join(jail_base, dir, 'home'), dry)
1128
        # Set up the user's home directory just in case they don't have a
1129
        # directory for this yet
1130
        action_mkdir(os.path.join(jail_base, dir, 'home', dir), dry)
1131
1132
    return 0
1133
107 by mattgiuca
setup.py: Added "action" functions which encapsulate calling OS functions.
1134
# The actions call Python os functions but print actions and handle dryness.
1135
# May still throw os exceptions if errors occur.
1136
108 by mattgiuca
setup.py: Added RunError class. action_runprog now throws a RunError if the
1137
class RunError:
1138
    """Represents an error when running a program (nonzero return)."""
1139
    def __init__(self, prog, retcode):
1140
        self.prog = prog
1141
        self.retcode = retcode
1142
    def __str__(self):
1143
        return str(self.prog) + " returned " + repr(self.retcode)
1144
107 by mattgiuca
setup.py: Added "action" functions which encapsulate calling OS functions.
1145
def action_runprog(prog, args, dry):
1146
    """Runs a unix program. Searches in $PATH. Synchronous (waits for the
1147
    program to return). Runs in the current environment. First prints the
1148
    action as a "bash" line.
1149
108 by mattgiuca
setup.py: Added RunError class. action_runprog now throws a RunError if the
1150
    Throws a RunError with a retcode of the return value of the program,
1151
    if the program did not return 0.
1152
107 by mattgiuca
setup.py: Added "action" functions which encapsulate calling OS functions.
1153
    prog: String. Name of the program. (No path required, if in $PATH).
1154
    args: [String]. Arguments to the program.
1155
    dry: Bool. If True, prints but does not execute.
1156
    """
1157
    print prog, string.join(args, ' ')
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
1158
    if dry: return
1159
    ret = os.spawnvp(os.P_WAIT, prog, args)
1160
    if ret != 0:
1161
        raise RunError(prog, ret)
107 by mattgiuca
setup.py: Added "action" functions which encapsulate calling OS functions.
1162
433 by mattgiuca
setup.py: Conf now writes another file, lib/conf/jailconf.py. This file is a
1163
def action_remove(path, dry):
1164
    """Calls rmtree, deleting the target file if it exists."""
434 by drtomc
setup.py: add a bunch of shared objects to be added to the jail for svn.
1165
    try:
433 by mattgiuca
setup.py: Conf now writes another file, lib/conf/jailconf.py. This file is a
1166
        print "rm -r", path
1167
        if not dry:
1168
            shutil.rmtree(path, True)
434 by drtomc
setup.py: add a bunch of shared objects to be added to the jail for svn.
1169
    except OSError, (err, msg):
1170
        if err != errno.EEXIST:
1171
            raise
1172
        # Otherwise, didn't exist, so we don't care
433 by mattgiuca
setup.py: Conf now writes another file, lib/conf/jailconf.py. This file is a
1173
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
1174
def action_rename(src, dst, dry):
1175
    """Calls rename. Deletes the target if it already exists."""
433 by mattgiuca
setup.py: Conf now writes another file, lib/conf/jailconf.py. This file is a
1176
    action_remove(dst, dry)
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
1177
    print "mv ", src, dst
1178
    if dry: return
1179
    try:
1180
        os.rename(src, dst)
1181
    except OSError, (err, msg):
1182
        if err != errno.EEXIST:
1183
            raise
1184
116 by mattgiuca
setup.py: mkdir now properly obeys "dry".
1185
def action_mkdir(path, dry):
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
1186
    """Calls mkdir. Silently ignored if the directory already exists.
1187
    Creates all parent directories as necessary."""
1188
    print "mkdir -p", path
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
1189
    if dry: return
107 by mattgiuca
setup.py: Added "action" functions which encapsulate calling OS functions.
1190
    try:
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
1191
        os.makedirs(path)
107 by mattgiuca
setup.py: Added "action" functions which encapsulate calling OS functions.
1192
    except OSError, (err, msg):
1193
        if err != errno.EEXIST:
1194
            raise
1195
118 by mattgiuca
setup.py: Added copytree and copylist actions.
1196
def action_copytree(src, dst, dry):
1197
    """Copies an entire directory tree. Symlinks are seen as normal files and
1198
    copies of the entire file (not the link) are made. Creates all parent
1199
    directories as necessary.
1200
1201
    See shutil.copytree."""
529 by mattgiuca
setup.py: Fixed copytree; now able to handle copying a directory over itself
1202
    # Allow copying over itself
1203
    if (os.path.normpath(os.path.join(os.getcwd(),src)) ==
1204
        os.path.normpath(os.path.join(os.getcwd(),dst))):
1205
        return
433 by mattgiuca
setup.py: Conf now writes another file, lib/conf/jailconf.py. This file is a
1206
    action_remove(dst, dry)
118 by mattgiuca
setup.py: Added copytree and copylist actions.
1207
    print "cp -r", src, dst
1208
    if dry: return
132 by mattgiuca
setup.py: File copying is more robust - preserves symlinks and permissions
1209
    shutil.copytree(src, dst, True)
118 by mattgiuca
setup.py: Added copytree and copylist actions.
1210
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
1211
def action_linktree(src, dst, dry):
1212
    """Hard-links an entire directory tree. Same as copytree but the created
1213
    files are hard-links not actual copies. Removes the existing destination.
1214
    """
433 by mattgiuca
setup.py: Conf now writes another file, lib/conf/jailconf.py. This file is a
1215
    action_remove(dst, dry)
252 by mattgiuca
setup.py: Added action "updatejails" which wipes all student jails, replacing
1216
    print "<cp with hardlinks> -r", src, dst
1217
    if dry: return
1218
    common.makeuser.linktree(src, dst)
1219
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
1220
def action_copylist(srclist, dst, dry, srcdir="."):
118 by mattgiuca
setup.py: Added copytree and copylist actions.
1221
    """Copies all files in a list to a new location. The files in the list
1222
    are read relative to the current directory, and their destinations are the
1223
    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
1224
    srcdir is "." by default, can be overridden.
118 by mattgiuca
setup.py: Added copytree and copylist actions.
1225
    """
1226
    for srcfile in srclist:
1227
        dstfile = os.path.join(dst, srcfile)
313 by mattgiuca
test/test_framework: Updated examples, a bit of better descriptions, sample
1228
        srcfile = os.path.join(srcdir, srcfile)
118 by mattgiuca
setup.py: Added copytree and copylist actions.
1229
        dstdir = os.path.split(dstfile)[0]
1230
        if not os.path.isdir(dstdir):
1231
            action_mkdir(dstdir, dry)
1232
        print "cp -f", srcfile, dstfile
1233
        if not dry:
133 by mattgiuca
setup.py: Now allows IVLE to be installed over itself, in order to allow
1234
            try:
1235
                shutil.copyfile(srcfile, dstfile)
1236
                shutil.copymode(srcfile, dstfile)
1237
            except shutil.Error:
1238
                pass
118 by mattgiuca
setup.py: Added copytree and copylist actions.
1239
119 by mattgiuca
setup.py: Added install action. Completely works!
1240
def action_copyfile(src, dst, dry):
1241
    """Copies one file to a new location. Creates all parent directories
1242
    as necessary.
318 by mattgiuca
setup.py: action_copyfile now handles errors as warnings, instead of quitting
1243
    Warn if file not found.
119 by mattgiuca
setup.py: Added install action. Completely works!
1244
    """
1245
    dstdir = os.path.split(dst)[0]
1246
    if not os.path.isdir(dstdir):
1247
        action_mkdir(dstdir, dry)
1248
    print "cp -f", src, dst
1249
    if not dry:
133 by mattgiuca
setup.py: Now allows IVLE to be installed over itself, in order to allow
1250
        try:
1251
            shutil.copyfile(src, dst)
1252
            shutil.copymode(src, dst)
318 by mattgiuca
setup.py: action_copyfile now handles errors as warnings, instead of quitting
1253
        except (shutil.Error, IOError), e:
1254
            print "Warning: " + str(e)
119 by mattgiuca
setup.py: Added install action. Completely works!
1255
122 by mattgiuca
setup.py: build action now copies all operating system files into the jail.
1256
def action_symlink(src, dst, dry):
1257
    """Creates a symlink in a given location. Creates all parent directories
1258
    as necessary.
1259
    """
1260
    dstdir = os.path.split(dst)[0]
1261
    if not os.path.isdir(dstdir):
1262
        action_mkdir(dstdir, dry)
131 by mattgiuca
setup.py:
1263
    # Delete existing file
1264
    if os.path.exists(dst):
1265
        os.remove(dst)
1266
    print "ln -fs", src, dst
122 by mattgiuca
setup.py: build action now copies all operating system files into the jail.
1267
    if not dry:
1268
        os.symlink(src, dst)
1269
256 by mattgiuca
Changed the way IVLE's path is loaded into Python's sys.path. Now a file
1270
def action_append(ivle_pth, ivle_www):
1271
    file = open(ivle_pth, 'a+')
1272
    file.write(ivle_www + '\n')
1273
    file.close()
1274
119 by mattgiuca
setup.py: Added install action. Completely works!
1275
def action_chown_setuid(file, dry):
1276
    """Chowns a file to root, and sets the setuid bit on the file.
1277
    Calling this function requires the euid to be root.
1278
    The actual mode of path is set to: rws--s--s
1279
    """
1280
    print "chown root:root", file
1281
    if not dry:
1282
        os.chown(file, 0, 0)
1283
    print "chmod a+xs", file
1284
    print "chmod u+rw", file
1285
    if not dry:
1286
        os.chmod(file, stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
1287
            | stat.S_ISUID | stat.S_IRUSR | stat.S_IWUSR)
1288
253 by mattgiuca
setup.py: chmods python-console when building.
1289
def action_chmod_x(file, dry):
371 by mattgiuca
setup.py: Fixed chmodding python-console. (Turns out this was a bug in setup,
1290
    """Chmod 755 a file (sets permissions to rwxr-xr-x)."""
1291
    print "chmod 755", file
253 by mattgiuca
setup.py: chmods python-console when building.
1292
    if not dry:
371 by mattgiuca
setup.py: Fixed chmodding python-console. (Turns out this was a bug in setup,
1293
        os.chmod(file, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR
1294
            | stat.S_IXGRP | stat.S_IRGRP | stat.S_IXOTH | stat.S_IROTH)
253 by mattgiuca
setup.py: chmods python-console when building.
1295
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
1296
def query_user(default, prompt):
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
1297
    """Prompts the user for a string, which is read from a line of stdin.
1298
    Exits silently if EOF is encountered. Returns the string, with spaces
1299
    removed from the beginning and end.
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
1300
1301
    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
1302
    """
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
1303
    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
1304
    try:
1305
        val = sys.stdin.readline()
1306
    except KeyboardInterrupt:
1307
        # Ctrl+C
1308
        sys.stdout.write("\n")
1309
        sys.exit(1)
1310
    sys.stdout.write("\n")
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
1311
    # If EOF, exit
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
1312
    if val == '': sys.exit(1)
113 by mattgiuca
setup.py: Now loads defaults, if possible, from the existing conf.py.
1313
    # If empty line, return default
1314
    val = val.strip()
1315
    if val == '': return default
1316
    return val
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
1317
114 by mattgiuca
setup.py: Wrote listmake (and ancillary functions).
1318
def filter_mutate(function, list):
1319
    """Like built-in filter, but mutates the given list instead of returning a
1320
    new one. Returns None."""
1321
    i = len(list)-1
1322
    while i >= 0:
1323
        # Delete elements which do not match
1324
        if not function(list[i]):
1325
            del list[i]
1326
        i -= 1
1327
746 by dcoles
Setup: During Build the system will now indicate what revision is being built
1328
def get_svn_revision():
1329
    """Returns either the current SVN revision of this build, or None"""
1330
    try:
1331
        svn = pysvn.Client()
1332
        entry = svn.info('.')
1333
        revnum = entry.revision.number
1334
    except pysvn.ClientError, e:
1335
        revnum = None
1336
    return revnum
1337
104 by mattgiuca
setup.py: Replaced the simple script with a full options processing script
1338
if __name__ == "__main__":
1339
    sys.exit(main())
746 by dcoles
Setup: During Build the system will now indicate what revision is being built
1340