scriptharness.actions module

The goals of modular actions are:
  • faster development feedback loops, and
  • different workflows for different usage requirements.
scriptharness.actions.LOGGER_NAME

str

logging.Logger name to use

scriptharness.actions.STRINGS

dict

strings for actions. In the future these may be in a function to allow for localization.

class scriptharness.actions.Action(name, action_groups=None, function=None, enabled=True)

Bases: object

Basic Action object.

name

str

This is the action name, for logging.

enabled

bool

Enabled actions will run. Disabled actions will log the skip_message and not run.

strings

dict

Strings for action-specific log messages.

logger_name

str

The logger name for logging calls inside this object.

function

function

This is the function to call in run_function().

history

dict

History of the action (return_value, status, start_time, end_time).

run(context)

Run the action.

This sets self.history timestamps and status.

Parameters:context (Context) – the context from the calling Script.
Returns:status – one of SUCCESS, ERROR, or FATAL.
Return type:int
Raises:scriptharness.exceptions.ScriptHarnessFatal – when the function raises ScriptHarnessFatal, run() re-raises.
run_function(context)

Run self.function. Called from run() for subclassing purposes.

This sets self.history[‘return_value’] for posterity.

Parameters:context (Context) – the context from the calling Script (passed from run()).
scriptharness.actions.get_function_by_name(function_name)

If function isn’t passed to Action, find the function with the same name

This searches in sys.modules[‘__main__’] and globals() for the function.

Parameters:function_name (str) – The name of the function to find.
Returns:the function found.
Return type:function
Raises:scriptharness.exceptions.ScriptHarnesException – if the function is not found or not callable.