command.endpoint

Defines base command class for all endpoint commands. Those having no children.

class lmi.scripts.common.command.endpoint.LmiEndPointCommand(*args, **kwargs)

Base class for any leaf command.

List of additional recognized properties:

CALLABLE : tuple
Associated function. Will be wrapped in LmiEndPointCommand.execute() method and will be accessible directly as a cmd.execute.dest property. It may be specified either as a string in form "<module_name>:<callable>" or as a reference to callable itself.
ARG_ARRAY_SUFFIX : str
String appended to every option parsed by docopt having list as an associated value. It defaults to empty string. This modification is applied before calling LmiEndPointCommand.verify_options() and LmiEndPointCommand.transform_options().
FORMATTER : callable
Default formatter factory for instances of given command. This factory accepts an output stream as the only parameter and returns an instance of Formatter.
Using metaclass:
meta.EndPointCommandMetaClass.
classmethod dest_pos_args_count()

Number of positional arguments the associated function takes from command. These arguments are created by the command alone – they do not belong to options in usage string. Function can take additional positional arguments that need to be covered by usage string.

Return type:integer
execute(*args, **kwargs)

Subclasses must override this method to pass given arguments to command library function. This function shall be specified in CALLABLE property.

formatter

Return instance of default formatter.

Return type:Formatter
formatter_factory()

Subclasses shall override this method to provide default formatter factory for printing output.

Returns:Subclass of basic formatter.
produce_output(data)

This method can be use to render and print results with default formatter.

Parameters:data – Is an object expected by the produce_output() method of formatter.
run(args)

Create options dictionary from input arguments, verify them, transform them, make positional and keyword arguments out of them and pass them to process_session().

Parameters:args (list) – List of command arguments.
Returns:Exit code of application.
Return type:integer
run_with_args(args, kwargs)

Process end-point arguments and exit.

Parameters:
  • args (list) – Positional arguments to pass to associated function in command library.
  • kwargs (dictionary) – Keyword arguments as a dictionary.
Returns:

Exit code of application.

Return type:

integer

transform_options(options)

This method can be overriden in subclasses if options shall be somehow modified before passing them associated function.

Note

Run after verify_options() method.

Parameters:options (dictionary) – Dictionary as returned by docopt parser.
verify_options(options)

This method can be overriden in subclasses to check, whether the options given on command line are valid. If any flaw is discovered, an LmiInvalidOptions exception shall be raised. Any returned value is ignored.

Note

This is run before transform_options() method.

Parameters:options (dictionary) – Dictionary as returned by docopt parser.
lmi.scripts.common.command.endpoint.opt_name_sanitize(opt_name)

Make a function parameter name out of option name. This replaces any character not suitable for python identificator with '_' and make the whole string lowercase.

Parameters:opt_name (string) – Option name.
Returns:Modified option name.
Return type:string
lmi.scripts.common.command.endpoint.options_dict2kwargs(options)

Convert option name from resulting docopt dictionary to a valid python identificator token used as function argument name.

Parameters:options (dictionary) – Dictionary returned by docopt call.
Returns:New dictionary with keys passable to function as argument names.
Return type:dictionary