71 lines
1.4 KiB
Python
71 lines
1.4 KiB
Python
import abc
|
|
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
|
|
|
|
|
|
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
|
|
|
|
|
|
class IsFileExistsAction(Action):
|
|
|
|
def execute(self, *args, **kwargs):
|
|
path = self.kwargs.get('path')
|
|
entry = self.kwargs.get('entry')
|
|
if not path:
|
|
Logger.write_error(entry, 'Need a path')
|
|
else:
|
|
return os.path.exists(path)
|
|
|
|
|
|
class IsDirectoryEmptyAction(Action):
|
|
|
|
def execute(self, *args, **kwargs):
|
|
path = self.kwargs.get('path')
|
|
entry = self.kwargs.get('entry')
|
|
if not path:
|
|
Logger.write_error(entry, 'Need a path')
|
|
else:
|
|
files = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))]
|
|
if files:
|
|
return False
|
|
return True
|
|
|