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

« back to all changes in this revision

Viewing changes to setup/configure.py

configure.py: Replaced use of globals() dictionary for conf options with a
    dedicated dict for it, conf_options.

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
    'forum_secret': 'plugins/forum/secret',
67
67
}
68
68
 
 
69
# conf_options maps option names to values
 
70
conf_options = {}
 
71
 
69
72
class ConfigOption:
70
73
    """A configuration option; one of the things written to conf.py."""
71
74
    def __init__(self, option_name, default, prompt, comment, ask=True):
263
266
        confmodule = __import__("ivle/conf/conf")
264
267
        for opt in config_options:
265
268
            try:
266
 
                globals()[opt.option_name] = \
 
269
                conf_options[opt.option_name] = \
267
270
                confmodule.__dict__[opt.option_name]
268
271
            except:
269
 
                globals()[opt.option_name] = opt.default
 
272
                conf_options[opt.option_name] = opt.default
270
273
    except ImportError:
271
274
        # Just set reasonable defaults
272
275
        for opt in config_options:
273
 
            globals()[opt.option_name] = opt.default
 
276
            conf_options[opt.option_name] = opt.default
274
277
 
275
278
    # Set up some variables
276
279
    cwd = os.getcwd()
310
313
 
311
314
        for opt in config_options:
312
315
            if opt.ask:
313
 
                globals()[opt.option_name] = \
314
 
                    query_user(globals()[opt.option_name], opt.prompt)
 
316
                conf_options[opt.option_name] = \
 
317
                    query_user(conf_options[opt.option_name], opt.prompt)
315
318
    else:
316
319
        opts = dict(opts)
317
320
        # Non-interactive mode. Parse the options.
318
321
        for opt in config_options:
319
322
            if '--' + opt.option_name in opts:
320
 
                globals()[opt.option_name] = opts['--' + opt.option_name]
 
323
                conf_options[opt.option_name] = opts['--' + opt.option_name]
321
324
 
322
325
    # Error handling on input values
323
326
    try:
324
 
        allowed_uids_list = map(int, globals()['allowed_uids'].split(','))
 
327
        allowed_uids_list = map(int, conf_options['allowed_uids'].split(','))
325
328
    except ValueError:
326
329
        print >>sys.stderr, (
327
330
        "Invalid UID list (%s).\n"
328
331
        "Must be a comma-separated list of integers." %
329
 
            globals()['allowed_uids'])
 
332
            conf_options['allowed_uids'])
330
333
        return 1
331
334
    try:
332
 
        globals()['db_port'] = int(globals()['db_port'])
333
 
        if globals()['db_port'] < 0 or globals()['db_port'] >= 65536:
 
335
        conf_options['db_port'] = int(conf_options['db_port'])
 
336
        if conf_options['db_port'] < 0 or conf_options['db_port'] >= 65536:
334
337
            raise ValueError()
335
338
    except ValueError:
336
339
        print >>sys.stderr, (
338
341
        "Must be an integer between 0 and 65535." % repr(db_port))
339
342
        return 1
340
343
    try:
341
 
        globals()['usrmgt_port'] = int(globals()['usrmgt_port'])
342
 
        if globals()['usrmgt_port'] < 0 or globals()['usrmgt_port'] >= 65536:
 
344
        conf_options['usrmgt_port'] = int(conf_options['usrmgt_port'])
 
345
        if (conf_options['usrmgt_port'] < 0
 
346
            or conf_options['usrmgt_port'] >= 65536):
343
347
            raise ValueError()
344
348
    except ValueError:
345
349
        print >>sys.stderr, (
348
352
        return 1
349
353
 
350
354
    # By default we generate the magic randomly.
351
 
    if globals()['usrmgt_magic'] is None:
352
 
        globals()['usrmgt_magic'] = hashlib.md5(uuid.uuid4().bytes).hexdigest()
 
355
    if conf_options['usrmgt_magic'] is None:
 
356
        conf_options['usrmgt_magic'] = \
 
357
            hashlib.md5(uuid.uuid4().bytes).hexdigest()
353
358
 
354
359
    # Generate the forum secret
355
360
    forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
363
368
 
364
369
    # Add the forum secret to the config file (regenerated each config)
365
370
    config_options.append(ConfigOption('forum_secret', None, '', ''))
366
 
    globals()['forum_secret'] = forum_secret
 
371
    conf_options['forum_secret'] = forum_secret
367
372
 
368
373
    for legacyopt in config_options:
369
374
        newopt_path = CONFIG_OPTIONS[legacyopt.option_name].split('/')
377
382
            conf_section = conf_section[seg]
378
383
        # The final path segment names the key to insert into
379
384
        keyname = newopt_path[-1]
380
 
        value = globals()[legacyopt.option_name]
 
385
        value = conf_options[legacyopt.option_name]
381
386
        if value is not None:
382
387
            conf_section[keyname] = value
383
388
            conf_section.comments[keyname] = legacyopt.comment.split('\n')
393
398
    # XXX Compute jail_base, jail_src_base and jail_system. These will
394
399
    # ALSO be done by the boilerplate code, but we need them here in order
395
400
    # to write to the C file.
396
 
    jail_base = os.path.join(globals()['data_path'], 'jailmounts')
397
 
    jail_src_base = os.path.join(globals()['data_path'], 'jails')
 
401
    jail_base = os.path.join(conf_options['data_path'], 'jailmounts')
 
402
    jail_src_base = os.path.join(conf_options['data_path'], 'jails')
398
403
    jail_system = os.path.join(jail_src_base, '__base__')
399
404
 
400
405
    conf.write("""/* IVLE Configuration File
434
439
    conf = open(phpBBconffile, "w")
435
440
    
436
441
    # php-pg work around
437
 
    if globals()['db_host'] == 'localhost':
 
442
    if conf_options['db_host'] == 'localhost':
438
443
        forumdb_host = '127.0.0.1'
439
444
    else:
440
 
        forumdb_host = globals()['db_host']
 
445
        forumdb_host = conf_options['db_host']
441
446
 
442
447
    conf.write( """<?php
443
448
// phpBB 3.0.x auto-generated configuration file
444
449
// Do not change anything in this file!
445
450
$dbms = 'postgres';
446
451
$dbhost = '""" + forumdb_host + """';
447
 
$dbport = '""" + str(globals()['db_port']) + """';
448
 
$dbname = '""" + globals()['db_forumdbname'] + """';
449
 
$dbuser = '""" + globals()['db_user'] + """';
450
 
$dbpasswd = '""" + globals()['db_password'] + """';
 
452
$dbport = '""" + str(conf_options['db_port']) + """';
 
453
$dbname = '""" + conf_options['db_forumdbname'] + """';
 
454
$dbuser = '""" + conf_options['db_user'] + """';
 
455
$dbpasswd = '""" + conf_options['db_password'] + """';
451
456
 
452
457
$table_prefix = 'phpbb_';
453
458
$acm_type = 'file';