23
23
# This is a command-line application, for use by the administrator.
24
# Prompts the administrator to enter machine-specific details and builds the
26
# (This file is not included with the distribution precisely because it
27
# contains machine-specific settings).
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
28
# setup.py conf [args]
29
# Configures IVLE with machine-specific details, most notably, various paths.
30
# Either prompts the administrator for these details or accepts them as
32
# Creates www/conf/conf.py and trampoline/conf.h.
35
# Compiles all files and sets up a jail template in the source directory.
37
# Compiles (GCC) trampoline/trampoline.c to trampoline/trampoline.
39
# Creates standard subdirs inside the jail, eg bin, opt, home, tmp.
40
# Copies console/ to a location within the jail.
41
# Copies OS programs and files to corresponding locations within the jail
42
# (eg. python and Python libs, ld.so, etc).
43
# Generates .pyc files for all the IVLE .py files.
45
# setup.py listmake (for developer use only)
46
# Recurses through the source tree and builds a list of all files which should
47
# be copied upon installation. This should be run by the developer before
48
# cutting a distribution, and the listfile it generates should be included in
49
# the distribution, avoiding the administrator having to run it.
51
# setup.py install [--nojail] [--dry|n]
53
# Create target install directory ($target).
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).
32
def query_user(prompt):
33
"""Prompts the user for a string, which is read from a line of stdin.
34
Exits silently if EOF is encountered. Returns the string, with spaces
35
removed from the beginning and end.
37
sys.stdout.write(prompt)
38
sys.stdout.write("\n>")
40
val = sys.stdin.readline()
41
except KeyboardInterrupt:
43
sys.stdout.write("\n")
45
sys.stdout.write("\n")
46
if val == '': sys.exit(1)
51
# Set up some variables
54
# the files that will be created/overwritten
55
conffile = os.path.join(cwd, "www/conf/conf.py")
56
conf_hfile = os.path.join(cwd, "trampoline/conf.h")
58
# Fixed config options that we don't ask the admin
62
# Print the opening spiel including the GPL notice
64
print """IVLE - Informatics Virtual Learning Environment Setup
64
# Main function skeleton from Guido van Rossum
65
# http://www.artima.com/weblogs/viewpost.jsp?thread=4829
67
class Usage(Exception):
68
def __init__(self, msg):
75
# Print the opening spiel including the GPL notice
77
print """IVLE - Informatics Virtual Learning Environment Setup
65
78
Copyright (C) 2007-2008 The University of Melbourne
66
79
IVLE comes with ABSOLUTELY NO WARRANTY.
67
80
This is free software, and you are welcome to redistribute it
68
81
under certain conditions. See LICENSE.txt for details.
72
This tool will create the following files:
86
# First argument is the name of the setup operation
90
# Print usage message and exit
94
# Call the requested operation's function
100
'listmake' : listmake,
102
}[operation](argv[2:])
104
print >>sys.stderr, (
105
"""Invalid operation '%s'. Try python setup.py help."""
110
opts, args = getopt.getopt(argv[1:], "h", ["help"])
111
except getopt.error, msg:
113
# more code, unchanged
115
print >>sys.stderr, err.msg
116
print >>sys.stderr, "for help use --help"
119
# Operation functions
123
print """Usage: python setup.py operation [args]
124
Operation (and args) can be:
128
install [--nojail] [-n|--dry]
132
print """Usage: python setup.py help [operation]"""
137
if operation == 'help':
138
print """python setup.py help [operation]
139
Prints the usage message or detailed help on an operation, then exits."""
140
elif operation == 'conf':
141
print """python setup.py conf [args]
142
Configures IVLE with machine-specific details, most notably, various paths.
143
Either prompts the administrator for these details or accepts them as
145
Creates www/conf/conf.py and trampoline/conf.h.
148
elif operation == 'build':
149
print """python setup.py build
150
Compiles all files and sets up a jail template in the source directory.
152
Compiles (GCC) trampoline/trampoline.c to trampoline/trampoline.
154
Creates standard subdirs inside the jail, eg bin, opt, home, tmp.
155
Copies console/ to a location within the jail.
156
Copies OS programs and files to corresponding locations within the jail
157
(eg. python and Python libs, ld.so, etc).
158
Generates .pyc files for all the IVLE .py files."""
159
elif operation == 'listmake':
160
print """python setup.py listmake
161
(For developer use only)
162
Recurses through the source tree and builds a list of all files which should
163
be copied upon installation. This should be run by the developer before
164
cutting a distribution, and the listfile it generates should be included in
165
the distribution, avoiding the administrator having to run it."""
166
elif operation == 'install':
167
print """sudo python setup.py install [--nojail] [--dry|-n]
169
Create target install directory ($target).
171
Copy trampoline/trampoline to $target/bin.
172
chown and chmod the installed trampoline.
173
Copy www/ to $target.
174
Copy jail/ to jails template directory (unless --nojail specified).
176
--nojail Do not copy the jail.
177
--dry | -n Print out the actions but don't do anything."""
179
print >>sys.stderr, (
180
"""Invalid operation '%s'. Try python setup.py help."""
185
# Set up some variables
188
# the files that will be created/overwritten
189
conffile = os.path.join(cwd, "www/conf/conf.py")
190
conf_hfile = os.path.join(cwd, "trampoline/conf.h")
192
# Fixed config options that we don't ask the admin
194
default_app = "dummy"
196
print """This tool will create the following files:
75
199
prompting you for details about your configuration. The file will be
78
202
Please hit Ctrl+C now if you do not wish to do this.
79
203
""" % (conffile, conf_hfile)
81
# Get information from the administrator
82
# If EOF is encountered at any time during the questioning, just exit silently
205
# Get information from the administrator
206
# If EOF is encountered at any time during the questioning, just exit
84
root_dir = query_user("""Root directory where IVLE is located (in URL space):
85
(eg. "/" or "/ivle")""")
86
ivle_install_dir = query_user('Root directory where IVLE is located (on the '
87
'local file system):\n'
88
'(eg. "/home/informatics/ivle")')
89
student_dir = query_user(
209
root_dir = query_user(
210
"""Root directory where IVLE is located (in URL space):
211
(eg. "/" or "/ivle")""")
212
ivle_install_dir = query_user(
213
'Root directory where IVLE is located (on the local file system):\n'
214
'(eg. "/home/informatics/ivle")')
215
student_dir = query_user(
90
216
"""Root directory where user files are stored (on the local file system):
91
(eg. "/home/informatics/jails")""")
96
conf = open(conffile, "w")
98
conf.write("""# IVLE Configuration File
217
(eg. "/home/informatics/jails")""")
219
# Write www/conf/conf.py
222
conf = open(conffile, "w")
224
conf.write("""# IVLE Configuration File
100
226
# Miscellaneous application settings
120
246
# presented with the login screen.
121
247
default_app = "%s"
122
248
""" % (root_dir, ivle_install_dir, student_dir, default_app))
125
except IOError, (errno, strerror):
126
print "IO error(%s): %s" % (errno, strerror)
129
print "Successfully wrote www/conf.py"
131
# Write trampoline/conf.h
134
conf = open(conf_hfile, "w")
136
conf.write("""/* IVLE Configuration File
251
except IOError, (errno, strerror):
252
print "IO error(%s): %s" % (errno, strerror)
255
print "Successfully wrote www/conf/conf.py"
257
# Write trampoline/conf.h
260
conf = open(conf_hfile, "w")
262
conf.write("""/* IVLE Configuration File
138
264
* Administrator settings required by trampoline.
139
265
* Note: trampoline will have to be rebuilt in order for changes to this file