diff --git a/AbstractModule.py b/AbstractModule.py new file mode 100644 index 0000000..4dbdbf0 --- /dev/null +++ b/AbstractModule.py @@ -0,0 +1,12 @@ +from abc import ABC, abstractmethod + + +class AbstractModule(ABC): + """docstring for Module.""" + + def __init__(self): + super(AbstractModule, self).__init__() + + @abstractmethod + def run(self): + pass diff --git a/CommandRunner.py b/CommandRunner.py deleted file mode 100644 index 8249941..0000000 --- a/CommandRunner.py +++ /dev/null @@ -1,18 +0,0 @@ -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.get_command()) diff --git a/IModule.py b/IModule.py deleted file mode 100644 index bdc3bbb..0000000 --- a/IModule.py +++ /dev/null @@ -1,8 +0,0 @@ -class IModule(object): - """docstring for Module.""" - - def __init__(self): - super(IModule, self).__init__() - - def get_command(self): - raise NotImplementedError diff --git a/main.py b/main.py index 3937e18..9f8f1dd 100644 --- a/main.py +++ b/main.py @@ -1,29 +1,48 @@ -from CommandRunner import CommandRunnerDebug as Runner +from PyInquirer import prompt import importlib import os -def get_modules(): - modules = [] - for folder in os.listdir("./modules"): - # skipping sample module - if folder == "sample": - continue +def transform_list_into_choices(choices_list): + mapped_list = [] + for choice in choices_list: + mapped_list.append({ + "name": choice + }) + return mapped_list - print("Module found: " + folder) - curr_module = importlib.import_module('.' + folder, package="modules") - print("Try to load module: " + folder) - modules.append(curr_module.get_module()) - print("Module loaded successfully: " + folder) + +def load_modules(): + print("Loading modules") + modules = {} + for folder in os.listdir("./modules"): + try: + curr_module = importlib.import_module('.' + folder, package="modules") + modules[folder] = curr_module.get_module() + except AttributeError: + pass + print("Modules loaded successfully.\n") return modules -print("Loading modules: \n") +def open_module_selection(modules): + print("Available Modules:") + module_selection = [ + { + 'type': 'checkbox', + 'message': 'Select modules', + 'name': 'modules', + 'choices': transform_list_into_choices( + list(modules.keys()) + ) + } + ] + return prompt(module_selection) -modules = get_modules() -print("\nRunning all modules \n") +modules = load_modules() -cmdRunner = Runner() -for module in modules: - cmdRunner.run(module) +selected_modules = open_module_selection(modules) + +for answer in selected_modules['modules']: + modules[answer].run() diff --git a/modules/sample/sampleModule.py b/modules/sample/sampleModule.py index 5fdd363..6a5b385 100644 --- a/modules/sample/sampleModule.py +++ b/modules/sample/sampleModule.py @@ -1,14 +1,12 @@ -from IModule import IModule +from AbstractModule import AbstractModule -class SampleModule(IModule): +class SampleModule(AbstractModule): """docstring for SampleModule.""" def __init__(self): super(SampleModule, self).__init__() - def get_command(self): - return [ - "command 1", - "command 2" - ] + def run(self): + print("Command 1") + print("Command 2") diff --git a/requirements.txt b/requirements.txt index 8b13789..efa466d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ - +PyInquirer==1.0.3