-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (33 loc) · 1.33 KB
/
main.py
File metadata and controls
51 lines (33 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python
import yaml
import sys
from task import Task
from decision import Decision
class PlayBook():
def __init__(self, playbook_path):
with open(playbook_path, "r") as f:
self._pb = yaml.load(f.read())
self._step = self._pb["starttaskid"]
self._tasks = {}
for task_id in self._pb["tasks"]:
task_settings = self._pb["tasks"][task_id]["task"]
if self._pb["tasks"][task_id]["type"] == "task":
self._tasks[task_id] = Task(settings=task_settings)
elif self._pb["tasks"][task_id]["type"] == "condition":
self._tasks[task_id] = Decision(settings=task_settings)
def start(self, data={}):
c_step = self._step
while c_step:
active = self._tasks[c_step]
if active._type == "task":
data = active.execute(data=data)
c_step = self._pb["tasks"][c_step]["nextstep"]
elif active._type == "condition":
result = active.execute(data=data)
if result:
c_step = self._pb["tasks"][c_step]["task"]["if_true"]
else:
c_step = self._pb["tasks"][c_step]["task"]["if_false"]
if __name__ == "__main__":
t = PlayBook(sys.argv[1])
t.start(data={"isbn": "9789000035526"})