Fix module load and reload
This commit is contained in:
parent
63cc770800
commit
fd5fbf6c6c
18
bot.py
18
bot.py
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user