72
74
# ('/usr/local' for the usual install, '/usr' for distribution packages)""",
75
config_options.append(ConfigOption("python_site_packages_override",
77
config_options.append(ConfigOption("paths/site_packages",
77
79
"""site-packages directory in Python, where Python libraries are to be
78
80
installed. May be left as the default, in which case the value will be
79
81
computed from prefix and the current Python version:""",
81
83
# 'site-packages' directory in Python, where Python libraries are to be
82
# installed. May be None (recommended), in which case the value will be
84
# installed. May be omitted (recommended), in which case the value will be
83
85
# computed from prefix and the current Python version.""", ask=False))
85
config_options.append(ConfigOption("data_path",
87
config_options.append(ConfigOption("paths/data",
87
89
"In the local file system, where user-modifiable data files should be "
122
124
# used by the setup program to write to conf.h (see setup.py config).""",
125
config_options.append(ConfigOption("db_host", "localhost",
127
config_options.append(ConfigOption("database/host", "localhost",
126
128
"""PostgreSQL Database config
127
129
==========================
128
130
Hostname of the DB server:""",
130
### PostgreSQL Database config ###
131
132
# Database server hostname"""))
133
config_options.append(ConfigOption("db_port", "5432",
134
config_options.append(ConfigOption("database/port", "5432",
134
135
"""Port of the DB server:""",
136
137
# Database server port"""))
138
config_options.append(ConfigOption("db_dbname", "ivle",
139
config_options.append(ConfigOption("database/name", "ivle",
139
140
"""Database name:""",
141
142
# Database name"""))
143
config_options.append(ConfigOption("db_forumdbname", "ivle_forum",
144
config_options.append(ConfigOption("plugins/forum/dbname", "ivle_forum",
144
145
"""Forum Database name:""",
146
147
# Forum Database name"""))
148
config_options.append(ConfigOption("db_user", "postgres",
149
config_options.append(ConfigOption("database/username", "postgres",
149
150
"""Username for DB server login:""",
151
152
# Database username"""))
153
config_options.append(ConfigOption("db_password", "",
154
config_options.append(ConfigOption("database/password", "",
154
155
"""Password for DB server login:
155
156
(Caution: This password is stored in plaintext in ivle/conf/conf.py)""",
157
158
# Database password"""))
159
config_options.append(ConfigOption("auth_modules", "",
160
config_options.append(ConfigOption("auth/modules", "",
160
161
"""Authentication config
161
162
=====================
162
163
Comma-separated list of authentication modules.""",
195
196
# other modules may be plugged in to pulldown against organisation-specific
196
197
# pulldown backends.""", ask=False))
198
config_options.append(ConfigOption("svn_addr", "http://svn.localhost/",
199
config_options.append(ConfigOption("urls/svn_addr", "http://svn.localhost/",
199
200
"""Subversion config
200
201
=================
201
202
The base url for accessing subversion repositories:""",
203
204
# The base url for accessing subversion repositories."""))
205
config_options.append(ConfigOption("usrmgt_host", "localhost",
206
config_options.append(ConfigOption("usrmgt/host", "localhost",
206
207
"""User Management Server config
207
208
============================
208
209
The hostname where the usrmgt-server runs:""",
210
211
# The hostname where the usrmgt-server runs."""))
212
config_options.append(ConfigOption("usrmgt_port", "2178",
213
config_options.append(ConfigOption("usrmgt/port", "2178",
213
214
"""The port where the usrmgt-server runs:""",
215
216
# The port where the usrmgt-server runs.""", ask=False))
217
config_options.append(ConfigOption("usrmgt_magic", None,
218
config_options.append(ConfigOption("usrmgt/magic", None,
218
219
"""The password for the usrmgt-server:""",
220
221
# The password for the usrmgt-server.""", ask=False))
223
def query_user(default, prompt):
224
"""Prompts the user for a string, which is read from a line of stdin.
225
Exits silently if EOF is encountered. Returns the string, with spaces
226
removed from the beginning and end.
228
Returns default if a 0-length line (after spaces removed) was read.
231
# A default of None means the value will be computed specially, so we
232
# can't really tell you what it is
233
defaultstr = "computed"
234
elif isinstance(default, basestring):
235
defaultstr = '"%s"' % default
237
defaultstr = repr(default)
238
sys.stdout.write('%s\n (default: %s)\n>' % (prompt, defaultstr))
240
val = sys.stdin.readline()
241
except KeyboardInterrupt:
243
sys.stdout.write("\n")
245
sys.stdout.write("\n")
247
if val == '': sys.exit(1)
248
# If empty line, return default
250
if val == '': return default
222
253
def configure(args):
223
usage = """usage: %prog config [options]
224
Creates lib/conf/conf.py (and a few other config files).
225
Interactively asks questions to set this up."""
228
parser = optparse.OptionParser(usage)
229
(options, args) = parser.parse_args(args)
231
# Call the real function
232
return __configure(args)
234
def __configure(args):
235
global db_port, usrmgt_port
237
254
# Try importing existing conf, but if we can't just set up defaults
238
255
# The reason for this is that these settings are used by other phases
239
256
# of setup besides conf, so we need to know them.
240
257
# Also this allows you to hit Return to accept the existing value.
242
confmodule = __import__("ivle/conf/conf")
243
for opt in config_options:
245
globals()[opt.option_name] = \
246
confmodule.__dict__[opt.option_name]
248
globals()[opt.option_name] = opt.default
250
# Just set reasonable defaults
251
for opt in config_options:
252
globals()[opt.option_name] = opt.default
259
conf = ivle.config.Config()
260
except ivle.config.ConfigError:
261
# Couldn't find a config file anywhere.
262
# Create a new blank config object (not yet bound to a file)
263
# All lookups (below) will fail, so it will be initialised with all
264
# the default values.
265
conf = ivle.config.Config(blank=True)
267
# Check that all the options are present, and if not, load the default
268
for opt in config_options:
270
conf.get_by_path(opt.option_name)
272
# If the default is None, omit it
273
# Else ConfigObj will write the string 'None' to the conf file
274
if opt.default is not None:
275
conf.set_by_path(opt.option_name, opt.default)
277
# Store comments in the conf object
278
for opt in config_options:
279
# Omitted if the key doesn't exist
280
conf.set_by_path(opt.option_name, comment=opt.comment)
254
282
# Set up some variables
255
283
cwd = os.getcwd()
257
285
# the files that will be created/overwritten
258
conffile = os.path.join(cwd, "ivle/conf/conf.py")
259
jailconffile = os.path.join(cwd, "ivle/conf/jailconf.py")
286
conffile = os.path.join(cwd, "etc/ivle.conf")
260
287
conf_hfile = os.path.join(cwd, "bin/trampoline/conf.h")
261
288
phpBBconffile = os.path.join(cwd, "www/php/phpBB3/config.php")
292
318
for opt in config_options:
294
globals()[opt.option_name] = \
295
query_user(globals()[opt.option_name], opt.prompt)
320
conf.set_by_path(opt.option_name,
321
query_user(conf.get_by_path(opt.option_name), opt.prompt))
297
323
opts = dict(opts)
298
324
# Non-interactive mode. Parse the options.
299
325
for opt in config_options:
300
326
if '--' + opt.option_name in opts:
301
globals()[opt.option_name] = opts['--' + opt.option_name]
327
conf.set_by_path(opt.option_name,
328
opts['--' + opt.option_name])
303
330
# Error handling on input values
305
allowed_uids_list = map(int, allowed_uids.split(','))
332
allowed_uids_list = map(int,
333
conf['os']['allowed_uids'].split(','))
306
334
except ValueError:
307
335
print >>sys.stderr, (
308
336
"Invalid UID list (%s).\n"
309
"Must be a comma-separated list of integers." % allowed_uids)
337
"Must be a comma-separated list of integers." %
338
conf['os']['allowed_uids'])
312
db_port = int(db_port)
313
if db_port < 0 or db_port >= 65536: raise ValueError()
341
conf['database']['port'] = int(conf['database']['port'])
342
if (conf['database']['port'] < 0
343
or conf['database']['port'] >= 65536):
314
345
except ValueError:
315
346
print >>sys.stderr, (
316
347
"Invalid DB port (%s).\n"
317
"Must be an integer between 0 and 65535." % repr(db_port))
348
"Must be an integer between 0 and 65535." %
349
repr(conf['database']['port']))
320
usrmgt_port = int(usrmgt_port)
321
if usrmgt_port < 0 or usrmgt_port >= 65536: raise ValueError()
352
conf['usrmgt']['port'] = int(conf['usrmgt']['port'])
353
if (conf['usrmgt']['port'] < 0 or conf['usrmgt']['port'] >= 65536):
322
355
except ValueError:
323
356
print >>sys.stderr, (
324
357
"Invalid user management port (%s).\n"
325
"Must be an integer between 0 and 65535." % repr(usrmgt_port))
358
"Must be an integer between 0 and 65535." %
359
repr(conf['usrmgt']['port']))
328
362
# By default we generate the magic randomly.
329
if globals()['usrmgt_magic'] is None:
330
globals()['usrmgt_magic'] = hashlib.md5(uuid.uuid4().bytes).hexdigest()
364
conf['usrmgt']['magic'] # Throw away; just check for KeyError
366
conf['usrmgt']['magic'] = hashlib.md5(uuid.uuid4().bytes).hexdigest()
332
368
# Generate the forum secret
333
369
forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
335
# Write lib/conf/conf.py
338
conf = open(conffile, "w")
340
conf.write("""# IVLE Configuration File
342
# Miscellaneous application settings
347
for opt in config_options:
348
conf.write('%s\n%s = %r\n' % (opt.comment, opt.option_name,
349
globals()[opt.option_name]))
351
# Add the forum secret to the config file (regenerated each config)
352
conf.write('forum_secret = "%s"\n\n' % (forum_secret))
354
write_conf_file_boilerplate(conf)
357
except IOError, (errno, strerror):
358
print "IO error(%s): %s" % (errno, strerror)
371
# Write ./etc/ivle.conf (even if we loaded from a different filename)
372
conf.filename = conffile
374
conf.initial_comment = ["# IVLE Configuration File"]
376
# Add the forum secret to the config file (regenerated each config)
377
config_options.append(ConfigOption('plugins/forum/secret', None, '', ''))
378
conf['plugins']['forum']['secret'] = forum_secret
361
382
print "Successfully wrote %s" % conffile
363
# Write conf/jailconf.py
366
conf = open(jailconffile, "w")
368
# In the "in-jail" version of conf, we don't need MOST of the details
369
# (it would be a security risk to have them here).
370
# So we just write root_dir, and jail_base is "/".
371
# (jail_base being "/" means "jail-relative" paths are relative to "/"
372
# when inside the jail.)
373
conf.write("""# IVLE Configuration File
375
# Miscellaneous application settings
376
# (User jail version)
379
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
381
# eg. "/" or "/ivle".
384
# In the local file system, where are the student/user file spaces located.
385
# The user jails are expected to be located immediately in subdirectories of
389
# The hostname for serving publicly accessible pages
392
# The URL under which the Subversion repositories are located.
394
""" % (repr(root_dir),repr(public_host),repr(svn_addr)))
397
except IOError, (errno, strerror):
398
print "IO error(%s): %s" % (errno, strerror)
401
print "Successfully wrote %s" % jailconffile
403
384
# Write bin/trampoline/conf.h
406
conf = open(conf_hfile, "w")
408
# XXX Compute jail_base, jail_src_base and jail_system. These will
409
# ALSO be done by the boilerplate code, but we need them here in order
410
# to write to the C file.
411
jail_base = os.path.join(data_path, 'jailmounts')
412
jail_src_base = os.path.join(data_path, 'jails')
413
jail_system = os.path.join(jail_src_base, '__base__')
415
conf.write("""/* IVLE Configuration File
386
conf_h = open(conf_hfile, "w")
388
# XXX Compute jail_base, jail_src_base and jail_system. These will
389
# ALSO be done by the boilerplate code, but we need them here in order
390
# to write to the C file.
391
jail_base = os.path.join(conf['paths']['data'], 'jailmounts')
392
jail_src_base = os.path.join(conf['paths']['data'], 'jails')
393
jail_system = os.path.join(jail_src_base, '__base__')
395
conf_h.write("""/* IVLE Configuration File
417
397
* Administrator settings required by trampoline.
418
398
* Note: trampoline will have to be rebuilt in order for changes to this file
440
420
# However they should be the same with the exception of the outer
441
421
# characters, which are stripped off and replaced
444
except IOError, (errno, strerror):
445
print "IO error(%s): %s" % (errno, strerror)
448
425
print "Successfully wrote %s" % conf_hfile
450
427
# Write www/php/phpBB3/config.php
453
conf = open(phpBBconffile, "w")
456
if db_host == 'localhost':
457
forumdb_host = '127.0.0.1'
459
forumdb_host = db_host
429
conf_php = open(phpBBconffile, "w")
432
if conf['database']['host'] == 'localhost':
433
forumdb_host = '127.0.0.1'
435
forumdb_host = conf['database']['host']
437
conf_php.write( """<?php
462
438
// phpBB 3.0.x auto-generated configuration file
463
439
// Do not change anything in this file!
464
440
$dbms = 'postgres';
465
441
$dbhost = '""" + forumdb_host + """';
466
$dbport = '""" + str(db_port) + """';
467
$dbname = '""" + db_forumdbname + """';
468
$dbuser = '""" + db_user + """';
469
$dbpasswd = '""" + db_password + """';
442
$dbport = '""" + str(conf['database']['port']) + """';
443
$dbname = '""" + conf['plugins']['forum']['dbname'] + """';
444
$dbuser = '""" + conf['database']['username'] + """';
445
$dbpasswd = '""" + conf['database']['password'] + """';
471
447
$table_prefix = 'phpbb_';
472
448
$acm_type = 'file';
478
454
$forum_secret = '""" + forum_secret +"""';
482
except IOError, (errno, strerror):
483
print "IO error(%s): %s" % (errno, strerror)
486
459
print "Successfully wrote %s" % phpBBconffile
489
462
print "You may modify the configuration at any time by editing"
493
465
print phpBBconffile
498
def write_conf_file_boilerplate(conf_file):
500
### Below is boilerplate code, appended by ./setup.py config ###
502
# Path where architecture-dependent data (including non-user-executable
503
# binaries) is installed.
504
lib_path = os.path.join(prefix, 'lib/ivle')
506
# Path where arch-independent data is installed.
507
share_path = os.path.join(prefix, 'share/ivle')
509
# Path where user-executable binaries are installed.
510
bin_path = os.path.join(prefix, 'bin')
512
# 'site-packages' directory in Python, where Python libraries are to be
514
if python_site_packages_override is None:
515
PYTHON_VERSION = sys.version[0:3] # eg. "2.5"
516
python_site_packages = os.path.join(prefix,
517
'lib/python%s/site-packages' % PYTHON_VERSION)
519
python_site_packages = python_site_packages_override
521
# In the local file system, where the student/user jails will be mounted.
522
# Only a single copy of the jail's system components will be stored here -
523
# all user jails will be virtually mounted here.
524
jail_base = os.path.join(data_path, 'jailmounts')
526
# In the local file system, where are the student/user file spaces located.
527
# The user jails are expected to be located immediately in subdirectories of
528
# this location. Note that no complete jails reside here - only user
530
jail_src_base = os.path.join(data_path, 'jails')
532
# In the local file system, where the template system jail will be stored.
533
jail_system = os.path.join(jail_src_base, '__base__')
535
# In the local file system, where the subject content files are located.
536
# (The 'subjects' and 'exercises' directories).
537
content_path = os.path.join(data_path, 'content')
539
# In the local file system, where are the per-subject file spaces located.
540
# The individual subject directories are expected to be located immediately
541
# in subdirectories of this location.
542
subjects_base = os.path.join(content_path, 'subjects')
544
# In the local file system, where are the subject-independent exercise sheet
545
# file spaces located.
546
exercises_base = os.path.join(content_path, 'exercises')
548
# In the local file system, where the system notices are stored (such as terms
549
# of service and MOTD).
550
notices_path = os.path.join(data_path, 'notices')
552
# In the local file system, where is the Terms of Service document located.
553
tos_path = os.path.join(notices_path, 'tos.html')
555
# In the local file system, where is the Message of the Day document
556
# located. This is an HTML file (just the body fragment), which will
557
# be displayed on the login page. It is optional.
558
motd_path = os.path.join(notices_path, 'motd.html')
560
# The location of all the subversion config and repositories.
561
svn_path = os.path.join(data_path, 'svn')
563
# The location of the subversion configuration file used by
564
# apache to host the user repositories.
565
svn_conf = os.path.join(svn_path, 'svn.conf')
567
# The location of the subversion configuration file used by
568
# apache to host the user repositories.
569
svn_group_conf = os.path.join(svn_path, 'svn-group.conf')
571
# The root directory for the subversion repositories.
572
svn_repo_path = os.path.join(svn_path, 'repositories')
574
# The location of the password file used to authenticate users
575
# of the subversion repository from the ivle server.
576
svn_auth_ivle = os.path.join(svn_path, 'ivle.auth')
474
# Print the opening spiel including the GPL notice
476
print """IVLE - Informatics Virtual Learning Environment Setup
477
Copyright (C) 2007-2009 The University of Melbourne
478
IVLE comes with ABSOLUTELY NO WARRANTY.
479
This is free software, and you are welcome to redistribute it
480
under certain conditions. See LICENSE.txt for details.
485
return configure(argv[1:])
487
if __name__ == "__main__":