From fd5fbf6c6c986710603ea6347d63cdc4eb846be0 Mon Sep 17 00:00:00 2001 From: nemunaire Date: Thu, 13 Nov 2014 21:38:18 +0100 Subject: [PATCH] Fix module load and reload --- bot.py | 18 ++++++++++++++++-- hooks/manager.py | 4 ++-- tools/config.py | 4 +--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/bot.py b/bot.py index 1c16278..2c38871 100644 --- a/bot.py +++ b/bot.py @@ -17,6 +17,7 @@ # along with this program. If not, see . from datetime import datetime, timedelta, timezone +import imp import logging from queue import Queue import re @@ -346,6 +347,21 @@ class Bot(threading.Thread): return False + def import_module(self, name): + """Load a module + + Argument: + name -- name of the module to load + """ + + if name in self.modules: + self.unload_module(name) + tt = __import__(name) + imp.reload(tt) + else: + __import__(name) + + def add_module(self, module): """Add a module to the context, if already exists, unload the old one before""" @@ -447,8 +463,6 @@ def hotswap(bak): return new def reload(): - import imp - import channel imp.reload(channel) diff --git a/hooks/manager.py b/hooks/manager.py index 2331d68..687fcf1 100644 --- a/hooks/manager.py +++ b/hooks/manager.py @@ -62,9 +62,9 @@ class HooksManager: if trigger in self.hooks: if hook is None: del self.hooks[trigger] - return True else: - return self.hooks[trigger].remove(hook) + self.hooks[trigger].remove(hook) + return True return False diff --git a/tools/config.py b/tools/config.py index e16b153..e1a2b37 100644 --- a/tools/config.py +++ b/tools/config.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import imp import logging import os @@ -130,5 +129,4 @@ def load_file(filename, context): # Unexisting file, assume a name was passed, import the module! else: - tt = __import__(filename) - imp.reload(tt) + context.import_module(filename)