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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
|
import imp
|
||||||
import logging
|
import logging
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
import re
|
import re
|
||||||
@ -346,6 +347,21 @@ class Bot(threading.Thread):
|
|||||||
return False
|
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):
|
def add_module(self, module):
|
||||||
"""Add a module to the context, if already exists, unload the
|
"""Add a module to the context, if already exists, unload the
|
||||||
old one before"""
|
old one before"""
|
||||||
@ -447,8 +463,6 @@ def hotswap(bak):
|
|||||||
return new
|
return new
|
||||||
|
|
||||||
def reload():
|
def reload():
|
||||||
import imp
|
|
||||||
|
|
||||||
import channel
|
import channel
|
||||||
imp.reload(channel)
|
imp.reload(channel)
|
||||||
|
|
||||||
|
@ -62,9 +62,9 @@ class HooksManager:
|
|||||||
if trigger in self.hooks:
|
if trigger in self.hooks:
|
||||||
if hook is None:
|
if hook is None:
|
||||||
del self.hooks[trigger]
|
del self.hooks[trigger]
|
||||||
return True
|
|
||||||
else:
|
else:
|
||||||
return self.hooks[trigger].remove(hook)
|
self.hooks[trigger].remove(hook)
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import imp
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@ -130,5 +129,4 @@ def load_file(filename, context):
|
|||||||
|
|
||||||
# Unexisting file, assume a name was passed, import the module!
|
# Unexisting file, assume a name was passed, import the module!
|
||||||
else:
|
else:
|
||||||
tt = __import__(filename)
|
context.import_module(filename)
|
||||||
imp.reload(tt)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user