avid.actions.pythonAction.PythonAction

class avid.actions.pythonAction.PythonAction(generateCallable, indicateCallable=None, additionalArgs=None, passOnlyURLs=True, defaultoutputextension='nrrd', outputReferenceArtefactName=None, actionTag='Python', alwaysDo=False, session=None, additionalActionProps=None, propInheritanceDict=None, **inputArgs)

Bases: SingleActionBase

Action that offers a generic wrapper around any python callable. The basic idea is to have a simple possibility to define action that execute a python script. The python script that should be executed must be passed as callable. The action will call the callable with the following arguments: 1. all unknown keyword arguments that are passed to the action (inputArgs). 2. **additionalArgs 3. an argument called “outputs”, that contain the result of self.indicateOutputs. For the input arguments the user of the action is free to use any keyword that is not reserved by the action and is not “outputs”. Additionally the action checks name collisions of inputArgs and additionalArgs and will raise an exception if needed.

Parameters:
  • generateCallable – A callable that will be called to generate the outputs. The action assumes that all outputs are generated and stored at their designated location.

  • indicateCallable – A callable that, if defined, will be called (like generateCallable) to query the outputs. The action assumes that the callable returns a list of output artefacts or None (if no indication can be made; like self.indicateOutputs). If this callable is not set, the default is one output that will be defined by the action and uses the first input artefact as reference. The signature of indicateCallable is: indicateCallable(actionInstance ( = Instance of the calling action), **allArgs (= all arguments passed to the action)

  • outputReferenceArtefactName – Name of the inputArgs that will be used as template when generating the output artefacts. If not set (None), the first input selection (in alphabetic order) will be used. If indicateCallable is set, this argument has only impact if the callable makes use of it.

  • additionalArgs – Dictionary containing all arguments that should be passed to generateCallable and are no artefact input arguments.

  • passOnlyURLs – If set to true only URLs of the artefacts, instead of the artefacts themselves, will be passed to generateCallable.

  • defaultoutputextension – Output extension that should be used if no indicateCallable is defined.

  • inputArgs – It is assumed that all unkown named arguments are inputs with artefact lists.

__init__(generateCallable, indicateCallable=None, additionalArgs=None, passOnlyURLs=True, defaultoutputextension='nrrd', outputReferenceArtefactName=None, actionTag='Python', alwaysDo=False, session=None, additionalActionProps=None, propInheritanceDict=None, **inputArgs)

init the action and setting the workflow session, the action is working in. @param session: Session object of the workflow the action is working in @param actionTag: Tag of the action within the session @param alwaysDo: Indicates if the action should generate its artefacts even if they already exist in the workflow (True) or if the action should skip the processing (False). @param additionalActionProps: Dictionary that can be used to define additional properties that should be added to any artefact that are produced by the action. Remark: properties defined here will always override the propInheritanceDict. @param propInheritanceDict: Dictionary that can be used to define if and who properties of the inputs are inherited to artefacts generated by SingelActionBase.generateArtefact(). The key of the dict defines the property for which a value is inherited. The value defines the input (key in self._inputArtefacts).

Methods

__init__(generateCallable[, ...])

init the action and setting the workflow session, the action is working in.

do()

Triggers the processing of an action instance.

do_finalize()

Function that has to be called after the data processing of an action processing to finalize the action state and do the bookkeeping (e.g. notifying the session, checking the validity and existence of the outputs).

do_processing()

Function that has to be called to do the data processing of an action processing.

do_setup()

Function that has to be called to prepare an action for the processing.

generateArtefact([reference, ...])

Helper method that can be used in derived action classes in their indicateOutputs() implementation.

indicateOutputs()

Return a list of artefact entries the action will produce if do_setup() is called.

Attributes

ACTION_FAILURE

Indicating the skipping of the (last) execution of an action.

ACTION_PENDING

Indicating that the action instance is currently generating the outputs.

ACTION_RUNNING

Indicating that the action instance is in an uninitialized state.

ACTION_SKIPPED

Indicating that the action instance was not executed so far.

ACTION_SUCCESS

Indicating the failure of the (last) execution of an action instance.

ACTION_UNINIT

OUTPUTS_ARGUMENT_NAME

actionInstanceUID

actionTag

action_tag_selector

has_warnings

instanceName

isFailure

isPending

isRunning

isSkipped

isSuccess

is_uninitialized

last_exec_state

last_warnings

outputArtefacts

ACTION_FAILURE = 'FAILURE'

Indicating the skipping of the (last) execution of an action. As any outputs the action instance would produce are available and still up to date.

ACTION_PENDING = 'PENDING'

Indicating that the action instance is currently generating the outputs.

ACTION_RUNNING = 'RUNNING'

Indicating that the action instance is in an uninitialized state.

ACTION_SKIPPED = 'SKIPPED'

Indicating that the action instance was not executed so far.

ACTION_SUCCESS = 'SUCCESS'

Indicating the failure of the (last) execution of an action instance.

do()

Triggers the processing of an action instance. This should be used as public trigger of an action. It is a convenient version that will trigger do_setup, do_process and do_finalize in the right way. Returns the action instance itself.

do_finalize()

Function that has to be called after the data processing of an action processing to finalize the action state and do the bookkeeping (e.g. notifying the session, checking the validity and existence of the outputs). After the call of the method the outputs of action instance are collected and verified. It is advised to use do(), which will use do_finalize() appropriately.

do_processing()

Function that has to be called to do the data processing of an action processing. After the call of the method the outputs of action instance are computed. It is advised to use do(), which will use do_processing() appropriately.

do_setup()

Function that has to be called to prepare an action for the processing. After the call of the method the action instance is able to process the data (if needed). The return value indicates of the instance can/needs to process (true) or not (false). It is advised to use do(), which will use do_setup() appropriately. After the call of this method, the instance will have one of the following states: (1) pending: expected state. Indicating that action should/needs to process and no waiting for triggering do_process() (2) skipped: indicated ouput data is already there and valid. No need for do_process, directly trigger do_finalize() (3) failed: indicated that the setup failed (e.g. because inputs are invalid). No need for do_process, directly trigger do_finalize()

generateArtefact(reference=None, copyAdditionalPropsFromReference=True, userDefinedProps=None, url_user_defined_part=None, url_extension=None, use_no_url_id=False)

Helper method that can be used in derived action classes in their indicateOutputs() implementation. The generation will be done in following steps: 1) It generates an artefact that has the actionTag of the current action. 2) Other properties will be taken from the reference (if given). 3) If a self._propInheritanceDict is specified it will be used to inherit property values. 4) self._additionalActionProps will be transferd. 5) the property values defined in userDefinedProps will be transfered. Remark: ActionTag will always be of this action. Remark: As default the URL will be None. If parameter url_user_defined_part or url_extension are not None, an artefact URL will be created. In this case the following pattern will be used: <artefact_path>[<url_user_defined_part>.]<artefact_id>[<><url_extension>] artefact_path: Return of artefactHelper.generateArtefactPath using the configured new artefact. url_user_defined_part: Parameter of the call artefact_id: ID of the new artefact extension_seperator: OS specific file extension seperator url_extension: Parameter of the call REMARK: Currently if self has a _propInheritanceDict specified, only the first artefact of the indicated input selection will be used to inherit the property. @param reference An other artefact as reference. If given, the following properties will be copied to the new artefact: Case, timepoint, type, format, objective. @param copyAdditionalPropsFromReference Indicates if also the additional properties should be transfered from the reference to the new artefact (only relevant of reference is not None). @param userDefinedProps Properties specified by the user that should be set for the new artefact. Parameter is a dictionary. The keys are the property ids and the dict values their value. Passing None indicates that there are no props @url_user_defined_part: specifies the humand readable prefix of the artefact url. If set a URL will be generated. @url_extension: specifies the file extension of the artefact url. If set a URL will be generated. @use_no_url_id Bool. If set to true, the unique id at the end of generated filenames will be removed, giving the user full control of the resulting filenames. WARNING: When using this option, the user has to take care themselves to avoid collisions between generated files.

indicateOutputs()

Return a list of artefact entries the action will produce if do_setup() is called. The method should return complete entries. Therefore, the entries should already contain the url where they will be stored if the action is executed. Remark: The output indication might not represent the final result of an action (e.g. because an action is not able to determine the outputs before they are actually generated.). This the list might only indicate the assumed outputs. Also An action can return None to signal that it cannot indicate the outputs before generation. :return: Either a list of indicated outputs or None.