From d02a1beb9e0bf341110b7c9cf535b34818df7510 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 5 Aug 2023 15:53:19 +0200 Subject: [PATCH] Added class Condition --- action.py | 14 ++++++++++++-- app.py | 4 ++-- entry.py | 6 +++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/action.py b/action.py index b41d50b..60e3d25 100644 --- a/action.py +++ b/action.py @@ -14,6 +14,16 @@ class Action(ABC): pass +class Condition(ABC): + def __init__(self, *args, **kwargs): + self.args = args + self.kwargs = kwargs + + @abc.abstractmethod + def execute(self, *args, **kwargs): + pass + + class LoggMessageAction(Action): def execute(self, *args, **kwargs): @@ -44,7 +54,7 @@ class CompressAction(Action): pass -class IsFileExistsAction(Action): +class IsFileExistsCondition(Condition): def execute(self, *args, **kwargs): path = self.kwargs.get('path') @@ -55,7 +65,7 @@ class IsFileExistsAction(Action): return os.path.exists(path) -class IsDirectoryEmptyAction(Action): +class IsDirectoryEmptyCondition(Condition): def execute(self, *args, **kwargs): path = self.kwargs.get('path') diff --git a/app.py b/app.py index a6fe865..0dc88b4 100644 --- a/app.py +++ b/app.py @@ -8,13 +8,13 @@ from logger import Logger class App: def __init__(self): - Logger.set_log_file('//testdata/log.txt') + Logger.set_log_file('testdata/log.txt') self._config = Config() def start(self): self._config.read_config() self._config.add_entry(Entry('myTest', - IsDirectoryEmptyAction(path='//emptydir', entry='myTest'), + IsDirectoryEmptyCondition(path='emptydir', entry='myTest'), LoggMessageAction('success', entry='myTest'), LoggMessageAction('fail', entry='myTest'))) diff --git a/entry.py b/entry.py index bec0e02..0581b17 100644 --- a/entry.py +++ b/entry.py @@ -1,11 +1,11 @@ -from action import Action +from action import Action, Condition class Entry: - def __init__(self, name: str, action: Action, success: Action, fail: Action): + def __init__(self, name: str, condition: Condition, success: Action, fail: Action): self._name = name - self._action = action + self._action = condition self._success = success self._fail = fail