.. _fbf.plugs.core.plug: plug ~~~~ .. automodule:: fbf.plugs.core.plug :show-inheritance: :members: :undoc-members: CODE ---- :: # fbf/plugs/core/plug.py # # """ plugin management. """ .. _fbf.plugs.core.plug_fbf_imports: fbf imports -------------- :: from fbf.lib.commands import cmnds from fbf.lib.examples import examples from fbf.lib.boot import default_plugins, plugin_packages, remove_plugin, update_mod from fbf.utils.exception import handle_exception, exceptionmsg from fbf.lib.boot import savecmndtable, savepluginlist, update_mod from fbf.lib.errors import NoSuchPlugin, RequireError from fbf.lib.boot import plugenable, plugdisable .. _fbf.plugs.core.plug_basic_imports: basic imports ---------------- :: import os import logging .. _fbf.plugs.core.plug_plug-enable_command: plug-enable command ---------------------- :: def handle_plugenable(bot, event): """ arguments" - enable a plugin. """ if not event.rest: event.missing("") ; return if "." in event.rest: mod = event.rest else: mod = bot.plugs.getmodule(event.rest) if not mod: event.reply("can't find module for %s" % event.rest) ; return event.reply("reloading and enabling %s" % mod) plugenable(mod) bot.enable(mod) bot.plugs.reload(mod, force=True) update_mod(mod) event.done() cmnds.add("plug-enable", handle_plugenable, ["OPER", ]) examples.add("plug-enable", "enable a plugin", "plug-enable rss") .. _fbf.plugs.core.plug_plug-disable_command: plug-disable command ----------------------- :: def handle_plugdisable(bot, event): """ arguments: - disable a plugin. """ if not event.rest: event.missing("") ; return mod = bot.plugs.getmodule(event.rest) if mod in default_plugins: event.reply("can't remove a default plugin") ; return if not mod: event.reply("can't find module for %s" % event.rest) ; return event.reply("unloading and disabling %s" % mod) bot.plugs.unload(mod) plugdisable(mod) bot.disable(mod) event.done() cmnds.add("plug-disable", handle_plugdisable, ["OPER", ]) examples.add("plug-disable", "disable a plugin", "plug-disable rss") .. _fbf.plugs.core.plug_plug-reload_command: plug-reload command ---------------------- :: def handle_plugreload(bot, ievent): """ arguments: - reload list of plugins. """ try: pluglist = ievent.args except IndexError: ievent.missing('') return ievent.untildone = True reloaded = [] errors = [] for plug in pluglist: modname = bot.plugs.getmodule(plug) if not modname: errors.append("can't find %s plugin" % plug) ; continue try: loaded = bot.plugs.reload(modname, force=True, showerror=True) for plug in loaded: reloaded.append(plug) logging.warn("%s reloaded" % plug) except RequireError as ex: errors.append(str(ex)) ; continue except NoSuchPlugin: errors.append("can't find %s plugin" % plug) ; continue except Exception as ex: if 'No module named' in str(ex) and plug in str(ex): logging.debug('%s - %s' % (modname, str(ex))) continue errors.append(exceptionmsg()) for modname in reloaded: if modname: update_mod(modname) if errors: ievent.reply('errors: ', errors) if reloaded: ievent.reply('reloaded: ', reloaded) ievent.done() cmnds.add('plug-reload', handle_plugreload, 'OPER') examples.add('plug-reload', 'plug-reload ', 'plug-reload core')