def confString(self, section, opt, default=None): """Read a string value from the plugin's own configuration file. :param section: configuration file section to read :param opt: option name to read :param default: value to read if the option is missing :return: string option value read, or default if option was missing """ return config.getOption(self._conf, section, opt, config.Option(default))
def confList(self, section, opt, default=None): """Read a boolean value from the plugin's own configuration file :param section: configuration file section to read :param opt: option name to read :param default: value to read if the option is missing :return: boolean option value read, or *default* if the option was missing or could not be parsed """ return config.getOption(self._conf, section, opt, config.ListOption(default))
def confBool(self, section, opt, default=None): '''Read a boolean value from the plugin's own configuration file @param section: Configuration file section to read. @param opt: Option name to read. @param default: Value to read if option is missing. @return: Boolean option value read, or default if option was missing or could not be parsed. ''' return config.getOption(self._conf, section, opt, config.BoolOption(default))
def confString(self, section, opt, default=None): '''Read a string value from the plugin's own configuration file @param section: Configuration file section to read. @param opt: Option name to read. @param default: Value to read if option is missing. @return: String option value read, or default if option was missing. ''' # ' xemacs highlighting hack return config.getOption(self._conf, section, opt, config.Option(default))
def confBool(self, section, opt, default=None): """Read a boolean value from the plugin's own configuration file :param section: configuration file section to read :param opt: option name to read :param default: value to read if the option is missing :return: boolean option value read, or *default* if the option was missing or could not be parsed """ return config.getOption(self._conf, section, opt, config.BoolOption(default))
def confInt(self, section, opt, default=None): """Read an integer value from the plugin's own configuration file. :param section: configuration file section to read :param opt: option name to read :param default: value to read if the option is missing :return: the integer option value read, or *default* if the option was missing or could not be parsed """ return config.getOption(self._conf, section, opt, config.IntOption(default))
def _loadplugin(self, modulefile, types): '''Attempt to import a plugin module and register the hook methods it uses. ''' dir, modname = os.path.split(modulefile) modname = modname.split('.py')[0] conf = self._getpluginconf(modname) if (not conf or (not config.getOption(conf, 'main', 'enabled', config.BoolOption(False)) and not self._plugin_cmdline_match(modname, self.enabledPlugins, self._used_enable_plugin))): self.verbose_logger.debug( _('Not loading "%s" plugin, as it is disabled'), modname) return try: fp, pathname, description = imp.find_module(modname, [dir]) try: module = imp.load_module(modname, fp, pathname, description) finally: fp.close() except: if self.verbose_logger.isEnabledFor(logginglevels.DEBUG_4): raise # Give full backtrace: self.verbose_logger.error( _('Plugin "%s" can\'t be imported') % modname) return # Check API version required by the plugin if not hasattr(module, 'requires_api_version'): self.verbose_logger.error( _('Plugin "%s" doesn\'t specify required API version') % modname) return if not apiverok(API_VERSION, module.requires_api_version): self.verbose_logger.error( _('Plugin "%s" requires API %s. Supported API is %s.') % ( modname, module.requires_api_version, API_VERSION, )) return # Check plugin type against filter plugintypes = getattr(module, 'plugin_type', ALL_TYPES) if not isinstance(plugintypes, (list, tuple)): plugintypes = (plugintypes, ) if len(plugintypes) < 1: return for plugintype in plugintypes: if id(plugintype) == id(TYPE_INTERFACE): self.verbose_logger.log( logginglevels.INFO_2, 'Plugin "%s" uses deprecated constant ' 'TYPE_INTERFACE.\nPlease use TYPE_INTERACTIVE ' 'instead.', modname) if plugintype not in types: return # This should really work like enable/disable repo. and be based on the # cmd line order ... but the API doesn't really allow that easily. # FIXME: Fix for 4.* if (self._plugin_cmdline_match(modname, self.disabledPlugins, self._used_disable_plugin) and not self._plugin_cmdline_match( modname, self.enabledPlugins, self._used_enable_plugin)): return self.verbose_logger.log(logginglevels.DEBUG_3, _('Loading "%s" plugin'), modname) # Store the plugin module and its configuration file if modname not in self._plugins: self._plugins[modname] = (module, conf) else: raise Errors.ConfigError(_('Two or more plugins with the name "%s" ' \ 'exist in the plugin search path') % modname) for slot in SLOTS: funcname = slot + '_hook' if hasattr(module, funcname): self._pluginfuncs[slot].append( (modname, getattr(module, funcname)))
def _loadplugin(self, modulefile, types): '''Attempt to import a plugin module and register the hook methods it uses. ''' dir, modname = os.path.split(modulefile) modname = modname.split('.py')[0] # This should really work like enable/disable repo. and be based on the # cmd line order ... but the API doesn't really allow that easily. # FIXME: Fix for 4.* (lol) # Do disabled cmd line checks before loading the module code. if (self._plugin_cmdline_match(modname, self.disabledPlugins, self._used_disable_plugin) and not self._plugin_cmdline_match(modname, self.enabledPlugins, self._used_enable_plugin)): return conf = self._getpluginconf(modname) if (not conf or (not config.getOption(conf, 'main', 'enabled', config.BoolOption(False)) and not self._plugin_cmdline_match(modname, self.enabledPlugins, self._used_enable_plugin))): self.verbose_logger.debug(_('Not loading "%s" plugin, as it is disabled'), modname) return try: fp, pathname, description = imp.find_module(modname, [dir]) try: module = imp.load_module(modname, fp, pathname, description) finally: fp.close() except: if self.verbose_logger.isEnabledFor(logginglevels.DEBUG_4): raise # Give full backtrace: self.verbose_logger.error(_('Plugin "%s" can\'t be imported') % modname) return # Check API version required by the plugin if not hasattr(module, 'requires_api_version'): self.verbose_logger.error( _('Plugin "%s" doesn\'t specify required API version') % modname) return if not apiverok(API_VERSION, module.requires_api_version): self.verbose_logger.error( _('Plugin "%s" requires API %s. Supported API is %s.') % ( modname, module.requires_api_version, API_VERSION, )) return # Check plugin type against filter plugintypes = getattr(module, 'plugin_type', ALL_TYPES) if not isinstance(plugintypes, (list, tuple)): plugintypes = (plugintypes,) if len(plugintypes) < 1: return for plugintype in plugintypes: if id(plugintype) == id(TYPE_INTERFACE): self.verbose_logger.log(logginglevels.INFO_2, 'Plugin "%s" uses deprecated constant ' 'TYPE_INTERFACE.\nPlease use TYPE_INTERACTIVE ' 'instead.', modname) if plugintype not in types: return self.verbose_logger.log(logginglevels.DEBUG_3, _('Loading "%s" plugin'), modname) # Store the plugin module and its configuration file if modname not in self._plugins: self._plugins[modname] = (module, conf) else: raise Errors.ConfigError(_('Two or more plugins with the name "%s" ' \ 'exist in the plugin search path') % modname) for slot in SLOTS: funcname = slot+'_hook' if hasattr(module, funcname): self._pluginfuncs[slot].append( (modname, getattr(module, funcname)) )
def refreshOption(self, filename): self.option = config.getOption(filename) self.getOption()
cmdDic = Option['cmd'] myip= recvSocket.myip() ADDR=(cmdDic['IP'], 10011) msg = "CONNECT|{}".format(myip) # log.PrintLog(msg) writeLog.PrintLog("Performance Test Start") print("Performance Test Start") while g_alive: try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(ADDR) sock.send(msg.encode('utf-8')) data = sock.recv(BUFSIZE) writeLog.PrintLog("{} -> {}".format(cmdDic['IP'], data.decode('utf-8'))) sock.close() time.sleep(10) except socket.error as e: writeLog.PrintLog("[main] exception({} - {})".format(e, msg)) except Exception as e: writeLog.PrintLog("[main] except :{}".format(sys.exc_info()[0])) time.sleep(10) writeLog.PrintLog("Performance Test End") print("Performance Test End") if __name__ == "__main__": Option = config.getOption('config.conf') main()