3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 09:19:23 +01:00

corecommands: fix wrong plugin module name causing 'unload' to not work

Plugin modules are now named 'pylinkirc.plugins.abcd' instead of just 'abcd', since the import system is absolute now.
This commit is contained in:
James Lu 2016-07-10 21:41:08 -07:00
parent c1cd6f42a0
commit 5d251d511a

View File

@ -2,6 +2,9 @@
corecommands.py - Implements core PyLink commands. corecommands.py - Implements core PyLink commands.
""" """
# Get the package name that plugins are stored under.
plugin_root = __name__.split('.')[0] + '.plugins.'
import gc import gc
import sys import sys
import importlib import importlib
@ -94,6 +97,11 @@ def unload(irc, source, args):
except IndexError: except IndexError:
irc.reply("Error: Not enough arguments. Needs 1: plugin name.") irc.reply("Error: Not enough arguments. Needs 1: plugin name.")
return return
# Since we're using absolute imports in 0.9.x+, the module name differs from the actual plugin
# name.
modulename = plugin_root + name
if name in world.plugins: if name in world.plugins:
log.info('(%s) Unloading plugin %r for %s', irc.name, name, irc.getHostmask(source)) log.info('(%s) Unloading plugin %r for %s', irc.name, name, irc.getHostmask(source))
pl = world.plugins[name] pl = world.plugins[name]
@ -105,7 +113,7 @@ def unload(irc, source, args):
for cmdfunc in cmdfuncs: for cmdfunc in cmdfuncs:
log.debug('__module__ of cmdfunc %s is %s', cmdfunc, cmdfunc.__module__) log.debug('__module__ of cmdfunc %s is %s', cmdfunc, cmdfunc.__module__)
if cmdfunc.__module__ == name: if cmdfunc.__module__ == modulename:
log.debug("Removing %s from world.services['pylink'].commands[%s]", cmdfunc, cmdname) log.debug("Removing %s from world.services['pylink'].commands[%s]", cmdfunc, cmdname)
world.services['pylink'].commands[cmdname].remove(cmdfunc) world.services['pylink'].commands[cmdname].remove(cmdfunc)
@ -117,7 +125,7 @@ def unload(irc, source, args):
# Remove any command hooks set by the plugin. # Remove any command hooks set by the plugin.
for hookname, hookfuncs in world.hooks.copy().items(): for hookname, hookfuncs in world.hooks.copy().items():
for hookfunc in hookfuncs: for hookfunc in hookfuncs:
if hookfunc.__module__ == name: if hookfunc.__module__ == modulename:
world.hooks[hookname].remove(hookfunc) world.hooks[hookname].remove(hookfunc)
# If the hookfuncs list is empty, remove it. # If the hookfuncs list is empty, remove it.
if not hookfuncs: if not hookfuncs: