def onEnable(self): """ Check that all the required plugins are actually enabled, and if not enable them. """ for req in self.requiresPlugins: plugin = self.console.getPlugin(req) if not plugin.isEnabled(): plugin.enable()
def _run_disable_plugin_commands(self): for cmd in self.config.findall("disable_plugin"): try: pluginName = cmd.attrib['plugin'].strip().lower() plugin = self.plugin.console.getPlugin(pluginName) if plugin: if not plugin.isEnabled(): self.plugin.info('Plugin %s is already disabled.' % pluginName) else: plugin.disable() self.plugin.info('Plugin %s is now OFF' % pluginName) else: self.plugin.warn('No plugin named %s loaded.' % pluginName) except Exception, e: self.plugin.error("task %s : %s" % (self.name, e))
def _run_disable_plugin_commands(self): for cmd in self.config.findall("disable_plugin"): try: pluginName = cmd.attrib['plugin'].strip().lower() plugin = self.plugin.console.getPlugin(pluginName) if plugin: if not plugin.isEnabled(): self.plugin.info('plugin %s is already disabled', pluginName) else: plugin.disable() self.plugin.info('plugin %s is now OFF', pluginName) else: self.plugin.warn('no plugin named %s loaded', pluginName) except Exception, e: self.plugin.error("task %s : %s", self.name, e)
def _run_enable_plugin_commands(self): for cmd in self.config.findall("enable_plugin"): try: pluginName = cmd.attrib["plugin"].strip().lower() plugin = self.plugin.console.getPlugin(pluginName) if plugin: if plugin.isEnabled(): self.plugin.info("Plugin %s is already enabled." % pluginName) else: plugin.enable() self.plugin.info("Plugin %s is now ON" % pluginName) else: self.plugin.warn("No plugin named %s loaded." % pluginName) except Exception, e: self.plugin.error("task %s : %s" % (self.name, e))
def do_unload(self, client, name=None): """ Unload a plugin :param client: The client who launched the command :param name: The name of the plugin to unload """ name = name.lower() if name in self._protected: client.message('^7Plugin ^1%s ^7is protected' % name) else: plugin = self.console.getPlugin(name) if not plugin: client.message('^7Plugin ^1%s ^7is not loaded' % name) else: if plugin.isEnabled(): client.message( '^7Plugin ^1%s ^7is currently enabled: disable it first' % name) else: unreg = [ x for x in self._adminPlugin._commands if self._adminPlugin._commands[x].plugin == plugin ] for command in unreg: self._adminPlugin.unregisterCommand(command) # unregister the event handler self.console.unregisterHandler(plugin) # remove all the crontabs bounded to this plugin unreg = [ x for x in self.console.cron._tabs if isinstance( self.console.cron._tabs[x], b3.cron.PluginCronTab) and self.console.cron._tabs[x].plugin == plugin ] for tab in unreg: self.console.cron.cancel(tab) del self.console._plugins[name] # queue an event so other plugins may react on this change self.console.queueEvent( self.console.getEvent('EVT_PLUGIN_UNLOADED', data=name)) client.message('^7Plugin ^1%s ^7has been unloaded' % name)
def do_enable(self, client, name=None): """ Enable a plugin :param client: The client who launched the command :param name: The name of the plugin to enable """ name = name.lower() if name in self._protected: client.message('^7Plugin ^1%s ^7is protected' % name) else: plugin = self.console.getPlugin(name) if not plugin: client.message('^7Plugin ^1%s ^7is not loaded' % name) else: if plugin.isEnabled(): client.message('^7Plugin ^3%s ^7is already enabled' % name) else: plugin.enable() client.message('^7Plugin ^3%s ^7is now ^2enabled' % name)
def do_disable(self, client, name=None): """ Disable a plugin :param client: The client who launched the command :param name: The name of the plugin to disable """ name = name.lower() if name in self._protected: client.message('^7Plugin ^1%s ^7is protected' % name) else: plugin = self.console.getPlugin(name) if not plugin: client.message('^7Plugin ^1%s ^7is not loaded' % name) else: if not plugin.isEnabled(): client.message('^7Plugin ^3%s ^7is already disabled' % name) else: plugin.disable() client.message('^7Plugin ^3%s ^7is now ^1disabled' % name)
def do_unload(self, client, name=None): """ Unload a plugin :param client: The client who launched the command :param name: The name of the plugin to unload """ name = name.lower() if name in self._protected: client.message('^7Plugin ^1%s ^7is protected' % name) else: plugin = self.console.getPlugin(name) if not plugin: client.message('^7Plugin ^1%s ^7is not loaded' % name) else: if plugin.isEnabled(): client.message('^7Plugin ^1%s ^7is currently enabled: disable it first' % name) else: unreg = [x for x in self._adminPlugin._commands if self._adminPlugin._commands[x].plugin == plugin] for command in unreg: self._adminPlugin.unregisterCommand(command) # unregister the event handler self.console.unregisterHandler(plugin) # remove all the crontabs bounded to this plugin unreg = [x for x in self.console.cron._tabs if isinstance(self.console.cron._tabs[x], b3.cron.PluginCronTab) and self.console.cron._tabs[x].plugin == plugin] for tab in unreg: self.console.cron.cancel(tab) del self.console._plugins[name] # queue an event so other plugins may react on this change self.console.queueEvent(self.console.getEvent('EVT_PLUGIN_UNLOADED', data=name)) client.message('^7Plugin ^1%s ^7has been unloaded' % name)