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

« back to all changes in this revision

Viewing changes to setup/configure.py

Changed new-style config file to a hierarchical one with nice shiny new names.
Note that this will break the previous revision's config files. Hopefully you
didn't just put IVLE into production off this branch in the past 30 minutes !!

Upgraded both compatibility layers (setup/configure.py and conf.py) to use the
new format (they both now contain a dict mapping the legacy names to the new
path names).

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).
 
44
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',
 
67
}
 
68
 
40
69
class ConfigOption:
41
70
    """A configuration option; one of the things written to conf.py."""
42
71
    def __init__(self, option_name, default, prompt, comment, ask=True):
332
361
 
333
362
    conf.initial_comment = ["# IVLE Configuration File"]
334
363
 
335
 
    for opt in config_options:
336
 
        conf[opt.option_name] = globals()[opt.option_name]
337
 
        conf.comments[opt.option_name] = opt.comment.split('\n')
338
 
 
339
364
    # Add the forum secret to the config file (regenerated each config)
340
 
    conf['forum_secret'] = forum_secret
 
365
    config_options.append(ConfigOption('forum_secret', None, '', ''))
 
366
    globals()['forum_secret'] = forum_secret
 
367
 
 
368
    for legacyopt in config_options:
 
369
        newopt_path = CONFIG_OPTIONS[legacyopt.option_name].split('/')
 
370
        # Iterate over each segment of the path, and find the section in conf
 
371
        # file to insert the value into (use all but the last path segment)
 
372
        conf_section = conf
 
373
        for seg in newopt_path[:-1]:
 
374
            # Create the section if it isn't there
 
375
            if seg not in conf_section:
 
376
                conf_section[seg] = {}
 
377
            conf_section = conf_section[seg]
 
378
        # The final path segment names the key to insert into
 
379
        keyname = newopt_path[-1]
 
380
        value = globals()[legacyopt.option_name]
 
381
        if value is not None:
 
382
            conf_section[keyname] = value
 
383
            conf_section.comments[keyname] = legacyopt.comment.split('\n')
341
384
 
342
385
    conf.write()
343
386