action

Module for performing arbitrary actions on objects

A FileAction object is a collection of multiple ActionUnit. When executing the FileAction each ActionUnit is run. Later you can query or display the result.

class jukeboxcore.action.ActionStatus(value=None, msg='Not executed.', traceback='', returnvalue=None)[source]

Bases: object

A status object that holds a status value and a short description of what the status means.

So when an action is performed, the action status shows, if the action has been successful or failed and also shows why.

You can query and set 4 attributes:

value:the status value as a string
message:the status message as a string
traceback:in case of an error, the traceback as a string
returnvalue:If the action wants to provide some value for further processing.

Possible status values are ActionStatus.SUCCESS, ActionStatus.SKIPPED, ActionStatus.FAILURE, ActionStatus.ERROR and None. Before a action gets executed, the status is None

Initialize a new action status with the given value, message and traceback

Parameters:
  • value (str) – The status value
  • msg (str) – The status message. A better description of the status
  • traceback (str) – The traceback if an error occured during action execution.
  • returnvalue (None|object) – If the actions wants to return values, this can be used to store the return value
Raises:

None

SUCCESS = 'Success'

Status for when the action succeded

SKIPPED = 'Skipped'

Status for when the action has been skipped, because a dependency was not met

FAILURE = 'Failure'

Status for when the action failed in doing what it should. But the action did not raise an error. So it is like an error that the action expected.

ERROR = 'Error'

Status for when the action crashed and raised an error.

class jukeboxcore.action.ActionUnit(name, description, actionfunc, depsuccess=None, depfail=None)[source]

Bases: object

A single action to be performed on a object.

Actions might depend on others and only get executed when the dependency was successful. Other actions might depend on the failure of another action and only get executed when the dependency failed.

ActionUnit has the following data you can query:

name:the name of the action.
description:the description of what the action does.
status:the status of the action. A ActionStatus object.

Note

The given object must be ready to be processed. So if the object is a file, the file needs to be opened first, create an action that opens the file, and put it as dependency for all other actions. The same goes for closing or saving files.

Initialize a new action unit that can depends on the success of depsucess or the failure of depfail

Parameters:
  • name (str) – The name of the action
  • description (str) – A short description of what the action unit does
  • actionfunc (callable) – A function that takes an object as argument and performs a action. the function should return a ActionStatus object. Use the returnvalue attribute of the status, if you need to return something else.
  • depsuccess (list|None) – a list of action units that has to succeed first before this action can be executed
  • depfail (list|None) – a list of action units that has to fail first before this action can be executed
Raises:

None

run(obj)[source]

Execute the actions on the given object.

Parameters:obj (object) – The object that the action should process
Returns:None
Return type:None
Raises:None
class jukeboxcore.action.ActionCollection(actions)[source]

Bases: object

Perform a collection of ActionUnit on a object.

Actions get executed in the given order.

Note

The given object must be ready to be processed. So if the object is a file, the file needs to be opened first, create an action that opens the file, and put it as dependency for all other actions. The same goes for closing or saving files.

You can access the action objects with these attributes:

actions:a list of action units.

Initializes a FileAction object. The actions will be performed on a object when FileAction.execute() is called.

Parameters:actions (list) – a list of action units
Raises:None
execute(obj)[source]

Run all action units on the given object.

Parameters:obj – the object to be processed
Returns:None
Return type:None
Raises:None
status()[source]

The global status that summerizes all actions

The status will be calculated in the following order:

If any error occured, the status will be ActionStatus.ERROR. If any failure occured, the status will be ActionStatus.FAILURE. If all actions were successful or skipped, the status will be ActonStatus.SUCCESS
Returns:a status object that represents a summary of all actions
Return type:ActionStatus
Raises:None