Mercurial > hg > configuration
changeset 23:73e72a764c3a
fix bool parser, i hope
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 26 Mar 2012 15:14:26 -0700 |
parents | f6c3f91af7f2 |
children | 39f2611db9be |
files | configuration/config.py tests/example.py |
diffstat | 2 files changed, 33 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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 = {}
--- 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},