Skip to content

base_task

trestle.tasks.base_task ¤

Trestle tasks base templating.

Attributes¤

logger = logging.getLogger(__name__) module-attribute ¤

Classes¤

PassFail ¤

Bases: TaskBase

Holding pattern template for a task which does nothing and always passes.

Attributes:

Name Type Description
name

Name of the task.

Source code in trestle/tasks/base_task.py
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
class PassFail(TaskBase):
    """
    Holding pattern template for a task which does nothing and always passes.

    Attributes:
        name: Name of the task.
    """

    name = 'pass-fail'

    def __init__(self, config_object: Optional[configparser.SectionProxy]) -> None:
        """
        Initialize trestle task pass-fail.

        Attributes:
            config_object: Config section associated with the task.
        """
        super().__init__(config_object)

    def print_info(self) -> None:
        """Print the help string."""
        logger.info(f'Help information for {self.name} task.')
        logger.info('This is a template task which reports pass fail depending on the specific configuration.')
        logger.info(
            'In this case if no config section is provided the task will fail. This a a task specific behavior.'
        )
        logger.info('Configuration flags sit under [task.pass-fail]')
        logger.info('with two boolean flags')
        logger.info('execute_status = True/False with a default pass')
        logger.info('simulate_status = True/False with a default fail')
        logger.info('Note that if the config file does not have the appropriate section this should fail.')
        logger.info('The princple goal is a simple development example.')

    def simulate(self) -> TaskOutcome:
        """Provide a simulated outcome."""
        if self._config:
            outcome = self._config.getboolean('simulate_status', fallback=True)
            if outcome:
                return TaskOutcome('simulated-success')
        return TaskOutcome('simulated-failure')

    def execute(self) -> TaskOutcome:
        """Provide a actual outcome."""
        if self._config:
            outcome = self._config.getboolean('execute_status', fallback=True)
            if outcome:
                return TaskOutcome('success')
        return TaskOutcome('failure')
Attributes¤
name = 'pass-fail' class-attribute instance-attribute ¤
Functions¤
__init__(config_object) ¤

Initialize trestle task pass-fail.

Attributes:

Name Type Description
config_object

Config section associated with the task.

Source code in trestle/tasks/base_task.py
74
75
76
77
78
79
80
81
def __init__(self, config_object: Optional[configparser.SectionProxy]) -> None:
    """
    Initialize trestle task pass-fail.

    Attributes:
        config_object: Config section associated with the task.
    """
    super().__init__(config_object)
execute() ¤

Provide a actual outcome.

Source code in trestle/tasks/base_task.py
105
106
107
108
109
110
111
def execute(self) -> TaskOutcome:
    """Provide a actual outcome."""
    if self._config:
        outcome = self._config.getboolean('execute_status', fallback=True)
        if outcome:
            return TaskOutcome('success')
    return TaskOutcome('failure')
print_info() ¤

Print the help string.

Source code in trestle/tasks/base_task.py
83
84
85
86
87
88
89
90
91
92
93
94
95
def print_info(self) -> None:
    """Print the help string."""
    logger.info(f'Help information for {self.name} task.')
    logger.info('This is a template task which reports pass fail depending on the specific configuration.')
    logger.info(
        'In this case if no config section is provided the task will fail. This a a task specific behavior.'
    )
    logger.info('Configuration flags sit under [task.pass-fail]')
    logger.info('with two boolean flags')
    logger.info('execute_status = True/False with a default pass')
    logger.info('simulate_status = True/False with a default fail')
    logger.info('Note that if the config file does not have the appropriate section this should fail.')
    logger.info('The princple goal is a simple development example.')
simulate() ¤

Provide a simulated outcome.

Source code in trestle/tasks/base_task.py
 97
 98
 99
100
101
102
103
def simulate(self) -> TaskOutcome:
    """Provide a simulated outcome."""
    if self._config:
        outcome = self._config.getboolean('simulate_status', fallback=True)
        if outcome:
            return TaskOutcome('simulated-success')
    return TaskOutcome('simulated-failure')

TaskBase ¤

Bases: ABC

Abstract base class for tasks.

Attributes:

Name Type Description
name str

Name of the task.

Source code in trestle/tasks/base_task.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class TaskBase(ABC):
    """
    Abstract base class for tasks.

    Attributes:
        name: Name of the task.
    """

    name: str = 'base'

    def __init__(self, config_object: Optional[configparser.SectionProxy]) -> None:
        """Initialize task base and store config."""
        self._config = config_object

    @abstractmethod
    def print_info(self) -> None:
        """Print the help string."""

    @abstractmethod
    def execute(self) -> TaskOutcome:
        """Execute the task including potential rollback."""

    @abstractmethod
    def simulate(self) -> TaskOutcome:
        """Simulate the task and report task outcome."""
Attributes¤
name: str = 'base' class-attribute instance-attribute ¤
Functions¤
__init__(config_object) ¤

Initialize task base and store config.

Source code in trestle/tasks/base_task.py
47
48
49
def __init__(self, config_object: Optional[configparser.SectionProxy]) -> None:
    """Initialize task base and store config."""
    self._config = config_object
execute() abstractmethod ¤

Execute the task including potential rollback.

Source code in trestle/tasks/base_task.py
55
56
57
@abstractmethod
def execute(self) -> TaskOutcome:
    """Execute the task including potential rollback."""
print_info() abstractmethod ¤

Print the help string.

Source code in trestle/tasks/base_task.py
51
52
53
@abstractmethod
def print_info(self) -> None:
    """Print the help string."""
simulate() abstractmethod ¤

Simulate the task and report task outcome.

Source code in trestle/tasks/base_task.py
59
60
61
@abstractmethod
def simulate(self) -> TaskOutcome:
    """Simulate the task and report task outcome."""

TaskOutcome ¤

Bases: Enum

Enum describing possible task outcomes.

Source code in trestle/tasks/base_task.py
26
27
28
29
30
31
32
33
34
class TaskOutcome(Enum):
    """Enum describing possible task outcomes."""

    SUCCESS = 'success'
    FAILURE = 'failure'
    ROLLEDBACK = 'rolledback'
    SIM_SUCCESS = 'simulated-success'
    SIM_FAILURE = 'simulated-failure'
    NOT_IMPLEMENTED = 'not-implemented'
Attributes¤
FAILURE = 'failure' class-attribute instance-attribute ¤
NOT_IMPLEMENTED = 'not-implemented' class-attribute instance-attribute ¤
ROLLEDBACK = 'rolledback' class-attribute instance-attribute ¤
SIM_FAILURE = 'simulated-failure' class-attribute instance-attribute ¤
SIM_SUCCESS = 'simulated-success' class-attribute instance-attribute ¤
SUCCESS = 'success' class-attribute instance-attribute ¤

handler: python