From 88514af6f99c1d66e70a8fec9ccb2c88daa49b39 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sat, 14 Dec 2019 04:11:32 +0100 Subject: [PATCH] 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" + ]