Fix module load and reload

This commit is contained in:
nemunaire 2014-11-13 21:38:18 +01:00
parent 63cc770800
commit fd5fbf6c6c
3 changed files with 19 additions and 7 deletions

18
bot.py
View File

@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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)

View File

@ -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

View File

@ -16,7 +16,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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)