From fd834500e02cd2230f62881717d6d222c74ac9f4 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 15 Aug 2023 14:52:37 +0200 Subject: [PATCH] separated Condition and Action --- actions.py | 48 +++++++++++++++++++++++++++++++++++++ app.py | 2 +- action.py => conditions.py | 49 ++++---------------------------------- config.py | 4 +++- entry.py | 2 +- 5 files changed, 57 insertions(+), 48 deletions(-) create mode 100644 actions.py rename action.py => conditions.py (52%) diff --git a/actions.py b/actions.py new file mode 100644 index 0000000..105badc --- /dev/null +++ b/actions.py @@ -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 + + + diff --git a/app.py b/app.py index 0dc88b4..be1e4b6 100644 --- a/app.py +++ b/app.py @@ -1,7 +1,7 @@ import os from config import Config from entry import Entry -from action import * +from actions import * from logger import Logger diff --git a/action.py b/conditions.py similarity index 52% rename from action.py rename to conditions.py index 60e3d25..a13b986 100644 --- a/action.py +++ b/conditions.py @@ -1,17 +1,7 @@ -import abc +from abc import ABC, abstractmethod import os -from abc import ABC from logger import Logger - - -class Action(ABC): - def __init__(self, *args, **kwargs): - self.args = args - self.kwargs = kwargs - - @abc.abstractmethod - def execute(self, *args, **kwargs): - pass +from typing import Tuple, List class Condition(ABC): @@ -19,38 +9,8 @@ class Condition(ABC): self.args = args self.kwargs = kwargs - @abc.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): + @abstractmethod + def execute(self, *args, **kwargs) -> Tuple[bool, List]: pass @@ -77,4 +37,3 @@ class IsDirectoryEmptyCondition(Condition): if files: return False return True - diff --git a/config.py b/config.py index 4825c2f..5662663 100644 --- a/config.py +++ b/config.py @@ -1,4 +1,5 @@ from entry import Entry +from actions import * class Config: @@ -27,6 +28,7 @@ class Config: splitts = line.split(';') assert(len(splitts) == 4) 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) fail, fail_param = splitts[3].strip().split(' ', 1) + self._entries.append(Entry(name, condition(con_param), success(suc_param), fail(fail_param))) diff --git a/entry.py b/entry.py index 0581b17..059f4cf 100644 --- a/entry.py +++ b/entry.py @@ -1,4 +1,4 @@ -from action import Action, Condition +from actions import Action, Condition class Entry: