35
36
from setup.util import query_user
40
# This dict maps legacy config option names to new config option paths
41
# ('section/option_name')
42
# NOTE: This is copied from ivle/conf/conf.py (because neither of these files
43
# can see each other).
45
'root_dir': 'urls/root',
46
'prefix': 'paths/prefix',
47
'data_path': 'paths/data',
48
'log_path': 'paths/logs',
49
'python_site_packages_override': 'paths/site_packages',
50
'public_host': 'urls/public_host',
51
'allowed_uids': 'os/allowed_uids',
52
'db_host': 'database/host',
53
'db_port': 'database/port',
54
'db_dbname': 'database/name',
55
'db_forumdbname': 'plugins/forum/dbname',
56
'db_user': 'database/username',
57
'db_password': 'database/password',
58
'auth_modules': 'auth/modules',
59
'ldap_url': 'auth/ldap_url',
60
'ldap_format_string': 'auth/ldap_format_string',
61
'subject_pulldown_modules': 'auth/subject_pulldown_modules',
62
'svn_addr': 'urls/svn_addr',
63
'usrmgt_host': 'usrmgt/host',
64
'usrmgt_port': 'usrmgt/port',
65
'usrmgt_magic': 'usrmgt/magic',
66
'forum_secret': 'plugins/forum/secret',
37
69
class ConfigOption:
38
70
"""A configuration option; one of the things written to conf.py."""
39
71
def __init__(self, option_name, default, prompt, comment, ask=True):
332
353
# Generate the forum secret
333
354
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)
356
# Write ./etc/ivle.conf
358
conf = configobj.ConfigObj()
359
conf.filename = conffile
361
conf.initial_comment = ["# IVLE Configuration File"]
363
# Add the forum secret to the config file (regenerated each config)
364
config_options.append(ConfigOption('forum_secret', None, '', ''))
365
globals()['forum_secret'] = forum_secret
367
for legacyopt in config_options:
368
newopt_path = CONFIG_OPTIONS[legacyopt.option_name].split('/')
369
# Iterate over each segment of the path, and find the section in conf
370
# file to insert the value into (use all but the last path segment)
372
for seg in newopt_path[:-1]:
373
# Create the section if it isn't there
374
if seg not in conf_section:
375
conf_section[seg] = {}
376
conf_section = conf_section[seg]
377
# The final path segment names the key to insert into
378
keyname = newopt_path[-1]
379
value = globals()[legacyopt.option_name]
380
if value is not None:
381
conf_section[keyname] = value
382
conf_section.comments[keyname] = legacyopt.comment.split('\n')
361
386
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
388
# 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
390
conf = open(conf_hfile, "w")
392
# XXX Compute jail_base, jail_src_base and jail_system. These will
393
# ALSO be done by the boilerplate code, but we need them here in order
394
# to write to the C file.
395
jail_base = os.path.join(data_path, 'jailmounts')
396
jail_src_base = os.path.join(data_path, 'jails')
397
jail_system = os.path.join(jail_src_base, '__base__')
399
conf.write("""/* IVLE Configuration File
417
401
* Administrator settings required by trampoline.
418
402
* Note: trampoline will have to be rebuilt in order for changes to this file
440
424
# However they should be the same with the exception of the outer
441
425
# characters, which are stripped off and replaced
444
except IOError, (errno, strerror):
445
print "IO error(%s): %s" % (errno, strerror)
448
429
print "Successfully wrote %s" % conf_hfile
450
431
# 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
433
conf = open(phpBBconffile, "w")
436
if db_host == 'localhost':
437
forumdb_host = '127.0.0.1'
439
forumdb_host = db_host
462
442
// phpBB 3.0.x auto-generated configuration file
463
443
// Do not change anything in this file!
464
444
$dbms = 'postgres';
478
458
$forum_secret = '""" + forum_secret +"""';
482
except IOError, (errno, strerror):
483
print "IO error(%s): %s" % (errno, strerror)
486
463
print "Successfully wrote %s" % phpBBconffile
489
466
print "You may modify the configuration at any time by editing"
493
469
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')