From b1604cb19e24445c18bab83c47203c526b8753b1 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sat, 14 Dec 2019 04:10:33 +0100 Subject: [PATCH 1/6] Add pycharm project --- .idea/.gitignore | 2 ++ .idea/inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/linux-tools.iml | 8 ++++++++ .idea/misc.xml | 7 +++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ 6 files changed, 37 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/linux-tools.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..e7e9d11 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/linux-tools.iml b/.idea/linux-tools.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/linux-tools.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6649a8c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c0de9cb --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file From e82aad8aafc4c79ab318813aac65c940cfc70139 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sat, 14 Dec 2019 04:10:42 +0100 Subject: [PATCH 2/6] Add gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bee8a64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ From e1e3549e53b67dd569891e1bae7e7e394ebcf5e2 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sat, 14 Dec 2019 04:11:12 +0100 Subject: [PATCH 3/6] Create RealRunner and DebugRunner and Module Interface --- CommandRunner.py | 18 ++++++++++++++++++ IModule.py | 8 ++++++++ 2 files changed, 26 insertions(+) create mode 100644 CommandRunner.py create mode 100644 IModule.py diff --git a/CommandRunner.py b/CommandRunner.py new file mode 100644 index 0000000..aee3dff --- /dev/null +++ b/CommandRunner.py @@ -0,0 +1,18 @@ +class CommandRunner(object): + """docstring for CommandRunner.""" + + def __init__(self): + super(CommandRunner).__init__() + + def run(self, module): + print("REAL RUNNER") + print("Commands should be executed as subprocess.") + + +class CommandRunnerDebug(object): + def __init__(self): + super(CommandRunnerDebug).__init__() + + def run(self, module): + print("DEBUG RUNNER") + print(module.getCommand()) diff --git a/IModule.py b/IModule.py new file mode 100644 index 0000000..377854d --- /dev/null +++ b/IModule.py @@ -0,0 +1,8 @@ +class IModule(object): + """docstring for Module.""" + + def __init__(self): + super(IModule, self).__init__() + + def getCommand(self): + raise NotImplementedError From 88514af6f99c1d66e70a8fec9ccb2c88daa49b39 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sat, 14 Dec 2019 04:11:32 +0100 Subject: [PATCH 4/6] Create main file with sample module --- main.py | 25 +++++++++++++++++++++++++ modules/sample/__init__.py | 5 +++++ modules/sample/sampleModule.py | 14 ++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 modules/sample/__init__.py create mode 100644 modules/sample/sampleModule.py diff --git a/main.py b/main.py index e69de29..f82a4a1 100644 --- a/main.py +++ b/main.py @@ -0,0 +1,25 @@ +from CommandRunner import CommandRunner as Runner +import importlib +import os + + +def get_modules(): + modules = [] + for folder in os.listdir("./modules"): + print("Module found: " + folder) + curr_module = importlib.import_module('.' + folder, package="modules") + print("Try to load module: " + folder) + modules.append(curr_module.getModule()) + print("Module loaded successfully: " + folder) + return modules + + +print("Loading modules: \n") + +modules = get_modules() + +print("\nRunning all modules \n") + +cmdRunner = Runner() +for module in modules: + cmdRunner.run(module) diff --git a/modules/sample/__init__.py b/modules/sample/__init__.py new file mode 100644 index 0000000..80f166e --- /dev/null +++ b/modules/sample/__init__.py @@ -0,0 +1,5 @@ +from .sampleModule import SampleModule + + +def getModule(): + return SampleModule() diff --git a/modules/sample/sampleModule.py b/modules/sample/sampleModule.py new file mode 100644 index 0000000..8b45a5d --- /dev/null +++ b/modules/sample/sampleModule.py @@ -0,0 +1,14 @@ +from IModule import IModule + + +class SampleModule(IModule): + """docstring for SampleModule.""" + + def __init__(self): + super(SampleModule, self).__init__() + + def getCommand(self): + return [ + "command 1", + "command 2" + ] From 03005113b2bf53b6273c25a84c31f2a12c27fdc4 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sat, 14 Dec 2019 04:13:35 +0100 Subject: [PATCH 5/6] Skip sample module --- main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.py b/main.py index f82a4a1..d9f4ae3 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,10 @@ import os def get_modules(): modules = [] for folder in os.listdir("./modules"): + #skipping sample module + if folder == "sample": + continue + print("Module found: " + folder) curr_module = importlib.import_module('.' + folder, package="modules") print("Try to load module: " + folder) From e8197d5cea6c7ce477107f73600eb91bbdda9542 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sat, 14 Dec 2019 04:26:02 +0100 Subject: [PATCH 6/6] Renaming of functions Autoformatting --- CommandRunner.py | 2 +- IModule.py | 2 +- main.py | 10 +++++----- modules/sample/__init__.py | 2 +- modules/sample/sampleModule.py | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CommandRunner.py b/CommandRunner.py index aee3dff..8249941 100644 --- a/CommandRunner.py +++ b/CommandRunner.py @@ -15,4 +15,4 @@ class CommandRunnerDebug(object): def run(self, module): print("DEBUG RUNNER") - print(module.getCommand()) + print(module.get_command()) diff --git a/IModule.py b/IModule.py index 377854d..bdc3bbb 100644 --- a/IModule.py +++ b/IModule.py @@ -4,5 +4,5 @@ class IModule(object): def __init__(self): super(IModule, self).__init__() - def getCommand(self): + def get_command(self): raise NotImplementedError diff --git a/main.py b/main.py index d9f4ae3..3b30b96 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,4 @@ -from CommandRunner import CommandRunner as Runner +from CommandRunner import CommandRunnerDebug as Runner import importlib import os @@ -6,14 +6,14 @@ import os def get_modules(): modules = [] for folder in os.listdir("./modules"): - #skipping sample module + # skipping sample module if folder == "sample": - continue - + continue + print("Module found: " + folder) curr_module = importlib.import_module('.' + folder, package="modules") print("Try to load module: " + folder) - modules.append(curr_module.getModule()) + modules.append(curr_module.get_module()) print("Module loaded successfully: " + folder) return modules diff --git a/modules/sample/__init__.py b/modules/sample/__init__.py index 80f166e..c1980aa 100644 --- a/modules/sample/__init__.py +++ b/modules/sample/__init__.py @@ -1,5 +1,5 @@ from .sampleModule import SampleModule -def getModule(): +def get_module(): return SampleModule() diff --git a/modules/sample/sampleModule.py b/modules/sample/sampleModule.py index 8b45a5d..5fdd363 100644 --- a/modules/sample/sampleModule.py +++ b/modules/sample/sampleModule.py @@ -7,7 +7,7 @@ class SampleModule(IModule): def __init__(self): super(SampleModule, self).__init__() - def getCommand(self): + def get_command(self): return [ "command 1", "command 2"