ScriptCommand (autotransform.command.script)

The implementation for the ScriptCommand.

class autotransform.command.script.ScriptCommand(*, run_pre_validation: bool = False, args: List[str], script: str, per_item: bool = False, run_on_changes: bool = False)

Bases: Command

Runs a script with the supplied arguments to perform a command. If the per_item flag is set, the script will be invoked on each Item. If run_on_changes is set to True, the script will replace the Batch Items with FileItems for each changed file. Sentinel values can be used in args to provide custom arguments for a run. The available sentinel values for args are:

<<KEY>>: A json encoded list of the Items for a Batch. If the per_item flag is set

this will simply be the key of an Item.

<<EXTRA_DATA>>: A JSON encoded mapping from Item key to that Item’s extra_data. If the

per_item flag is set, this will simply be a JSON encoding of the Item’s extra_data. If extra_data is not present for an item, it is treated as an empty Dict.

<<METADATA>>: A JSON encoded version of the Batch’s metadata.

_FILE can be appended to any of these (i.e. <<KEY_FILE>>) and the arg will instead be replaced

with a path to a file containing the value.

args

The arguments to supply to the script.

Type

List[str]

script

The script to run.

Type

str

per_item

Whether to run the script on each item. Defaults to False.

Type

bool, optional

run_on_changes

Whether to replace the Items in the batch with FileItems for the changed files. Defaults to False.

Type

bool, optional

run_pre_validation

Whether to run the command before validation is done. Defaults to False.

Type

bool, optional

name

The name of the Component.

Type

ClassVar[CommandName]

args: List[str]
name: ClassVar[CommandName] = 'script'
per_item: bool
run(batch: Batch, _transform_data: Optional[Mapping[str, Any]]) None

Runs the script command against the Batch, either on each item individually or on the entire Batch, based on the per_item flag.

Parameters
  • batch (Batch) – The transformed Batch to run against.

  • _transform_data (Optional[Mapping[str, Any]]) – Data from the transformation. Unused.

run_on_changes: bool
run_pre_validation: bool
script: str