Command and action models

Action

class katello.client.core.base.Action

Class implementing common functionality for CLI commands and actions

Variables:
  • parser – optparse.OptionParser instance
  • takes_options – bool flag that says whether the action has any options
  • opts – options returned from parsing command line
  • args – arguments returned from parsing command line
check_options(validator)

Add custom option requirements

Note :this method should be overridden to check for required options
error(error_msg)

Logs an error and prints it to stderr

get_option(opt_dest, default=None)

Get an option from opts or from the config file Options from opts take precedence.

Parameters:opt (str) – name of option to get
Returns:value of the option or None if the option is no present
has_option(opt)

Check if option is present

Parameters:opt (str) – name of option to check
Returns:True if the option was set, otherwise False
main(args, command_name=None, parent_usage=None)

Main execution of the action This method setups up the parser, parses the arguments, and calls run() in a try/except block, handling RestlibExceptions and general errors

Warning :this method should only be overridden with care
run()

Action’s functionality

Note :override this method to implement the actoin’s functionality
Raises NotImplementedError:
 if this method is not overridden
usage(command_name=None, parent_usage=None)

Usage string.

Return type:str
Returns:command’s usage string

BaseAction

class katello.client.core.base.BaseAction

Action class representing a single CLI action. All actions should inherit from this class. Inherits from Action.

Variables:Printer – printer.Printer instance

Command

class katello.client.core.base.Command

Represents a CLI command. It is a simple action with the ability to contain multiple subcommands and actions.

check_options(validator)

Add custom option requirements

Note :this method should be overridden to check for required options
error(error_msg)

Logs an error and prints it to stderr

get_option(opt_dest, default=None)

Get an option from opts or from the config file Options from opts take precedence.

Parameters:opt (str) – name of option to get
Returns:value of the option or None if the option is no present
has_option(opt)

Check if option is present

Parameters:opt (str) – name of option to check
Returns:True if the option was set, otherwise False
run()

Action’s functionality

Note :override this method to implement the actoin’s functionality
Raises NotImplementedError:
 if this method is not overridden
usage(command_name=None, parent_usage=None)

Usage string.

Return type:str
Returns:command’s usage string
add_command(name, command)

Add command or action

Parameters:
  • name (string) – a name undher which the command/action will be registered
  • command (Action|Command) –
get_command(name)
Raises Exception:
 if the command was not found
Returns:command or action registered under the given name
remove_command(name)
Parameters:name (string) – a name undher which the command/action is registered

Table Of Contents

Previous topic

Developing for the Katello Python Client

Next topic

Documenting the code

This Page