plug

plugin management.

fbf.plugs.core.plug.handle_plugdisable(bot, event)

arguments: <plugname> - disable a plugin.

fbf.plugs.core.plug.handle_plugenable(bot, event)

arguments” <plugname> - enable a plugin.

fbf.plugs.core.plug.handle_plugreload(bot, ievent)

arguments: <list of plugnames> - reload list of plugins.

CODE

# fbf/plugs/core/plug.py
#
#

""" plugin management. """

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

basic imports

import os
import logging

plug-enable command

def handle_plugenable(bot, event):
    """ arguments" <plugname> - enable a plugin. """
    if not event.rest: event.missing("<plugname>") ; 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")

plug-disable command

def handle_plugdisable(bot, event):
    """ arguments: <plugname> - disable a plugin. """
    if not event.rest: event.missing("<plugin>") ; 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")

plug-reload command

def handle_plugreload(bot, ievent):
    """ arguments: <list of plugnames> - reload list of plugins. """
    try: pluglist = ievent.args
    except IndexError:
        ievent.missing('<list of plugnames>')
        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 <plugin>', 'plug-reload core')

Table Of Contents

Previous topic

outputcache

Next topic

rc

This Page