Rename variables to not cover outer ones, remove transform method
simplify module run process
This commit is contained in:
parent
058bdcd828
commit
c7e2afbbc7
28
main.py
28
main.py
@ -3,46 +3,32 @@ import importlib
|
|||||||
import os
|
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():
|
def load_modules():
|
||||||
print("Loading modules")
|
print("Loading modules")
|
||||||
modules = {}
|
loaded_modules = {}
|
||||||
for folder in os.listdir("./modules"):
|
for folder in os.listdir("./modules"):
|
||||||
try:
|
try:
|
||||||
curr_module = importlib.import_module('.' + folder, package="modules")
|
curr_module = importlib.import_module('.' + folder, package="modules")
|
||||||
modules[folder] = curr_module.get_module()
|
loaded_modules[folder] = curr_module.get_module()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
print("Modules loaded successfully.\n")
|
print("Modules loaded successfully.\n")
|
||||||
return modules
|
return loaded_modules
|
||||||
|
|
||||||
|
|
||||||
def open_module_selection(modules):
|
def open_module_selection(module_names):
|
||||||
print("Available Modules:")
|
print("Available Modules:")
|
||||||
module_selection = [
|
module_selection = [
|
||||||
{
|
{
|
||||||
'type': 'checkbox',
|
'type': 'checkbox',
|
||||||
'message': 'Select modules',
|
'message': 'Select modules',
|
||||||
'name': 'modules',
|
'name': 'modules',
|
||||||
'choices': transform_list_into_choices(
|
'choices': list(map(lambda x: {"name": x}, list(module_names)))
|
||||||
list(modules.keys())
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
return prompt(module_selection)
|
return prompt(module_selection)['modules']
|
||||||
|
|
||||||
|
|
||||||
modules = load_modules()
|
modules = load_modules()
|
||||||
|
|
||||||
selected_modules = open_module_selection(modules)
|
[modules[module].run() for module in open_module_selection(modules.keys())]
|
||||||
|
|
||||||
for answer in selected_modules['modules']:
|
|
||||||
modules[answer].run()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user