Modify context reload for better maintainability
This commit is contained in:
parent
4dd837cf4b
commit
4776fbe931
31
bot.py
31
bot.py
@ -429,6 +429,9 @@ class Bot(threading.Thread):
|
||||
|
||||
def hotswap(bak):
|
||||
bak.stop = True
|
||||
if bak.event_timer is not None:
|
||||
bak.event_timer.cancel()
|
||||
|
||||
new = Bot(str(bak.ip), bak.modules_paths, bak.data_path)
|
||||
new.servers = bak.servers
|
||||
new.modules = bak.modules
|
||||
@ -436,6 +439,8 @@ def hotswap(bak):
|
||||
new.events = bak.events
|
||||
new.hooks = bak.hooks
|
||||
new.network = bak.network
|
||||
|
||||
new._update_event_timer()
|
||||
return new
|
||||
|
||||
def reload():
|
||||
@ -455,10 +460,8 @@ def reload():
|
||||
|
||||
import hooks
|
||||
imp.reload(hooks)
|
||||
import hooks.manager
|
||||
imp.reload(hooks.manager)
|
||||
import hooks.messagehook
|
||||
imp.reload(hooks.messagehook)
|
||||
|
||||
hooks.reload()
|
||||
|
||||
import importer
|
||||
imp.reload(importer)
|
||||
@ -466,28 +469,24 @@ def reload():
|
||||
import message
|
||||
imp.reload(message)
|
||||
|
||||
message.reload()
|
||||
|
||||
import prompt
|
||||
imp.reload(prompt)
|
||||
import prompt.builtins
|
||||
imp.reload(prompt.builtins)
|
||||
|
||||
prompt.reload()
|
||||
|
||||
import server
|
||||
rl,wl,xl = server._rlist,server._wlist,server._xlist
|
||||
imp.reload(server)
|
||||
server._rlist,server._wlist,server._xlist = rl,wl,xl
|
||||
import server.socket
|
||||
imp.reload(server.socket)
|
||||
import server.IRC
|
||||
imp.reload(server.IRC)
|
||||
|
||||
server.reload()
|
||||
|
||||
import tools
|
||||
imp.reload(tools)
|
||||
import tools.countdown
|
||||
imp.reload(tools.countdown)
|
||||
import tools.date
|
||||
imp.reload(tools.date)
|
||||
import tools.web
|
||||
imp.reload(tools.web)
|
||||
|
||||
tools.reload()
|
||||
|
||||
import xmlparser
|
||||
imp.reload(xmlparser)
|
||||
|
@ -16,6 +16,8 @@
|
||||
# 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
|
||||
|
||||
from exception import IRCException
|
||||
|
||||
def call_game(call, *args, **kargs):
|
||||
@ -74,3 +76,11 @@ def hook(store, *args, **kargs):
|
||||
last_registered.append((store, MessageHook(call, *args, **kargs)))
|
||||
return call
|
||||
return sec
|
||||
|
||||
|
||||
def reload():
|
||||
import hooks.manager
|
||||
imp.reload(hooks.manager)
|
||||
|
||||
import hooks.messagehook
|
||||
imp.reload(hooks.messagehook)
|
||||
|
@ -17,6 +17,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from datetime import datetime, timezone
|
||||
import imp
|
||||
|
||||
class AbstractMessage:
|
||||
|
||||
@ -158,3 +159,13 @@ class OwnerCommand(Command):
|
||||
"""This class represents a special command incomming from the owner"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
def reload():
|
||||
import message.visitor
|
||||
imp.reload(message.visitor)
|
||||
|
||||
import message.printer
|
||||
imp.reload(message.printer)
|
||||
|
||||
message.printer.reload()
|
||||
|
@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Nemubot is a smart and modulable IM bot.
|
||||
# Copyright (C) 2012-2014 nemunaire
|
||||
#
|
||||
# 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
|
||||
|
||||
def reload():
|
||||
import message.printer.IRC
|
||||
imp.reload(message.printer.IRC)
|
@ -101,3 +101,7 @@ class Prompt:
|
||||
|
||||
def hotswap(prompt):
|
||||
return Prompt(prompt.HOOKS_CAPS, prompt.HOOKS_LIST)
|
||||
|
||||
def reload():
|
||||
import prompt.builtins
|
||||
imp.reload(prompt.builtins)
|
||||
|
@ -17,6 +17,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import io
|
||||
import imp
|
||||
import logging
|
||||
import socket
|
||||
import queue
|
||||
@ -143,3 +144,11 @@ class AbstractServer(io.IOBase):
|
||||
"""Exception occurs in fd"""
|
||||
self.logger.warning("Unhandle file descriptor exception on server %s",
|
||||
self.id)
|
||||
|
||||
|
||||
def reload():
|
||||
import server.socket
|
||||
imp.reload(server.socket)
|
||||
|
||||
import server.IRC
|
||||
imp.reload(server.IRC)
|
||||
|
@ -31,3 +31,14 @@ def ipToInt(ip):
|
||||
for b in ip.split("."):
|
||||
sum = 256 * sum + int(b)
|
||||
return sum
|
||||
|
||||
|
||||
def reload():
|
||||
import tools.countdown
|
||||
imp.reload(tools.countdown)
|
||||
|
||||
import tools.date
|
||||
imp.reload(tools.date)
|
||||
|
||||
import tools.web
|
||||
imp.reload(tools.web)
|
||||
|
Loading…
x
Reference in New Issue
Block a user