def __start_modules(self, modules): """Responsible for starting all enabled modules in separate threads.""" global_config_dict = self.__config.as_config_dict() queue = queues.command_queue for module_name in modules: logger.debug("Inspecting module: {}".format(module_name)) # parse module config and convert it to a dict config = config_reader.read_config_file(defaults.get_module_config_path(self.__config_dir, module_name)) config_dict = config.as_config_dict() # find all classes in the module extending AbstractModule reminisc_module_impls = module_utils.find_reminisc_module_implementations(module_name) # only one class extending AbstractModule is going to be started per reminisc module if len(reminisc_module_impls) > 1: logger.error("Module {} has more than 1 module class. Module will not be started.".format(module_name)) else: for impl in reminisc_module_impls: # instantiate the module class dbpath = defaults.get_config_database_path(self.__config_dir) dbconfig = DbConfig(dbpath, prefix=module_name) mod_instance = impl(global_config_dict, config_dict, queue, dbconfig) # start thread for the module if can be started if mod_instance.should_be_started(): logger.info("Starting {}".format(impl.__name__)) thread = threading.Thread(target=mod_instance.start) thread.daemon = True thread.start() else: logger.warn("Module class {} is disabled".format(impl.__name__))
def execute(self): """Starts the application.""" # we don't take any arguments for now parser = argparse.ArgumentParser() parser.add_argument('--config-directory', help='config directory location') parser.add_argument('--create-config', action='store_true', help='generate default configuration files') parser.add_argument('--start-webpanel', action='store_true', help='start the web panel') args = parser.parse_args() # determine config directory location self.__config_dir = args.config_directory if args.config_directory else defaults.config_folder_path # generate config if should be generated end stop execution if args.create_config: print("Generating config directory: {}".format(self.__config_dir)) config_generator.create_config_directory(self.__config_dir) return self.__config = config_reader.read_config_file(defaults.get_global_config_path(self.__config_dir)) self.__start_processing() # filter enabled modules from config and start them enabled_modules = {k: v for (k, v) in self.__config.items('modules') if v == 'True'} enabled_modules_names = map(lambda item: item[0], enabled_modules.items()) self.__start_modules(enabled_modules_names) if args.start_webpanel: self.__start_webpanel()
def __start_modules(self, modules): """Responsible for starting all enabled modules in separate threads.""" global_config_dict = self.__config.as_config_dict() queue = queues.command_queue for module_name in modules: logger.debug("Inspecting module: {}".format(module_name)) # parse module config and convert it to a dict config = config_reader.read_config_file( defaults.get_module_config_path(self.__config_dir, module_name)) config_dict = config.as_config_dict() # find all classes in the module extending AbstractModule reminisc_module_impls = module_utils.find_reminisc_module_implementations( module_name) # only one class extending AbstractModule is going to be started per reminisc module if len(reminisc_module_impls) > 1: logger.error( "Module {} has more than 1 module class. Module will not be started." .format(module_name)) else: for impl in reminisc_module_impls: # instantiate the module class dbpath = defaults.get_config_database_path( self.__config_dir) dbconfig = DbConfig(dbpath, prefix=module_name) mod_instance = impl(global_config_dict, config_dict, queue, dbconfig) # start thread for the module if can be started if mod_instance.should_be_started(): logger.info("Starting {}".format(impl.__name__)) thread = threading.Thread(target=mod_instance.start) thread.daemon = True thread.start() else: logger.warn("Module class {} is disabled".format( impl.__name__))
def execute(self): """Starts the application.""" # we don't take any arguments for now parser = argparse.ArgumentParser() parser.add_argument('--config-directory', help='config directory location') parser.add_argument('--create-config', action='store_true', help='generate default configuration files') parser.add_argument('--start-webpanel', action='store_true', help='start the web panel') args = parser.parse_args() # determine config directory location self.__config_dir = args.config_directory if args.config_directory else defaults.config_folder_path # generate config if should be generated end stop execution if args.create_config: print("Generating config directory: {}".format(self.__config_dir)) config_generator.create_config_directory(self.__config_dir) return self.__config = config_reader.read_config_file( defaults.get_global_config_path(self.__config_dir)) self.__start_processing() # filter enabled modules from config and start them enabled_modules = { k: v for (k, v) in self.__config.items('modules') if v == 'True' } enabled_modules_names = map(lambda item: item[0], enabled_modules.items()) self.__start_modules(enabled_modules_names) if args.start_webpanel: self.__start_webpanel()