From 676f479d526d2639580f358d8b10d212eadce627 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sun, 17 Jan 2016 09:21:29 -0600 Subject: [PATCH] ircbot: add some debug logging in plugin (un)load --- dr_botzo/ircbot/bot.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/dr_botzo/ircbot/bot.py b/dr_botzo/ircbot/bot.py index 607f70f..42bc64d 100644 --- a/dr_botzo/ircbot/bot.py +++ b/dr_botzo/ircbot/bot.py @@ -591,13 +591,19 @@ class IRCBot(irc.client.SimpleIRCClient): The general assumption here is that a plugin's init loads its hooks and handlers. """ - log.debug("trying to load %s", plugin_path) + log.debug("trying to load plugin %s", plugin_path) dest = None if feedback: dest = ircbotlib.reply_destination_for_event(event) + # loop over the sys.modules entries, for debugging + log.debug("loaded modules:") + for module_name, module in sys.modules.items(): + log.debug(" %s", module_name) + for path, plugin in self.plugins: + log.debug("looping already loaded plugin: %s %s", plugin, path) if plugin_path == path: if feedback: self.privmsg(dest, "Plugin '{0:s}' is already loaded.".format(plugin_path)) @@ -629,6 +635,11 @@ class IRCBot(irc.client.SimpleIRCClient): if feedback: self.privmsg(dest, "Plugin '{0:s}' could not be loaded: {1:s}".format(plugin_path, str(e))) + # loop over the sys.modules entries, for debugging + log.debug("new list of loaded modules:") + for module_name, module in sys.modules.items(): + log.debug(" %s", module_name) + def handle_unload(self, connection, event, match): """Handle IRC requests to unload a plugin.""" @@ -642,10 +653,15 @@ class IRCBot(irc.client.SimpleIRCClient): def _unload_plugin(self, connection, event, plugin_path): """Attempt to unload and del a module if it's loaded.""" - log.debug("trying to unload %s", plugin_path) + log.debug("trying to unload plugin %s", plugin_path) dest = ircbotlib.reply_destination_for_event(event) + # loop over the sys.modules entries, for debugging + log.debug("loaded modules:") + for module_name, module in sys.modules.items(): + log.debug(" %s", module_name) + unloaded = False for path, plugin in self.plugins: if plugin_path == path: @@ -660,6 +676,11 @@ class IRCBot(irc.client.SimpleIRCClient): if not unloaded: self.privmsg(dest, "Plugin '{0:s}' is not loaded.".format(plugin_path)) + # loop over the sys.modules entries, for debugging + log.debug("new list of loaded modules:") + for module_name, module in sys.modules.items(): + log.debug(" %s", module_name) + def privmsg(self, target, text): """Send a PRIVMSG command.