-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommand.py
61 lines (42 loc) · 1.65 KB
/
command.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
__author__ = "Ziyad Alsaeed"
__email__ = "[email protected]"
class Command(object):
def __init__(self):
raise NotImplementedError("The method should be implemented in the concrete class!")
def execute(self) -> bool:
raise NotImplementedError("The method should be implemented in the concrete class!")
def set_args(self, args: list):
raise NotImplementedError("The method should be implemented in the concrete class!")
def set_kwargs(self, kwargs: dict):
raise NotImplementedError("The method should be implemented in the concrete class!")
def get_result(self) -> (bool, str):
raise NotImplementedError("The method should be implemented in the concrete class!")
class PythonCommand(Command):
def __init__(self, task_to_perform, args=[], kwargs={}):
self.task = task_to_perform
self.args = args
self.kwargs = kwargs
self.result = None
def set_args(self, args: list):
self.args = args
def set_kwargs(self, kwargs: dict):
self.kwargs = kwargs
def execute(self):
"""
The goal is to call a method by reference,
see https://stackoverflow.com/a/706735/3504748
"""
self.result = self.task(*self.args, **self.kwargs)
def get_result(self) -> (bool, str):
return self.result
class BashCommand(Command):
def __init__(self, task_to_perform: str, pre_rq: str = None):
super().__init__()
self.task = task_to_perform
self.pre_rq = pre_rq
self.result = ""
self.executed = False
def execute(self) -> bool:
pass
def get_result(self) -> str:
pass