Package CedarBackup2 :: Module cli :: Class _ActionSet
[show private | hide private]
[frames | no frames]

Type _ActionSet

object --+
         |
        _ActionSet


Class representing a set of actions to be executed.

This class does three different things. First, it ensures that the actions specified on the command-line are sensible. The command-line can only list either built-in actions or extended actions specified in configuration. Also, certain actions (in NONCOMBINE_ACTIONS) cannot be combined with other actions.

Second, the class enforces an execution order on the specified actions. Any time actions are combined on the command line (either built-in actions or extended actions), we must make sure they get executed in a sensible order.

Third, the class ensures that any pre-action or post-action hooks are scheduled and executed appropriately. Hooks are configured by building a dictionary mapping between hook action name and command. Pre-action hooks are executed immediately before their associated action, and post-action hooks are executed immediately after their associated action.
Method Summary
  __init__(self, actions, extensions, hooks)
Constructor for the _ActionSet class.
  executeActions(self, configPath, options, config)
Executes all actions and extended actions, in the proper order.
  _buildActionMap(extensionNames, functionMap, indexMap, preHookMap, postHookMap)
Builds a mapping from action name to list of _ActionItem objects. (Static method)
  _buildActionSet(actions, actionMap)
Build set of actions to be executed. (Static method)
  _buildFunctionMap(extensions)
Builds a mapping from named action to action function. (Static method)
  _buildHookMaps(hooks)
Build two mappings from action name to configured ActionHook. (Static method)
  _buildIndexMap(extensions)
Builds a mapping from action name to proper execution index. (Static method)
  _deriveExtensionNames(extensions)
Builds a list of extended actions that are available in configuration. (Static method)
  _deriveHooks(action, preHookDict, postHookDict)
Derive pre- and post-action hooks, if any, associated with named action. (Static method)
  _validateActions(actions, extensionNames)
Validate that the set of specified actions is sensible. (Static method)
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Instance Method Details

__init__(self, actions, extensions, hooks)
(Constructor)

Constructor for the _ActionSet class.

This is kind of ugly, because the constructor has to set up a lot of data before being able to do anything useful. The following data structures are initialized based on the input:
  • extensionNames: List of extensions available in configuration
  • preHookMap: Mapping from action name to pre ActionHook
  • preHookMap: Mapping from action name to post ActionHook
  • functionMap: Mapping from action name to Python function
  • indexMap: Mapping from action name to execution index
  • actionMap: Mapping from action name to _ActionItem
Once these data structures are set up, the command line is validated to make sure only valid actions have been requested, and in a sensible combination. Then, all of the data is used to build self.actionSet, the set of _ActionItem object to be executed by executeActions().
Parameters:
actions - Names of actions specified on the command-line.
extensions - Extended action configuration (i.e. config.extensions)
hooks - List of pre- and post-action hooks (i.e. config.options.hooks)
Raises:
ValueError - If one of the specified actions is invalid.
ValueError -
Overrides:
__builtin__.object.__init__

executeActions(self, configPath, options, config)

Executes all actions and extended actions, in the proper order.

Each action (whether built-in or extension) is executed in an identical manner. The built-in actions will use only the options and config values. We also pass in the config path so that extension modules can re-parse configuration if they want to, to add in extra information.
Parameters:
configPath - Path to configuration file on disk.
options - Command-line options to be passed to action functions.
config - Parsed configuration to be passed to action functions.
Raises:
Exception - If there is a problem executing the actions.

Static Method Details

_buildActionMap(extensionNames, functionMap, indexMap, preHookMap, postHookMap)

Builds a mapping from action name to list of _ActionItem objects.

In most cases, the mapping from action name to _ActionItem is 1:1. The exception is the "all" action, which is a special case. However, a list is returned in all cases, just for consistency later.

Each _ActionItem will be created with a proper function reference and index value for execution ordering.
Parameters:
extensionNames - List of valid extended action names
functionMap - Dictionary mapping action name to Python function
indexMap - Dictionary mapping action name to integer execution index
preHookMap - Dictionary mapping action name to pre hooks (if any) for the action
postHookMap - Dictionary mapping action name to post hooks (if any) for the action
Returns:
Dictionary mapping action name to list of _ActionItem objects.

_buildActionSet(actions, actionMap)

Build set of actions to be executed.

The set of actions is built in the proper order, so executeActions can spin through the set without thinking about it. Since we've already validated that the set of actions is sensible, we don't take any precautions here to make sure things are combined properly. If the action is listed, it will be "scheduled" for execution.
Parameters:
actions - Names of actions specified on the command-line.
actionMap - Dictionary mapping action name to _ActionItem object.
Returns:
Set of action items in proper order.

_buildFunctionMap(extensions)

Builds a mapping from named action to action function.
Parameters:
extensions - Extended action configuration (i.e. config.extensions)
Returns:
Dictionary mapping action to function.

_buildHookMaps(hooks)

Build two mappings from action name to configured ActionHook.
Parameters:
hooks - List of pre- and post-action hooks (i.e. config.options.hooks)
Returns:
Tuple of (pre hook dictionary, post hook dictionary).

_buildIndexMap(extensions)

Builds a mapping from action name to proper execution index.

If extensions configuration is None, or there are no configured extended actions, the ordering dictionary will only include the built-in actions and their standard indices.

Otherwise, if the extensions order mode is None or "index", actions will scheduled by explicit index; and if the extensions order mode is "dependency", actions will be scheduled using a dependency graph.
Parameters:
extensions - Extended action configuration (i.e. config.extensions)
Returns:
Dictionary mapping action name to integer execution index.

_deriveExtensionNames(extensions)

Builds a list of extended actions that are available in configuration.
Parameters:
extensions - Extended action configuration (i.e. config.extensions)
Returns:
List of extended action names.

_deriveHooks(action, preHookDict, postHookDict)

Derive pre- and post-action hooks, if any, associated with named action.
Parameters:
action - Name of action to look up
preHookDict - Dictionary mapping pre-action hooks to action name
postHookDict - Dictionary mapping post-action hooks to action name @return Tuple (preHook, postHook) per mapping, with None values if there is no hook.

_validateActions(actions, extensionNames)

Validate that the set of specified actions is sensible.

Any specified action must either be a built-in action or must be among the extended actions defined in configuration. The actions from within NONCOMBINE_ACTIONS may not be combined with other actions.
Parameters:
actions - Names of actions specified on the command-line.
extensionNames - Names of extensions specified in configuration.
Raises:
ValueError - If one or more configured actions are not valid.

Generated by Epydoc 2.1 on Thu Mar 29 20:58:26 2007 http://epydoc.sf.net