def start(self, no_libs_check=False): """ Main application loop """ # Resize the console window SimpleTUI.resize_console(30, 120) # Load all the modules self.load_all_modules(no_libs_check=no_libs_check) # Loop exit = False while(not exit): SimpleTUI.set_console_title("EasyCloud") platform = self.menu() manager = self.get_instance(platform.manager_class) try: close = False while(not close): action = manager.menu() # if action == 0: # Ignore this value # pass if action == 1: # Close current manager menu close = True elif action == 2: # Close this application close = True exit = True except Exception as e: SimpleTUI.exception_dialog(e) self.close(0)
def get_instance(self, manager_class): """ Returns an existing instance of the manager_class provided in input if previously instantiated or creates a new instance. Args: manager_class (<manager_class>): class of the module manager Returns: <manager_class_instance>: an instance of <manager_class> """ for _instance in self.loaded_instances: if isinstance(_instance, manager_class): return _instance try: _new_instance = manager_class() self.loaded_instances.append(_new_instance) return _new_instance except Exception as e: SimpleTUI.exception_dialog(e) return None
def menu(self): """ Prints the modules menu """ global kill while True: # Header creation menu_header = "******************** EasyCloud ********************" # Subheader creation disclaimer = "\033[34;1mThis is a proof-of-concept build, not suitable\nfor production use.\033[0m\n" debug_status = None hffr_status = None if "LIBCLOUD_DEBUG" in environ: debug_status = "\033[93mLibcloud Debug Mode ON\033[0m" else: debug_status = "\033[90mLibcloud Debug Mode OFF\033[0m" if "LIBCLOUD_DEBUG_PRETTY_PRINT_RESPONSE" in environ and environ["LIBCLOUD_DEBUG_PRETTY_PRINT_RESPONSE"] == "1": hffr_status = "\033[93mLibcloud Human friendly formatted response ON\033[0m" else: hffr_status = "\033[90mLibcloud Human friendly formatted response OFF\033[0m" menu_subheader = [disclaimer, debug_status, hffr_status] # Menu items creation menu_items = [] for module in self.loaded_modules: menu_items.append(module.platform_name) menu_items.append("Close application") # Menu print choice = SimpleTUI.print_menu(menu_header, menu_items, subheader_items=menu_subheader, custom_question="Select a platform") try: if(choice >= 1 and choice <= len(self.loaded_modules)): return self.loaded_modules[choice - 1] # Load a module elif(choice == len(self.loaded_modules) + 1): # Close application self.close(0) else: SimpleTUI.msg_dialog("Error", "Unimplemented functionality", SimpleTUI.DIALOG_ERROR) except Exception as e: SimpleTUI.exception_dialog(e)