Example #1
0
def parse_extra_strategy_args(args):
    """
    Turns a list of unknown arguments from the controller into a dictionary. This is
    necessary because the framework doesn't know what argument a strategy might
    require.

    This ONLY supports named arguments, and only supports the syntax '--name name', not
    --name=name.

    There are likely more graceful ways to do this, such as having Strategies know which
    of their properties are configurable and allowing them to register extra arguments,
    but this will do for now.

    TODO:
      - don't print messages from argparse here, just throw an exception or something.
      - the hackery here to support boolean flags (the nargs/const condition) means that
        if you don't give an value for an argument that should have one, no error is
        thrown, and that value is set to 'True'. In most cases this should be caught
        further down the line, but we really should handle it here.
    """

    settings = [x for x in args if x[:2] == '--']

    parser = argparse.ArgumentParser()

    for setting_name in settings:
        parser.add_argument(setting_name,
                            action='store',
                            nargs='?',
                            const=True)

    output = vars(
        parser.parse_args(args))  # Vars turns a Namespace into a dict.

    output = {
        k: configuration.parse_configurable_value(v)
        for k, v in output.items()
    }

    return output
Example #2
0
def get_command_line_configuration(known_args, extra_args):
    command_line_configuration = {
        'platform': {
            'strategy': known_args.strategy,
            'config_file': known_args.config_file,
            'builtin': known_args.builtin,
            'heartbeat': known_args.heartbeat,
            'sentry': known_args.sentry,
            'emerald': known_args.emerald,
            'audit': known_args.audit,
            'execute': known_args.execute,
        },
        'strategy': {
            'tick_sleep':
            configuration.parse_configurable_value(known_args.tick_sleep),
        },
    }

    extra_strategy_configuration = parse_extra_strategy_args(extra_args)

    command_line_configuration['strategy'].update(extra_strategy_configuration)

    return command_line_configuration
Example #3
0
    def test_configurable_value_string(self):
        value = 'tornado'

        output = configuration.parse_configurable_value(value)

        output.should.equal('tornado')
Example #4
0
    def test_configurable_value_money(self):
        value = 'BTC 0.1'

        output = configuration.parse_configurable_value(value)

        output.should.equal(Money('0.1', 'BTC'))
Example #5
0
    def test_configurable_value_bool_4(self):
        value = False

        output = configuration.parse_configurable_value(value)

        output.should.equal(False)
Example #6
0
    def test_configurable_value_bool_3(self):
        value = True

        output = configuration.parse_configurable_value(value)

        output.should.equal(True)
Example #7
0
    def test_configurable_value_number_2(self):
        value = '0'

        output = configuration.parse_configurable_value(value)

        output.should.equal(Decimal('0'))
Example #8
0
    def test_configurable_value_number(self):
        value = '133120102'

        output = configuration.parse_configurable_value(value)

        output.should.equal(Decimal('133120102'))
Example #9
0
    def test_configurable_value_bad_money(self):
        value = '1000 USD'

        output = configuration.parse_configurable_value(value)

        output.should.equal('1000 USD')