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:
objectA 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.ERRORand None. Before a action gets executed, the status is NoneInitialize a new action status with the given value, message and traceback
Parameters: 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:
objectA 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 ActionStatusobject.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
depsucessor the failure ofdepfailParameters: - 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
ActionStatusobject. Use thereturnvalueattribute 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
- name (
-
class
jukeboxcore.action.ActionCollection(actions)[source]¶ Bases:
objectPerform a collection of
ActionUniton 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 beActionStatus.ERROR. If any failure occured, the status will beActionStatus.FAILURE. If all actions were successful or skipped, the status will beActonStatus.SUCCESSReturns: a status object that represents a summary of all actions Return type: ActionStatusRaises: None
-