Rename variables to not cover outer ones, remove transform method

simplify module run process
This commit is contained in:
Marcel Schwarz 2020-01-05 17:56:53 +01:00
parent 058bdcd828
commit c7e2afbbc7

28
main.py
View File

@ -3,46 +3,32 @@ 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 = {}
loaded_modules = {}
for folder in os.listdir("./modules"):
try:
curr_module = importlib.import_module('.' + folder, package="modules")
modules[folder] = curr_module.get_module()
loaded_modules[folder] = curr_module.get_module()
except AttributeError:
pass
print("Modules loaded successfully.\n")
return modules
return loaded_modules
def open_module_selection(modules):
def open_module_selection(module_names):
print("Available Modules:")
module_selection = [
{
'type': 'checkbox',
'message': 'Select modules',
'name': 'modules',
'choices': transform_list_into_choices(
list(modules.keys())
)
'choices': list(map(lambda x: {"name": x}, list(module_names)))
}
]
return prompt(module_selection)
return prompt(module_selection)['modules']
modules = load_modules()
selected_modules = open_module_selection(modules)
for answer in selected_modules['modules']:
modules[answer].run()
[modules[module].run() for module in open_module_selection(modules.keys())]