def load_languages(self): self.translations = {} tool.touch_folder(self.language_folder) for file in tool.list_file(self.language_folder, LANGUAGE_FILE_SUFFIX): language = os.path.basename(file).rstrip(LANGUAGE_FILE_SUFFIX) with open(file, encoding='utf8') as f: self.translations[language] = yaml.round_trip_load(f)
def load_reactor(self, folder): reactors = [] for file in tool.list_file(folder, '.py'): module = tool.load_source(file) if callable(getattr(module, 'get_reactor', None)): reactors.append(module.get_reactor(self)) return reactors
def load_reactor(self, folder): reactors = [] for file in tool.list_file(folder, constant.REACTOR_FILE_SUFFIX): module = tool.load_source(file) if callable(getattr(module, 'get_reactor', None)): reactors.append(module.get_reactor(self.server)) return reactors
def __get_file_list(self, suffix): if not os.path.isdir(self.plugin_folder): os.makedirs(self.plugin_folder) full_path_list = tool.list_file(self.plugin_folder, suffix) return [ path.replace(self.plugin_folder + os.path.sep, '', 1) for path in full_path_list ]
def load_plugins(self): self.server.logger.info( self.server.t('plugin_manager.load_plugins.loading')) # init self.server.command_manager.clean_help_message() self.command_prefix_listeners = {} if not os.path.isdir(constant.PLUGIN_FOLDER): os.makedirs(constant.PLUGIN_FOLDER) file_list = tool.list_file(constant.PLUGIN_FOLDER, '.py') name_dict = {plugin.file_name: plugin for plugin in self.plugins} counter_all = counter_load = counter_unload = counter_reload = 0 # load and reload for file_name in file_list: if file_name in name_dict: plugin = name_dict[file_name] counter_reload += self.reload_plugin(plugin) counter_all += 1 else: counter_load += self.load_plugin(file_name) counter_all += 1 # unload unload_list = [] for plugin in self.plugins: if plugin.file_name not in file_list: counter_unload += self.unload_plugin(plugin) counter_all += 1 unload_list.append(plugin) for plugin in unload_list: self.plugins.remove(plugin) # end counter_fail = counter_all - counter_load - counter_unload - counter_reload msg = [] if counter_load > 0: msg.append( self.server.t('plugin_manager.load_plugins.info_loaded', counter_load)) if counter_unload > 0: msg.append( self.server.t('plugin_manager.load_plugins.info_unloaded', counter_unload)) if counter_reload > 0: msg.append( self.server.t('plugin_manager.load_plugins.info_reloaded', counter_reload)) if counter_fail > 0: msg.append( self.server.t('plugin_manager.load_plugins.info_fail', counter_fail)) if len(msg) == 0: msg = self.server.t('plugin_manager.load_plugins.info_none') else: msg = '; '.join(msg) return msg
def load_languages(self): self.translations = {} if os.path.isdir(self.language_folder): for file in tool.list_file(self.language_folder, LANGUAGE_FILE_SUFFIX): language = os.path.basename(file).rstrip(LANGUAGE_FILE_SUFFIX) with open(file, encoding='utf8') as f: self.translations[language] = yaml.round_trip_load(f) return True else: os.makedirs(self.language_folder) return False
def __get_file_list(self, suffix): full_path_list = tool.list_file(self.plugin_folder, suffix) return [path.replace(self.plugin_folder + os.path.sep, '', 1) for path in full_path_list]