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 __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 create_config_directory(dirpath): """Creates config directory at the given path""" # create directories if not os.path.isdir(dirpath): os.mkdir(dirpath) # save global config file global_config_path = defaults.get_global_config_path(dirpath) if not os.path.isfile(global_config_path): shutil.copyfile('reminisc/config/default_config.ini', global_config_path) # create config database dbpath = defaults.get_config_database_path(dirpath) print(dbpath) create_config_database(dbpath) # save config files for all modules for reminisc_module_name in defaults.approved_reminisc_modules: reminisc_module_impls = utils.find_reminisc_module_implementations(reminisc_module_name) if len(reminisc_module_impls) > 1: logger.error("Reminisc module {} defines more than one module class. Config will not be generated" .format(reminisc_module_name)) else: for impl in reminisc_module_impls: module_dir = defaults.get_module_config_dir(dirpath, reminisc_module_name) module_config = defaults.get_module_config_path(dirpath, reminisc_module_name) if not os.path.isdir(module_dir): print(module_dir) os.makedirs(module_dir) if not os.path.isfile(module_config): print(module_config) config_file = open(module_config, 'w') config_file.write(impl.default_config()) config_file.close()