-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep.py
72 lines (64 loc) · 1.8 KB
/
step.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from .renderjob import RenderJob
from .exceptions import UserInvalidConfig
import logging
from functools import partial
from typing import Any, Callable
logger = logging.getLogger(__name__)
class Step(object):
methods = {}
required_params = {}
renderwatch = None
def __init__(
self,
action_keyword: str = None,
index: int = None,
step_type: str = None,
renderwatch = None,
trigger: str = None,
):
self.action_keyword = action_keyword
self.index = index
self.renderwatch = renderwatch
self.step_type = step_type
self.trigger = trigger
@classmethod
def action(self, action_keyword: str, *args, params: list = []):
def decorator(func):
instance = partial(
func,
self,
)
self._register_method(action_keyword, instance, params)
return instance
return decorator
@classmethod
def _register_method(
self,
action_keyword: str,
method: Callable[[str], Any],
params: list,
):
self.methods[action_keyword] = method
self.required_params[action_keyword] = params
@classmethod
def run(
self,
func,
*args,
callback_pre: Callable,
callback_post: Callable,
**kwargs,
):
callback_pre()
result = func(
self,
*args,
**kwargs,
)
callback_post()
return result
def get_method_from_keyword(self, action_keyword: str):
"""Sets the Step's `action` keyword and returns the method connected to it"""
if action_keyword in self.methods:
self.action_keyword = action_keyword
return self.methods[action_keyword]