commit a98f68357c20854bf94a1749b62aee62db0f922e Author: alex Date: Sun Sep 21 21:52:57 2025 +0200 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ecbfcaa --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +.venv \ No newline at end of file diff --git a/date_and_time.py b/date_and_time.py new file mode 100644 index 0000000..f14d6dc --- /dev/null +++ b/date_and_time.py @@ -0,0 +1,12 @@ +# Copyright (c) 20.09.25, 13:58. a.jurcenko@inproduct.de +import enum + + +class TimePeriod(enum.Enum): + ONETIME = 0 + DAY = 1 + WEEK = 2 + MONTH = 3 + QUARTER = 4 + YEAR = 5 + WEEKDAY = 6 diff --git a/date_time_event.py b/date_time_event.py new file mode 100644 index 0000000..9351dab --- /dev/null +++ b/date_time_event.py @@ -0,0 +1,3 @@ +# Copyright (c) 20.09.25, 15:06. a.jurcenko@inproduct.de + + diff --git a/events.py b/events.py new file mode 100644 index 0000000..fa9c41d --- /dev/null +++ b/events.py @@ -0,0 +1,64 @@ +# Copyright (c) 20.09.25, 15:06. a.jurcenko@inproduct.de +import abc +import datetime +import enum +import os + + +class EVENTPERIOD(enum.Enum): + ONETIME = 0 + CONTINUOUS = 1 + + +class Event(abc.ABC): + + def __init__(self, name, description, task, period): + self.name = name + self.description = description + self.task = task + self.period = period + self.active = True + self.counter = 0 + + @abc.abstractmethod + def check_conditions(self): + pass + + + +class TimeEvent(Event): + + def __init__(self, name=None, description=None, task=None, period=EVENTPERIOD.ONETIME, time=None): + super().__init__(name, description, task, period) + self.time = time + + def check_conditions(self): + if not self.active: + return + if datetime.datetime.now() > self.time: + self.task.execute() + self.counter += 1 + if self.period == EVENTPERIOD.ONETIME and self.counter > 0: + self.active = False + + +class SystemEvent(Event): + + def __init__(self, name=None, description=None, task=None, period=EVENTPERIOD.ONETIME, time=None): + super().__init__(name, description, task, period) + + def check_conditions(self): + pass + + +class DirectoryWatchEvent(SystemEvent): + def __init__(self, name=None, description=None, task=None, period=EVENTPERIOD.CONTINUOUS, directory=None): + super().__init__(name, description, task, period) + self.directory = directory + self.files_in_directory = os.listdir(self.directory) + + def check_conditions(self): + files = os.listdir(self.directory) + if sorted(files) != sorted(self.files_in_directory): + self.task.execute() + self.files_in_directory = os.listdir(self.directory) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6762084 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,52 @@ +anyio==4.8.0 +build==1.2.2.post1 +CacheControl==0.14.0 +certifi==2024.8.30 +cffi==1.16.0 +charset-normalizer==3.3.0 +cleo==2.1.0 +crashtest==0.4.1 +cryptography==41.0.4 +distlib==0.3.8 +dulwich==0.22.8 +et_xmlfile==2.0.0 +fastjsonschema==2.18.1 +filelock==3.16.1 +findpython==0.6.2 +h11==0.14.0 +httpcore==1.0.7 +httpx==0.28.1 +idna==3.4 +installer==0.7.0 +jaraco.classes==3.3.0 +jaraco.context==6.0.1 +jaraco.functools==4.1.0 +jeepney==0.8.0 +keyring==25.6.0 +more-itertools==10.1.0 +msgpack==1.0.7 +openpyxl==3.1.5 +pbs-installer==2025.2.12 +pipenv==2025.0.4 +pkginfo==1.12.0 +platformdirs==4.3.6 +poetry==2.1.4 +poetry-core==2.1.3 +pycparser==2.21 +pyproject_hooks==1.0.0 +PySide6==6.9.2 +PySide6_Addons==6.9.2 +PySide6_Essentials==6.9.2 +RapidFuzz==3.13.0 +requests==2.31.0 +requests-toolbelt==1.0.0 +SecretStorage==3.3.3 +shellingham==1.5.3 +shiboken6==6.9.2 +sniffio==1.3.1 +tomlkit==0.12.1 +trove-classifiers==2023.9.19 +typing_extensions==4.12.2 +urllib3==2.0.6 +virtualenv==20.32.0 +zstandard==0.23.0 diff --git a/task.py b/task.py new file mode 100644 index 0000000..96a209e --- /dev/null +++ b/task.py @@ -0,0 +1,86 @@ +# Copyright (c) 20.09.25, 14:01. a.jurcenko@inproduct.de +import abc +import subprocess +import requests + +class Task(abc.ABC): + + def __init__(self, name=None, description=None, destination=None, arguments=None, on_success=None, on_failure=None): + self._name = name + self._description = description + self._destination = destination + self._arguments = arguments + self._on_success = on_success + self._on_failure = on_failure + + + def get_name(self): + return self._name + + def get_description(self): + return self._description + + def get_destination(self): + return self._destination + + def get_arguments(self): + return self._arguments + + def get_on_success(self): + return self._on_success + + def get_on_failure(self): + return self._on_failure + + def set_name(self, name): + self._name = name + + def set_description(self, description): + self._description = description + + def set_destination(self, destination): + self._destination = destination + + def set_arguments(self, arguments): + self._arguments = arguments + + def set_on_success(self, on_success): + self._on_success = on_success + + def set_on_failure(self, on_failure): + self._on_failure = on_failure + + @abc.abstractmethod + def execute(self): + print(self._name) + + +class ConsolePrintTask(Task): + + def execute(self): + print(self._name, 'success') + +class SystemTask(Task): + + def execute(self): + super().execute() + res = subprocess.run([self._destination, self._arguments], text=True) + if res.returncode == 0: + if self._on_success is not None: + self._on_success() + else: + if self._on_failure is not None: + self._on_failure() + + +class GETTask(Task): + #todo: HTTP Task mit möglichkeit schema -> get/post/put/head auszusuchen + def execute(self): + super().execute() + res = requests.get(self._destination) + if res.status_code == 200: + if self._on_success is not None: + self._on_success() + else: + if self._on_failure is not None: + self._on_failure() \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..9716390 --- /dev/null +++ b/test.py @@ -0,0 +1,29 @@ +# Copyright (c) 20.09.25, 14:06. a.jurcenko@inproduct.de +import datetime +import time +from task import SystemTask, GETTask, ConsolePrintTask +from events import TimeEvent, DirectoryWatchEvent + +# +# t1 = SystemTask(name='test', destination="ls", arguments='-la') +# t1.execute() +# +# t2 = SystemTask(name='pip', destination="python3", arguments='-m pip', on_success=lambda: print('sehr gut'), on_failure=lambda: print('schlecht')) +# t2.execute() +# +# t3 = GETTask(name='get_inproduct', destination="http://google.de", on_success=lambda: print('sehr gut'), on_failure=lambda: print('schlecht')) +# +# +# t4 = GETTask(name='get_google', destination="https://google.de", on_success=t3.execute, on_failure=lambda: print('schlecht')) +# t4.execute() +# +# now = datetime.datetime.now() +# now = now + datetime.timedelta(minutes=1) +# te = TimeEvent('test_event', time=now, task=t1) +# +# while True: +# te.check_conditions() + +dwe = DirectoryWatchEvent(task=ConsolePrintTask(name='test'), directory='/home/alex/test') +while True: + dwe.check_conditions() \ No newline at end of file diff --git a/test_event.py b/test_event.py new file mode 100644 index 0000000..0ad63af --- /dev/null +++ b/test_event.py @@ -0,0 +1,18 @@ +# Copyright (c) 20.09.25, 16:22. a.jurcenko@inproduct.de +import unittest +from task import ConsolePrintTask +from events import DirectoryWatchEvent + + +class TestEvent(unittest.TestCase): + + + def setUp(self): + pass + def tearDown(self): + pass + + def test_task(self): + dwe = DirectoryWatchEvent(task=ConsolePrintTask(name='test'), directory='/home/alex/test') + while True: + dwe.check_conditions() \ No newline at end of file diff --git a/test_pyside.py b/test_pyside.py new file mode 100644 index 0000000..7754a12 --- /dev/null +++ b/test_pyside.py @@ -0,0 +1,24 @@ +# Copyright (c) 20.09.25, 13:56. a.jurcenko@inproduct.de + +import sys +from PySide6.QtUiTools import QUiLoader +from PySide6.QtWidgets import QApplication +from PySide6.QtCore import QFile, QIODevice + +if __name__ == "__main__": + app = QApplication(sys.argv) + + ui_file_name = "mainwindow.ui" + ui_file = QFile(ui_file_name) + if not ui_file.open(QIODevice.ReadOnly): + print(f"Cannot open {ui_file_name}: {ui_file.errorString()}") + sys.exit(-1) + loader = QUiLoader() + window = loader.load(ui_file) + ui_file.close() + if not window: + print(loader.errorString()) + sys.exit(-1) + window.show() + + sys.exit(app.exec())