separated Condition and Action
parent
d9ef99dcb1
commit
fd834500e0
|
|
@ -0,0 +1,48 @@
|
||||||
|
import os
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
|
from typing import Tuple, List
|
||||||
|
|
||||||
|
from logger import Logger
|
||||||
|
|
||||||
|
|
||||||
|
class Action(ABC):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.args = args
|
||||||
|
self.kwargs = kwargs
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def execute(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class LoggMessageAction(Action):
|
||||||
|
|
||||||
|
def execute(self, *args, **kwargs):
|
||||||
|
entry = self.kwargs.get('entry')
|
||||||
|
Logger.write_message(entry, self.args[0])
|
||||||
|
|
||||||
|
|
||||||
|
class StubAction(Action):
|
||||||
|
def execute(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ReadAction(Action):
|
||||||
|
|
||||||
|
def execute(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class MoveAction(Action):
|
||||||
|
|
||||||
|
def execute(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class CompressAction(Action):
|
||||||
|
|
||||||
|
def execute(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
2
app.py
2
app.py
|
|
@ -1,7 +1,7 @@
|
||||||
import os
|
import os
|
||||||
from config import Config
|
from config import Config
|
||||||
from entry import Entry
|
from entry import Entry
|
||||||
from action import *
|
from actions import *
|
||||||
from logger import Logger
|
from logger import Logger
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,7 @@
|
||||||
import abc
|
from abc import ABC, abstractmethod
|
||||||
import os
|
import os
|
||||||
from abc import ABC
|
|
||||||
from logger import Logger
|
from logger import Logger
|
||||||
|
from typing import Tuple, List
|
||||||
|
|
||||||
class Action(ABC):
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
self.args = args
|
|
||||||
self.kwargs = kwargs
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def execute(self, *args, **kwargs):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Condition(ABC):
|
class Condition(ABC):
|
||||||
|
|
@ -19,38 +9,8 @@ class Condition(ABC):
|
||||||
self.args = args
|
self.args = args
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abstractmethod
|
||||||
def execute(self, *args, **kwargs):
|
def execute(self, *args, **kwargs) -> Tuple[bool, List]:
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class LoggMessageAction(Action):
|
|
||||||
|
|
||||||
def execute(self, *args, **kwargs):
|
|
||||||
entry = self.kwargs.get('entry')
|
|
||||||
Logger.write_message(entry, self.args[0])
|
|
||||||
|
|
||||||
|
|
||||||
class StubAction(Action):
|
|
||||||
def execute(self, *args, **kwargs):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class ReadAction(Action):
|
|
||||||
|
|
||||||
def execute(self, *args, **kwargs):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class MoveAction(Action):
|
|
||||||
|
|
||||||
def execute(self, *args, **kwargs):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class CompressAction(Action):
|
|
||||||
|
|
||||||
def execute(self, *args, **kwargs):
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -77,4 +37,3 @@ class IsDirectoryEmptyCondition(Condition):
|
||||||
if files:
|
if files:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
from entry import Entry
|
from entry import Entry
|
||||||
|
from actions import *
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
|
@ -27,6 +28,7 @@ class Config:
|
||||||
splitts = line.split(';')
|
splitts = line.split(';')
|
||||||
assert(len(splitts) == 4)
|
assert(len(splitts) == 4)
|
||||||
name = splitts[0]
|
name = splitts[0]
|
||||||
action, act_param = splitts[1].strip().split(' ')
|
condition, con_param = splitts[1].strip().split(' ')
|
||||||
success, suc_param = splitts[2].strip().split(' ', 1)
|
success, suc_param = splitts[2].strip().split(' ', 1)
|
||||||
fail, fail_param = splitts[3].strip().split(' ', 1)
|
fail, fail_param = splitts[3].strip().split(' ', 1)
|
||||||
|
self._entries.append(Entry(name, condition(con_param), success(suc_param), fail(fail_param)))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue