-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #93: Use THEN to execute (execute action in device)
- Loading branch information
Showing
2 changed files
with
59 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,31 @@ | ||
from typing import List | ||
|
||
|
||
COMPLETE_CONDITION = 'complete' | ||
ACTION_STATUSES = ['failure', 'success'] | ||
ALL_COMPLETE_CONDITIONS = [COMPLETE_CONDITION] + ACTION_STATUSES | ||
|
||
|
||
class Action: | ||
def __init__(self, use, params=None, condition=None, template=None): | ||
self.use = use | ||
self.params = params | ||
self.condition = condition | ||
self.condition = condition.lower() if condition else condition | ||
self.template = template | ||
|
||
def is_first_run_action(self): | ||
return self.condition not in ALL_COMPLETE_CONDITIONS | ||
|
||
def evaluate_condition(self, value): | ||
return self.condition == value or (value in ACTION_STATUSES and self.condition == COMPLETE_CONDITION) | ||
|
||
|
||
class Actions: | ||
def __init__(self, actions): | ||
self._actions: List[Action] = [Action(**action) for action in actions] | ||
|
||
def get_first_run_actions(self): | ||
return filter(lambda x: x.is_first_run_action(), self._actions) | ||
|
||
def get_complete_actions(self): | ||
return filter(lambda x: not x.is_first_run_action(), self._actions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters