Beispiel #1
0
 def setUp(self):
     self.args = TEST_ARGS[1:]
     model = yaml.safe_load(open(os.path.join(MODEL_DIR, 'service.yaml')))
     service_model = ServiceModel(model, 'servicename')
     service_operation = ServiceOperation(
         'submit-spark-job', 'dataeng', '',
         service_model.operation_model('submitSparkJob'))
     self.parser = ArgTableArgParser(service_operation.arg_table)
Beispiel #2
0
    def __call__(self, client_creator, args, parsed_globals):
        if args:
            subcommand_parser = ArgTableArgParser(
                {}, command_table=self.subcommand_table)
            parsed, remaining = subcommand_parser.parse_known_args(args)
            if getattr(parsed, 'subcommand', None) is not None:
                return self.subcommand_table[parsed.subcommand](remaining,
                                                                parsed_globals)

        generate_doc(self.GeneratorClass(self), self)
        self.renderer.render(self.doc.getvalue())
Beispiel #3
0
class TestArgTableArgParser(unittest.TestCase):
    def setUp(self):
        self.args = TEST_ARGS[1:]
        model = yaml.safe_load(open(os.path.join(MODEL_DIR, 'service.yaml')))
        service_model = ServiceModel(model, 'servicename')
        service_operation = ServiceOperation(
            'submit-spark-job', 'dataeng', '',
            service_model.operation_model('submitSparkJob'))
        self.parser = ArgTableArgParser(service_operation.arg_table)

    def testArsParsedCorrectly(self):
        parsed, remaining = self.parser.parse_known_args(self.args)
        self.assertEqual([], remaining)
        parsed_args = vars(parsed)
        # The second jar starts with a dash. We should decode it correctly.
        self.assertEquals(
            ['s3a://foobar/barfoo-1.0.jar', '-s3a://foobar/barfoo-1.0.jar'],
            parsed_args['jars'])
        self.assertEquals('com.foobarcorp.big_data_maker.SimpleApp',
                          parsed_args['main_class'])
        self.assertEquals('Cluster9', parsed_args['cluster_name'])
        # The following tests that we decoded the starting dash
        self.assertEquals([
            '-o', 's3a://foobar-demo/big.out/', '-p', '100', '-rfoo\\-bar\\-',
            '1000000'
        ], parsed_args['arguments'])
Beispiel #4
0
    def __call__(self, client_creator, args, parsed_globals):
        # args is the remaining unparsed args.
        # We might be able to parse these args so we need to create
        # an arg parser and parse them.
        self._subcommand_table = self._build_subcommand_table()
        self._arg_table = self._build_arg_table()
        self._handle_override_required_args(args)
        parser = ArgTableArgParser(self.arg_table,
                                   command_table=self.subcommand_table)
        parsed_args, remaining = parser.parse_known_args(args)

        # Unpack arguments
        for key, value in vars(parsed_args).items():
            cli_argument = None

            # Convert the name to use dashes instead of underscore
            # as these are how the parameters are stored in the
            # `arg_table`.
            xformed = key.replace('_', '-')
            if xformed in self.arg_table:
                cli_argument = self.arg_table[xformed]

            value = unpack_argument(cli_argument, value)

            # If this parameter has a schema defined, then allow plugins
            # a chance to process and override its value.
            if self._should_allow_override(cli_argument, value):
                # Unpack the argument, which is a string, into the
                # correct Python type (dict, list, etc)
                value = unpack_cli_arg(cli_argument, value)
                self._validate_value_against_schema(
                    cli_argument.argument_model, value)

            setattr(parsed_args, key, value)

        if hasattr(parsed_args, 'help'):
            self._display_help(client_creator, parsed_args, parsed_globals)
        elif getattr(parsed_args, 'subcommand', None) is None:
            # No subcommand was specified so call the main
            # function for this top level command.
            if remaining:
                raise ValueError("Unknown options: %s" % ','.join(remaining))
            return self._run_main(client_creator, parsed_args, parsed_globals)
        else:
            return self.subcommand_table[parsed_args.subcommand](
                client_creator, remaining, parsed_globals)
Beispiel #5
0
 def _create_operation_parser(self, arg_table):
     return ArgTableArgParser(arg_table,
                              service_name=self._parent_name,
                              operation_name=self._name)