Use a new way to reload modules
This commit is contained in:
parent
a6b69aa672
commit
afdf951758
24
DCC.py
24
DCC.py
|
@ -1,14 +1,28 @@
|
|||
import imp
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Nemubot is a modulable IRC bot, built around XML configuration files.
|
||||
# Copyright (C) 2012 Mercier Pierre-Olivier
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# 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 os
|
||||
import re
|
||||
import socket
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
import traceback
|
||||
|
||||
message = __import__("message")
|
||||
imp.reload(message)
|
||||
import message
|
||||
|
||||
#Store all used ports
|
||||
PORTS = list()
|
||||
|
|
28
message.py
28
message.py
|
@ -1,18 +1,30 @@
|
|||
# coding=utf-8
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Nemubot is a modulable IRC bot, built around XML configuration files.
|
||||
# Copyright (C) 2012 Mercier Pierre-Olivier
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
import imp
|
||||
import re
|
||||
import shlex
|
||||
import string
|
||||
import sys
|
||||
import time
|
||||
|
||||
from credits import Credits
|
||||
import credits
|
||||
dcc = __import__("DCC")
|
||||
imp.reload(dcc)
|
||||
from credits import Credits
|
||||
import DCC
|
||||
import module_states_file as xmlparser
|
||||
|
||||
CREDITS = {}
|
||||
filename = ""
|
||||
|
|
|
@ -1,8 +1,23 @@
|
|||
# coding=utf-8
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Nemubot is a modulable IRC bot, built around XML configuration files.
|
||||
# Copyright (C) 2012 Mercier Pierre-Olivier
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# 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 xml.sax
|
||||
from datetime import datetime
|
||||
from datetime import date
|
||||
import time
|
||||
|
||||
class ModuleState:
|
||||
|
|
|
@ -1,12 +1,24 @@
|
|||
#!/usr/bin/python3
|
||||
# coding=utf-8
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Nemubot is a modulable IRC bot, built around XML configuration files.
|
||||
# Copyright (C) 2012 Mercier Pierre-Olivier
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# 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 os
|
||||
import imp
|
||||
import xml.sax
|
||||
|
||||
module_state = __import__("module_state")
|
||||
imp.reload(module_state)
|
||||
import module_state
|
||||
|
||||
class ModuleStatesFile(xml.sax.ContentHandler):
|
||||
def startDocument(self):
|
||||
|
|
46
nemubot.py
46
nemubot.py
|
@ -1,14 +1,31 @@
|
|||
#!/usr/bin/python3
|
||||
# coding=utf-8
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Nemubot is a modulable IRC bot, built around XML configuration files.
|
||||
# Copyright (C) 2012 Mercier Pierre-Olivier
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# 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 sys
|
||||
import os
|
||||
import imp
|
||||
import traceback
|
||||
|
||||
servers = dict()
|
||||
import reloader
|
||||
import prompt
|
||||
|
||||
prompt = __import__ ("prompt")
|
||||
servers = dict()
|
||||
|
||||
#Add modules dir path
|
||||
if os.path.isdir("./modules/"):
|
||||
|
@ -26,17 +43,18 @@ if len(sys.argv) >= 2:
|
|||
|
||||
print ("Nemubot ready, my PID is %i!" % (os.getpid()))
|
||||
while prompt.launch(servers):
|
||||
try:
|
||||
if prompt.MODS is None:
|
||||
imp.reload(prompt)
|
||||
else:
|
||||
mods = prompt.MODS
|
||||
imp.reload(prompt)
|
||||
prompt.MODS = mods
|
||||
except:
|
||||
print ("Unable to reload the prompt due to errors. Fix them before trying to reload the prompt.")
|
||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||
sys.stdout.write (traceback.format_exception_only(exc_type, exc_value)[0])
|
||||
try:
|
||||
imp.reload(reloader)
|
||||
if prompt.MODS is None:
|
||||
reloader.reload()
|
||||
else:
|
||||
mods = prompt.MODS
|
||||
reloader.reload()
|
||||
prompt.MODS = mods
|
||||
except:
|
||||
print ("Unable to reload the prompt due to errors. Fix them before trying to reload the prompt.")
|
||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||
sys.stdout.write (traceback.format_exception_only(exc_type, exc_value)[0])
|
||||
|
||||
print ("Bye")
|
||||
sys.exit(0)
|
||||
|
|
|
@ -1,17 +1,29 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Nemubot is a modulable IRC bot, built around XML configuration files.
|
||||
# Copyright (C) 2012 Mercier Pierre-Olivier
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# 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 os
|
||||
import shlex
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
server = __import__("server")
|
||||
imp.reload(server)
|
||||
|
||||
xmlparser = __import__("module_states_file")
|
||||
imp.reload(xmlparser)
|
||||
server.xmlparser = xmlparser
|
||||
server.message.xmlparser = xmlparser
|
||||
xmlparser.module_state.xmlparser = xmlparser
|
||||
import server
|
||||
import module_states_file as xmlparser
|
||||
|
||||
selectedServer = None
|
||||
modules_path = "./modules/"
|
||||
|
@ -47,7 +59,7 @@ def getPS1():
|
|||
return selectedServer.id
|
||||
|
||||
def launch(servers):
|
||||
"""Launch the prompt"""
|
||||
"""Launch the prompt and readline"""
|
||||
global MODS
|
||||
if MODS is None:
|
||||
MODS = list()
|
||||
|
@ -129,10 +141,8 @@ def load_module_from_name(name, servers, config=None):
|
|||
if md.name == name:
|
||||
mod = imp.reload(md)
|
||||
loaded = True
|
||||
try:
|
||||
if hasattr(mod, 'reload'):
|
||||
mod.reload()
|
||||
except AttributeError:
|
||||
pass
|
||||
break
|
||||
if not loaded:
|
||||
mod = __import__(name)
|
||||
|
@ -140,7 +150,7 @@ def load_module_from_name(name, servers, config=None):
|
|||
try:
|
||||
if mod.nemubotversion < 3.0:
|
||||
print (" Module `%s' is not compatible with this version." % name)
|
||||
return
|
||||
return false
|
||||
|
||||
#Set module common functions and datas
|
||||
mod.name = name
|
||||
|
@ -328,7 +338,7 @@ def connect(cmds, servers):
|
|||
servers[s].launch(MODS)
|
||||
else:
|
||||
print ("connect: server `%s' not found." % s)
|
||||
|
||||
|
||||
elif selectedServer is not None:
|
||||
selectedServer.launch(MODS)
|
||||
else:
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Nemubot is a modulable IRC bot, built around XML configuration files.
|
||||
# Copyright (C) 2012 Mercier Pierre-Olivier
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# 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 credits
|
||||
import channel
|
||||
import DCC
|
||||
import message
|
||||
import module_state
|
||||
import module_states_file
|
||||
import prompt
|
||||
import server
|
||||
|
||||
def reload():
|
||||
imp.reload(credits)
|
||||
imp.reload(channel)
|
||||
imp.reload(DCC)
|
||||
imp.reload(message)
|
||||
imp.reload(module_state)
|
||||
imp.reload(module_states_file)
|
||||
imp.reload(prompt)
|
||||
imp.reload(server)
|
||||
|
30
server.py
30
server.py
|
@ -1,16 +1,30 @@
|
|||
import imp
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Nemubot is a modulable IRC bot, built around XML configuration files.
|
||||
# Copyright (C) 2012 Mercier Pierre-Olivier
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# 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 socket
|
||||
import sys
|
||||
import threading
|
||||
import traceback
|
||||
import time
|
||||
|
||||
message = __import__("message")
|
||||
imp.reload(message)
|
||||
channel = __import__("channel")
|
||||
imp.reload(channel)
|
||||
dcc = __import__("DCC")
|
||||
imp.reload(dcc)
|
||||
import channel
|
||||
import DCC
|
||||
import message
|
||||
import module_states_file as xmlparser
|
||||
|
||||
class Server(threading.Thread):
|
||||
def __init__(self, node, nick, owner, realname, socket = None):
|
||||
|
|
Loading…
Reference in New Issue