linux-tools/main.py
Marcel Schwarz af169b9598 Replace IModule with AbstractModule
Delete CommandRunner
Set up API to delegate the module execution to the module itself
Update SampleModule
2019-12-21 02:49:53 +01:00

49 lines
1.1 KiB
Python

from PyInquirer import prompt
import importlib
import os
def transform_list_into_choices(choices_list):
mapped_list = []
for choice in choices_list:
mapped_list.append({
"name": choice
})
return mapped_list
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
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 = load_modules()
selected_modules = open_module_selection(modules)
for answer in selected_modules['modules']:
modules[answer].run()