Skip to content

Task

dm.tasks.Task

Module providing the base task.

Task

The base class for tasks.

This class provides the basic functions shared by all tasks.

__init__(element, name)

Initializer.

Parameters:

Name Type Description Default
element _Element

The xml element instantiating the task.

required
name str

The name of the task.

required
basedir()

The base directory.

If an input file is used by the task, the base directory is the path to the input file.

Returns:

Type Description
str | None

The base directory of the task, or None if no input file is used.

checkAllowedAttributes(element, attributes)

Checks that only allowed attributes are provided.

Parameters:

Name Type Description Default
element _Element

The element defining a task.

required
attributes List[str]

The list of allowed attribute names.

required

Raises:

Type Description
TaskException

if the element defining a task contains attributes that are not allowed.

checkAllowedElements(element, elements)

Checks that only allowed child elements are provided.

Parameters:

Name Type Description Default
element _Element

The element defining a task.

required
elements List[str]

The list of allowed element names.

required

Raises:

Type Description
TaskException

if the element defining a task contains subelements that are not allowed.

checkInputDocument(required=False)

Checks a task's input document.

Parameters:

Name Type Description Default
required bool

Indicates that the input document is required.

False

Raises:

Type Description
TaskException

if the input document is required, but not provided

checkNumberOfElements(name, multiple, required)

Checks whether the correct number of child elements are provided.

Parameters:

Name Type Description Default
name str

The name of the child elements to check.

required
multiple bool

Indicates that the child element may be provided multiple times.

required
required bool

Indicates that the child element has to be provided at least once.

required

Raises:

Type Description
TaskException

if an incorrect number of child elements is provided.

checkOutputDocument(required=False)

Checks a task's output document.

Parameters:

Name Type Description Default
required bool

Indicates that the output document is required.

False

Raises:

Type Description
TaskException

if the output document is required, but not provided

getAttribute(attribute, required=False, default=None)

Get a task attribute.

Parameters:

Name Type Description Default
attribute str

The name of the attribute to retrieve.

required
required bool

Indicates that the attribute is required.

False
default str | None

The default value of the attribute.

None

Returns:

Type Description
str | None

The value of the attribute, if avaiable. Otherwise, the default value is returned.

Raises:

Type Description
TaskException

if the attribute is not defined, no default value has been provided, but the attribute is required.

getElement(name, required=False)

Get a task subelement.

Parameters:

Name Type Description Default
name str

The name of the subelement to retrieve.

required
required bool

Indicates that the subelement is required.

False

Returns:

Type Description
str | None

The value of the subelement, if avaiable. Otherwise, None will be returned.

Raises:

Type Description
TaskException

if the subelement is not defined, but the subelement is required.

getMultipleElements(name, required=False)

Get a task's subelements.

Parameters:

Name Type Description Default
name str

The name of the subelements to retrieve.

required
required bool

Indicates that the subelement is required.

False

Returns:

Type Description
List[str]

A list of the values of the subelements. Can be an empty list if no subelements are available.

Raises:

Type Description
TaskException

if the subelement is not defined, but the subelement is required.

load()

Loads the input document.

Raises:

Type Description
TaskException

if the input document can not be loaded.

save()

Saves the output document.

Raises:

Type Description
TaskException

if the output document can not be saved.