From c7e2afbbc73c76d1635333faeb7ead4a78626b5c Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sun, 5 Jan 2020 17:56:53 +0100 Subject: [PATCH] Rename variables to not cover outer ones, remove transform method simplify module run process --- main.py | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/main.py b/main.py index 9f8f1dd..c88fc76 100644 --- a/main.py +++ b/main.py @@ -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())]