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

« back to all changes in this revision

Viewing changes to setup/configure.py

setup.configure: Replaced all of the config option names with the new path
    names (as used in ivle.conf).
    Still loads from conf.py, using the legacy names. A new dictionary maps
    new names to legacy names, so that we can look them up in the conf.py.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
import configobj
39
39
 
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).
 
40
# This dict maps new config option paths ('section/option_name') to legacy
 
41
# config option names ('option_name'). 
 
42
# NOTE: This is the inverse of the dictionary from ivle/conf/conf.py.
44
43
CONFIG_OPTIONS = {
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',
 
44
    'urls/root': 'root_dir',
 
45
    'paths/prefix': 'prefix',
 
46
    'paths/data': 'data_path',
 
47
    'paths/logs': 'log_path',
 
48
    'paths/site_packages': 'python_site_packages_override',
 
49
    'urls/public_host': 'public_host',
 
50
    'os/allowed_uids': 'allowed_uids',
 
51
    'database/host': 'db_host',
 
52
    'database/port': 'db_port',
 
53
    'database/name': 'db_dbname',
 
54
    'plugins/forum/dbname': 'db_forumdbname',
 
55
    'database/username': 'db_user',
 
56
    'database/password': 'db_password',
 
57
    'auth/modules': 'auth_modules',
 
58
    'auth/ldap_url': 'ldap_url',
 
59
    'auth/ldap_format_string': 'ldap_format_string',
 
60
    'auth/subject_pulldown_modules': 'subject_pulldown_modules',
 
61
    'urls/svn_addr': 'svn_addr',
 
62
    'usrmgt/host': 'usrmgt_host',
 
63
    'usrmgt/port': 'usrmgt_port',
 
64
    'usrmgt/magic': 'usrmgt_magic',
 
65
    'plugins/forum/secret': 'forum_secret',
67
66
}
68
67
 
69
68
# conf_options maps option names to values
91
90
# Configuration options, defaults and descriptions
92
91
config_options = []
93
92
 
94
 
config_options.append(ConfigOption("root_dir", "/",
 
93
config_options.append(ConfigOption("urls/root", "/",
95
94
    """Root directory where IVLE is located (in URL space):""",
96
95
    """
97
96
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
98
97
# with this).
99
98
# eg. "/" or "/ivle".""", ask=False))
100
99
 
101
 
config_options.append(ConfigOption("prefix", "/usr/local",
 
100
config_options.append(ConfigOption("paths/prefix", "/usr/local",
102
101
    """In the local file system, the prefix to the system directory where IVLE
103
102
is installed. (This should either be /usr or /usr/local):""",
104
103
    """
107
106
# ('/usr/local' for the usual install, '/usr' for distribution packages)""",
108
107
    ask=False))
109
108
 
110
 
config_options.append(ConfigOption("python_site_packages_override",
 
109
config_options.append(ConfigOption("paths/site_packages",
111
110
    None,
112
111
    """site-packages directory in Python, where Python libraries are to be
113
112
installed. May be left as the default, in which case the value will be
117
116
# installed. May be None (recommended), in which case the value will be
118
117
# computed from prefix and the current Python version.""", ask=False))
119
118
 
120
 
config_options.append(ConfigOption("data_path",
 
119
config_options.append(ConfigOption("paths/data",
121
120
    "/var/lib/ivle",
122
121
    "In the local file system, where user-modifiable data files should be "
123
122
    "located:",
125
124
# In the local file system, where user-modifiable data files should be
126
125
# located.""", ask=False))
127
126
 
128
 
config_options.append(ConfigOption("log_path",
 
127
config_options.append(ConfigOption("paths/logs",
129
128
    "/var/log/ivle",
130
129
    """Directory where IVLE log files are stored (on the local
131
130
file system). Note - this must be writable by the user the IVLE server 
134
133
# In the local file system, where IVLE error logs should be located.""",
135
134
    ask=False))
136
135
 
137
 
config_options.append(ConfigOption("public_host", "public.localhost",
 
136
config_options.append(ConfigOption("urls/public_host", "public.localhost",
138
137
    """Hostname which will cause the server to go into "public mode",
139
138
providing login-free access to student's published work:""",
140
139
    """
145
144
# Private mode (normal mode) requires login, and only serves files relevant to
146
145
# the logged-in user."""))
147
146
 
148
 
config_options.append(ConfigOption("allowed_uids", "33",
 
147
config_options.append(ConfigOption("os/allowed_uids", "33",
149
148
    """UID of the web server process which will run IVLE.
150
149
Only this user may execute the trampoline. May specify multiple users as
151
150
a comma-separated list.
157
156
# used by the setup program to write to conf.h (see setup.py config).""",
158
157
    ask=False))
159
158
 
160
 
config_options.append(ConfigOption("db_host", "localhost",
 
159
config_options.append(ConfigOption("database/host", "localhost",
161
160
    """PostgreSQL Database config
162
161
==========================
163
162
Hostname of the DB server:""",
164
163
    """
165
164
# Database server hostname"""))
166
165
 
167
 
config_options.append(ConfigOption("db_port", "5432",
 
166
config_options.append(ConfigOption("database/port", "5432",
168
167
    """Port of the DB server:""",
169
168
    """
170
169
# Database server port"""))
171
170
 
172
 
config_options.append(ConfigOption("db_dbname", "ivle",
 
171
config_options.append(ConfigOption("database/name", "ivle",
173
172
    """Database name:""",
174
173
    """
175
174
# Database name"""))
176
175
 
177
 
config_options.append(ConfigOption("db_forumdbname", "ivle_forum",
 
176
config_options.append(ConfigOption("plugins/forum/dbname", "ivle_forum",
178
177
    """Forum Database name:""",
179
178
    """
180
179
# Forum Database name"""))
181
180
 
182
 
config_options.append(ConfigOption("db_user", "postgres",
 
181
config_options.append(ConfigOption("database/username", "postgres",
183
182
    """Username for DB server login:""",
184
183
    """
185
184
# Database username"""))
186
185
 
187
 
config_options.append(ConfigOption("db_password", "",
 
186
config_options.append(ConfigOption("database/password", "",
188
187
    """Password for DB server login:
189
188
    (Caution: This password is stored in plaintext in ivle/conf/conf.py)""",
190
189
    """
191
190
# Database password"""))
192
191
 
193
 
config_options.append(ConfigOption("auth_modules", "",
 
192
config_options.append(ConfigOption("auth/modules", "",
194
193
    """Authentication config
195
194
=====================
196
195
Comma-separated list of authentication modules.""",
204
203
# other modules may be plugged in to auth against organisation-specific
205
204
# auth backends.""", ask=False))
206
205
 
207
 
config_options.append(ConfigOption("ldap_url", "ldaps://www.example.com",
 
206
config_options.append(ConfigOption("auth/ldap_url", "ldaps://www.example.com",
208
207
    """(LDAP options are only relevant if "ldap" is included in the list of
209
208
auth modules).
210
209
URL for LDAP authentication server:""",
211
210
    """
212
211
# URL for LDAP authentication server""", ask=False))
213
212
 
214
 
config_options.append(ConfigOption("ldap_format_string",
 
213
config_options.append(ConfigOption("auth/ldap_format_string",
215
214
    "uid=%s,ou=users,o=example",
216
215
    """Format string for LDAP auth request:
217
216
    (Must contain a single "%s" for the user's login name)""",
219
218
# Format string for LDAP auth request
220
219
# (Must contain a single "%s" for the user's login name)""", ask=False))
221
220
 
222
 
config_options.append(ConfigOption("subject_pulldown_modules", "",
 
221
config_options.append(ConfigOption("auth/subject_pulldown_modules", "",
223
222
    """Comma-separated list of subject pulldown modules.
224
223
Add proprietary modules to automatically enrol students in subjects.""",
225
224
    """
229
228
# other modules may be plugged in to pulldown against organisation-specific
230
229
# pulldown backends.""", ask=False))
231
230
 
232
 
config_options.append(ConfigOption("svn_addr", "http://svn.localhost/",
 
231
config_options.append(ConfigOption("urls/svn_addr", "http://svn.localhost/",
233
232
    """Subversion config
234
233
=================
235
234
The base url for accessing subversion repositories:""",
236
235
    """
237
236
# The base url for accessing subversion repositories."""))
238
237
 
239
 
config_options.append(ConfigOption("usrmgt_host", "localhost",
 
238
config_options.append(ConfigOption("usrmgt/host", "localhost",
240
239
    """User Management Server config
241
240
============================
242
241
The hostname where the usrmgt-server runs:""",
243
242
    """
244
243
# The hostname where the usrmgt-server runs."""))
245
244
 
246
 
config_options.append(ConfigOption("usrmgt_port", "2178",
 
245
config_options.append(ConfigOption("usrmgt/port", "2178",
247
246
    """The port where the usrmgt-server runs:""",
248
247
    """
249
248
# The port where the usrmgt-server runs.""", ask=False))
250
249
 
251
 
config_options.append(ConfigOption("usrmgt_magic", None,
 
250
config_options.append(ConfigOption("usrmgt/magic", None,
252
251
    """The password for the usrmgt-server:""",
253
252
    """
254
253
# The password for the usrmgt-server.""", ask=False))
267
266
        for opt in config_options:
268
267
            try:
269
268
                conf_options[opt.option_name] = \
270
 
                confmodule.__dict__[opt.option_name]
 
269
                    confmodule.__dict__[CONFIG_OPTIONS[opt.option_name]]
271
270
            except:
272
271
                conf_options[opt.option_name] = opt.default
273
272
    except ImportError:
324
323
 
325
324
    # Error handling on input values
326
325
    try:
327
 
        allowed_uids_list = map(int, conf_options['allowed_uids'].split(','))
 
326
        allowed_uids_list = map(int,
 
327
                                conf_options['os/allowed_uids'].split(','))
328
328
    except ValueError:
329
329
        print >>sys.stderr, (
330
330
        "Invalid UID list (%s).\n"
331
331
        "Must be a comma-separated list of integers." %
332
 
            conf_options['allowed_uids'])
 
332
            conf_options['os/allowed_uids'])
333
333
        return 1
334
334
    try:
335
 
        conf_options['db_port'] = int(conf_options['db_port'])
336
 
        if conf_options['db_port'] < 0 or conf_options['db_port'] >= 65536:
 
335
        conf_options['database/port'] = int(conf_options['database/port'])
 
336
        if (conf_options['database/port'] < 0
 
337
            or conf_options['database/port'] >= 65536):
337
338
            raise ValueError()
338
339
    except ValueError:
339
340
        print >>sys.stderr, (
340
341
        "Invalid DB port (%s).\n"
341
342
        "Must be an integer between 0 and 65535." %
342
 
            repr(conf_options['db_port']))
 
343
            repr(conf_options['database/port']))
343
344
        return 1
344
345
    try:
345
 
        conf_options['usrmgt_port'] = int(conf_options['usrmgt_port'])
346
 
        if (conf_options['usrmgt_port'] < 0
347
 
            or conf_options['usrmgt_port'] >= 65536):
 
346
        conf_options['usrmgt/port'] = int(conf_options['usrmgt/port'])
 
347
        if (conf_options['usrmgt/port'] < 0
 
348
            or conf_options['usrmgt/port'] >= 65536):
348
349
            raise ValueError()
349
350
    except ValueError:
350
351
        print >>sys.stderr, (
351
352
        "Invalid user management port (%s).\n"
352
353
        "Must be an integer between 0 and 65535." %
353
 
            repr(conf_options['usrmgt_port']))
 
354
            repr(conf_options['usrmgt/port']))
354
355
        return 1
355
356
 
356
357
    # By default we generate the magic randomly.
357
 
    if conf_options['usrmgt_magic'] is None:
358
 
        conf_options['usrmgt_magic'] = \
 
358
    if conf_options['usrmgt/magic'] is None:
 
359
        conf_options['usrmgt/magic'] = \
359
360
            hashlib.md5(uuid.uuid4().bytes).hexdigest()
360
361
 
361
362
    # Generate the forum secret
369
370
    conf.initial_comment = ["# IVLE Configuration File"]
370
371
 
371
372
    # Add the forum secret to the config file (regenerated each config)
372
 
    config_options.append(ConfigOption('forum_secret', None, '', ''))
373
 
    conf_options['forum_secret'] = forum_secret
 
373
    config_options.append(ConfigOption('plugins/forum/secret', None, '', ''))
 
374
    conf_options['plugins/forum/secret'] = forum_secret
374
375
 
375
 
    for legacyopt in config_options:
376
 
        newopt_path = CONFIG_OPTIONS[legacyopt.option_name].split('/')
 
376
    for opt in config_options:
 
377
        newopt_path = opt.option_name.split('/')
377
378
        # Iterate over each segment of the path, and find the section in conf
378
379
        # file to insert the value into (use all but the last path segment)
379
380
        conf_section = conf
384
385
            conf_section = conf_section[seg]
385
386
        # The final path segment names the key to insert into
386
387
        keyname = newopt_path[-1]
387
 
        value = conf_options[legacyopt.option_name]
 
388
        value = conf_options[opt.option_name]
388
389
        if value is not None:
389
390
            conf_section[keyname] = value
390
 
            conf_section.comments[keyname] = legacyopt.comment.split('\n')
 
391
            conf_section.comments[keyname] = opt.comment.split('\n')
391
392
 
392
393
    conf.write()
393
394
 
400
401
    # XXX Compute jail_base, jail_src_base and jail_system. These will
401
402
    # ALSO be done by the boilerplate code, but we need them here in order
402
403
    # to write to the C file.
403
 
    jail_base = os.path.join(conf_options['data_path'], 'jailmounts')
404
 
    jail_src_base = os.path.join(conf_options['data_path'], 'jails')
 
404
    jail_base = os.path.join(conf_options['paths/data'], 'jailmounts')
 
405
    jail_src_base = os.path.join(conf_options['paths/data'], 'jails')
405
406
    jail_system = os.path.join(jail_src_base, '__base__')
406
407
 
407
408
    conf.write("""/* IVLE Configuration File
441
442
    conf = open(phpBBconffile, "w")
442
443
    
443
444
    # php-pg work around
444
 
    if conf_options['db_host'] == 'localhost':
 
445
    if conf_options['database/host'] == 'localhost':
445
446
        forumdb_host = '127.0.0.1'
446
447
    else:
447
 
        forumdb_host = conf_options['db_host']
 
448
        forumdb_host = conf_options['database/host']
448
449
 
449
450
    conf.write( """<?php
450
451
// phpBB 3.0.x auto-generated configuration file
451
452
// Do not change anything in this file!
452
453
$dbms = 'postgres';
453
454
$dbhost = '""" + forumdb_host + """';
454
 
$dbport = '""" + str(conf_options['db_port']) + """';
455
 
$dbname = '""" + conf_options['db_forumdbname'] + """';
456
 
$dbuser = '""" + conf_options['db_user'] + """';
457
 
$dbpasswd = '""" + conf_options['db_password'] + """';
 
455
$dbport = '""" + str(conf_options['database/port']) + """';
 
456
$dbname = '""" + conf_options['plugins/forum/dbname'] + """';
 
457
$dbuser = '""" + conf_options['database/username'] + """';
 
458
$dbpasswd = '""" + conf_options['database/password'] + """';
458
459
 
459
460
$table_prefix = 'phpbb_';
460
461
$acm_type = 'file';