Coverage for src / mafw / enumerators.py: 100%
50 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-09 09:08 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-09 09:08 +0000
1# Copyright 2025 European Union
2# Author: Bulgheroni Antonio (antonio.bulgheroni@ec.europa.eu)
3# SPDX-License-Identifier: EUPL-1.2
4"""
5Module provides a set of enumerators for dealing with standard tasks.
6"""
8from __future__ import annotations
10from enum import Enum, IntEnum, StrEnum, auto
13class ProcessorExitStatus(IntEnum):
14 """The processor exit status enumerator class
16 * Successful: means that the processor reached the end with success
17 * Failed: means that the processor did not reach the end with success
18 * Aborted: means that the user aborted the processor execution
20 """
22 Successful = auto()
23 """The processor execution was successfully concluded"""
25 Failed = auto()
26 """The processor execution was failed"""
28 Aborted = auto()
29 """The processor execution was aborted by the user"""
32class ProcessorStatus(StrEnum):
33 """Enumerator to describe the status of a processor."""
35 Unknown = 'unknown'
36 """Unknown status"""
37 Init = 'initializing'
38 """Initialized"""
39 Start = 'starting'
40 """Started"""
41 Run = 'processing'
42 """Running"""
43 Finish = 'finishing'
44 """Finished"""
47class LoopingStatus(IntEnum):
48 """
49 Enumerator to modify the looping cycle.
51 In the case of a looping Processor, the user has the ability to slightly modify the looping structure using this
52 enumerator.
54 In the :meth:`~mafw.processor.Processor.process` the user can set the variable `looping_status` to one of the following values:
56 - :attr:`LoopingStatus.Continue`. It means that everything is working well and the loop cycle must go ahead as
57 foreseen and the :meth:`~mafw.processor.Processor.accept_item` will be invoked.
59 - :attr:`LoopingStatus.Skip`. The :meth:`~mafw.processor.Processor.skip_item` will be called soon after the
60 :meth:`~mafw.processor.Processor.process` is finished. The status will be reset to Continue and the next item will be processed.
62 - :attr:`LoopingStatus.Abort`. The cycle is broken immediately.
64 - :attr:`LoopingStatus.Quit`. The cycle is broken immediately.
66 The last two options are apparently identical, but they offer the possibility to implement a different behaviour
67 in the :meth:`~mafw.processor.Processor.finish` method. When abort is used, then the
68 :class:`~mafw.mafw_errors.AbortProcessorException` will be raised. For example, the user can decide to rollback
69 all changes if an abort as occurred or to save what done so far in case of a quit.
70 """
72 Continue = auto()
73 """The loop can continue"""
75 #: Skip this item.
76 Skip = auto()
78 #: Break the loop and force the outside container (:class:`mafw.processor.ProcessorList`) to quit.
79 Abort = auto()
81 #: Break the loop but let the outside container (:class:`mafw.processor.ProcessorList`) to continue.
82 Quit = auto()
85class LoopType(StrEnum):
86 """
87 The loop strategy for the processor.
89 Each processor can be executed in one of the following modes:
91 #. **Single mode.** The process method is executed only once.
93 #. **For loop mode.** The process method is executed inside a for loop after the start and before the finish. The
94 loop is based on a list of elements, the user **must** overload the :meth:`~mafw.processor.Processor.get_items`
95 method to define the list of items for the loop.
97 #. **While loop mode.** The process method is executed inside a while loop after the start and before the finish.
98 The user **must** overload the :meth:`~mafw.processor.Processor.while_condition` to define when to stop the loop.
100 .. admonition:: Future development
102 Implement concurrent loop. Depending on the development of the `free-threading capabilities
103 <https://docs.python.org/3/howto/free-threading-python.html>`_ of future python releases, this concurrent
104 looping strategy might be based on threads or a porting of the ``autorad`` multi-processor approach.
105 """
107 SingleLoop = 'single'
108 """Value for the single mode execution."""
110 ForLoop = 'for_loop'
111 """Value for the for loop on item list execution."""
113 WhileLoop = 'while_loop'
114 """Value for the while loop execution."""
117class LogicalOp(Enum):
118 """
119 Enumeration of supported logical operations.
121 .. versionadded:: v1.3.0
122 """
124 EQ = '==' # Equal
125 NE = '!=' # Not equal
126 LT = '<' # Less than
127 LE = '<=' # Less than or equal
128 GT = '>' # Greater than
129 GE = '>=' # Greater than or equal
130 GLOB = 'GLOB' # String pattern matching
131 LIKE = 'LIKE' # SQL LIKE pattern matching
132 REGEXP = 'REGEXP' # Regular expression matching
133 IN = 'IN' # Value in list
134 NOT_IN = 'NOT_IN' # Value not in list
135 BETWEEN = 'BETWEEN' # Value between two bounds
136 BIT_AND = 'BIT_AND' # Bitwise AND
137 BIT_OR = 'BIT_OR' # Bitwise OR
138 IS_NULL = 'IS_NULL' # Field is NULL
139 IS_NOT_NULL = 'IS_NOT_NULL' # Field is not NULL