|
1
|
|
|
from synergine.core.exception.NotFoundError import NotFoundError |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class ActionManager(): |
|
5
|
|
|
""" |
|
6
|
|
|
Manaer of Action object |
|
7
|
|
|
""" |
|
8
|
|
|
|
|
9
|
|
|
def get_steps_for_actions(self, actions: list): |
|
10
|
|
|
""" |
|
11
|
|
|
Return a list of hierarchical list of action where an action is always |
|
12
|
|
|
placed in list after list containing his Action dependencies |
|
13
|
|
|
:param actions: list of Action |
|
14
|
|
|
:return: list of steps where step contain list of Event |
|
15
|
|
|
""" |
|
16
|
|
|
actions_copy = actions[:] |
|
17
|
|
|
steps = [[]] |
|
18
|
|
|
count = 0 |
|
19
|
|
|
for action in actions_copy: |
|
20
|
|
|
count += 1 |
|
21
|
|
|
if count > 10000: # TODO: hard code |
|
22
|
|
|
raise Exception("Impossible to find dependencies of action", actions) |
|
23
|
|
|
last_action = action |
|
24
|
|
|
action_dependencies = action.get_dependencies() |
|
25
|
|
|
if action_dependencies: |
|
26
|
|
|
try: |
|
27
|
|
|
step_index = self._get_step_index_for_dependencies(steps, action_dependencies) |
|
28
|
|
|
if step_index is not None: |
|
29
|
|
|
try: |
|
30
|
|
|
steps[step_index+1].append(action) |
|
31
|
|
|
except IndexError: |
|
32
|
|
|
steps.append([action]) |
|
33
|
|
|
else: |
|
34
|
|
|
step = [] |
|
35
|
|
|
step.extend(action_dependencies) |
|
36
|
|
|
steps.append(step) |
|
37
|
|
|
# Si une des dependences n'est pas encore dans les steps, on s'occupera de cette action plus tard |
|
38
|
|
|
except NotFoundError: |
|
39
|
|
|
# TODO: Prevoir le cas ou la dependance n'existera jamais dans la liste et lever une erreur |
|
40
|
|
|
actions_copy.append(action) |
|
41
|
|
|
else: |
|
42
|
|
|
steps[0].append(action) |
|
43
|
|
|
return steps |
|
44
|
|
|
|
|
45
|
|
|
def _get_step_index_for_dependencies(self, steps, dependencies): |
|
|
|
|
|
|
46
|
|
|
step_index_found = None |
|
47
|
|
|
for dependency in dependencies: |
|
48
|
|
|
step_index = self._get_step_index_for_dependency(steps, dependency) |
|
49
|
|
|
if step_index_found is None: |
|
50
|
|
|
step_index_found = step_index |
|
51
|
|
|
else: |
|
52
|
|
|
if step_index > step_index_found: |
|
53
|
|
|
step_index_found = step_index |
|
54
|
|
|
return step_index_found |
|
55
|
|
|
|
|
56
|
|
|
def _get_step_index_for_dependency(self, steps, dependency): |
|
57
|
|
|
for step_index, step_actions in enumerate(steps): |
|
58
|
|
|
for step_action in step_actions: |
|
59
|
|
|
if issubclass(step_action, dependency): |
|
60
|
|
|
return step_index |
|
61
|
|
|
raise NotFoundError() |
This check looks for invalid names for a range of different identifiers.
You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.
If your project includes a Pylint configuration file, the settings contained in that file take precedence.
To find out more about Pylint, please refer to their site.