# HG changeset patch # User Jeff Hammel # Date 1332800066 25200 # Node ID 73e72a764c3a7985bae9809b7530e0338db49cf5 # Parent f6c3f91af7f24d0376babf83c92052212d7f3b23 fix bool parser, i hope diff -r f6c3f91af7f2 -r 73e72a764c3a configuration/config.py --- a/configuration/config.py Mon Mar 26 14:51:44 2012 -0700 +++ b/configuration/config.py Mon Mar 26 15:14:26 2012 -0700 @@ -64,9 +64,23 @@ return args, kw def bool_cli(name, value): + + # preserve the default values + help = value.get('help') + flags = value.get('flags') + args, kw = base_cli(name, value) + kw['help'] = help # reset if value.get('default'): - pass # TODO + kw['action'] = 'store_false' + if not flags: + args = ['--no-%s' % name] + if not help: + kw['help'] = 'disable %s' % name + else: + kw['action'] = 'store_true' + if not help: + kw['help'] = 'enable %s' % name return args, kw def list_cli(name, value): @@ -79,9 +93,21 @@ kw['action'] = 'append' return args, kw -types = {bool: bool_cli, - list: list_cli, - None: base_cli} # default +def int_cli(name, value): + args, kw = base_cli(name, value) + kw['type'] = 'int' + return args, kw + +def float_cli(name, value): + args, kw = base_cli(name, value) + kw['type'] = 'float' + return args, kw + +types = {bool: bool_cli, + int: int_cli, + float: float_cli, + list: list_cli, + None: base_cli} # default class Configuration(object): options = {} diff -r f6c3f91af7f2 -r 73e72a764c3a tests/example.py --- a/tests/example.py Mon Mar 26 14:51:44 2012 -0700 +++ b/tests/example.py Mon Mar 26 15:14:26 2012 -0700 @@ -1,3 +1,5 @@ +#!/usr/bin/env python + from configuration import Configuration class ExampleConfiguration(Configuration): @@ -12,7 +14,7 @@ 'flags': ['-e', '--executablePath'], 'help': 'path to firefox'}, 'develop': {'help': "useful for running tests on a developer machine. Creates a local webserver and doesn't upload to the graph servers.", - 'type': bool} + 'type': bool}, 'test_timeout': {'type': int, 'help': "Time to wait for the browser to output to the log file", 'default': 1200},