1
0
Fork 0

Remove reload feature

As reload shoudl be done in a particular order, to keep valid types, and because maintaining such system is too complex (currently, it doesn't work for a while), now, a reload is just reload configuration file (and possibly modules)
This commit is contained in:
nemunaire 2016-03-27 20:34:12 +01:00
parent 6cd299ab60
commit 7cf73fb84a
12 changed files with 1 additions and 245 deletions

View File

@ -133,66 +133,3 @@ def daemonize():
os.dup2(si.fileno(), sys.stdin.fileno())
os.dup2(so.fileno(), sys.stdout.fileno())
os.dup2(se.fileno(), sys.stderr.fileno())
def reload():
"""Reload code of all Python modules used by nemubot
"""
import imp
import nemubot.bot
imp.reload(nemubot.bot)
import nemubot.channel
imp.reload(nemubot.channel)
import nemubot.config
imp.reload(nemubot.config)
nemubot.config.reload()
import nemubot.consumer
imp.reload(nemubot.consumer)
import nemubot.datastore
imp.reload(nemubot.datastore)
nemubot.datastore.reload()
import nemubot.event
imp.reload(nemubot.event)
import nemubot.exception
imp.reload(nemubot.exception)
nemubot.exception.reload()
import nemubot.hooks
imp.reload(nemubot.hooks)
nemubot.hooks.reload()
import nemubot.importer
imp.reload(nemubot.importer)
import nemubot.message
imp.reload(nemubot.message)
nemubot.message.reload()
import nemubot.server
rl = nemubot.server._rlist
wl = nemubot.server._wlist
xl = nemubot.server._xlist
imp.reload(nemubot.server)
nemubot.server._rlist = rl
nemubot.server._wlist = wl
nemubot.server._xlist = xl
nemubot.server.reload()
import nemubot.tools
imp.reload(nemubot.tools)
nemubot.tools.reload()

View File

@ -158,24 +158,10 @@ def main():
def sighuphandler(signum, frame):
"""On SIGHUP, perform a deep reload"""
import imp
nonlocal nemubot, context, module_finder
nonlocal context
logger.debug("SIGHUP receive, iniate reload procedure...")
# Reload nemubot Python modules
imp.reload(nemubot)
nemubot.reload()
# Hotswap context
import nemubot.bot
context = nemubot.bot.hotswap(context)
# Reload ModuleFinder
sys.meta_path.remove(module_finder)
module_finder = ModuleFinder(context.modules_paths, context.add_module)
sys.meta_path.append(module_finder)
# Reload configuration file
for path in args.files:
if os.path.isfile(path):

View File

@ -564,22 +564,3 @@ class Bot(threading.Thread):
del store[hook.name]
elif isinstance(store, list):
store.remove(hook)
def hotswap(bak):
bak.stop = True
if bak.event_timer is not None:
bak.event_timer.cancel()
# Unload modules
for mod in [k for k in bak.modules.keys()]:
bak.unload_module(mod)
# Save datastore
bak.datastore.close()
new = Bot(str(bak.ip), bak.modules_paths, bak.datastore)
new.servers = bak.servers
new._update_event_timer()
return new

View File

@ -24,24 +24,3 @@ from nemubot.config.include import Include
from nemubot.config.module import Module
from nemubot.config.nemubot import Nemubot
from nemubot.config.server import Server
def reload():
global Include, Module, Nemubot, Server
import imp
import nemubot.config.include
imp.reload(nemubot.config.include)
Include = nemubot.config.include.Include
import nemubot.config.module
imp.reload(nemubot.config.module)
Module = nemubot.config.module.Module
import nemubot.config.nemubot
imp.reload(nemubot.config.nemubot)
Nemubot = nemubot.config.nemubot.Nemubot
import nemubot.config.server
imp.reload(nemubot.config.server)
Server = nemubot.config.server.Server

View File

@ -16,16 +16,3 @@
from nemubot.datastore.abstract import Abstract
from nemubot.datastore.xml import XML
def reload():
global Abstract, XML
import imp
import nemubot.datastore.abstract
imp.reload(nemubot.datastore.abstract)
Abstract = nemubot.datastore.abstract.Abstract
import nemubot.datastore.xml
imp.reload(nemubot.datastore.xml)
XML = nemubot.datastore.xml.XML

View File

@ -32,10 +32,3 @@ class IMException(Exception):
from nemubot.message import Text
return Text(*self.args,
server=msg.server, to=msg.to_response)
def reload():
import imp
import nemubot.exception.Keyword
imp.reload(nemubot.exception.printer.IRC)

View File

@ -49,23 +49,3 @@ class hook:
def pre(*args, store=["pre"], **kwargs):
return hook._add(store, Abstract, *args, **kwargs)
def reload():
import imp
import nemubot.hooks.abstract
imp.reload(nemubot.hooks.abstract)
import nemubot.hooks.command
imp.reload(nemubot.hooks.command)
import nemubot.hooks.message
imp.reload(nemubot.hooks.message)
import nemubot.hooks.keywords
imp.reload(nemubot.hooks.keywords)
nemubot.hooks.keywords.reload()
import nemubot.hooks.manager
imp.reload(nemubot.hooks.manager)

View File

@ -45,13 +45,3 @@ class AnyKeyword(Abstract):
def help(self):
return self.h
def reload():
import imp
import nemubot.hooks.keywords.abstract
imp.reload(nemubot.hooks.keywords.abstract)
import nemubot.hooks.keywords.dict
imp.reload(nemubot.hooks.keywords.dict)

View File

@ -19,27 +19,3 @@ from nemubot.message.text import Text
from nemubot.message.directask import DirectAsk
from nemubot.message.command import Command
from nemubot.message.command import OwnerCommand
def reload():
global Abstract, Text, DirectAsk, Command, OwnerCommand
import imp
import nemubot.message.abstract
imp.reload(nemubot.message.abstract)
Abstract = nemubot.message.abstract.Abstract
imp.reload(nemubot.message.text)
Text = nemubot.message.text.Text
imp.reload(nemubot.message.directask)
DirectAsk = nemubot.message.directask.DirectAsk
imp.reload(nemubot.message.command)
Command = nemubot.message.command.Command
OwnerCommand = nemubot.message.command.OwnerCommand
import nemubot.message.visitor
imp.reload(nemubot.message.visitor)
import nemubot.message.printer
imp.reload(nemubot.message.printer)
nemubot.message.printer.reload()

View File

@ -13,12 +13,3 @@
#
# 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/>.
def reload():
import imp
import nemubot.message.printer.IRC
imp.reload(nemubot.message.printer.IRC)
import nemubot.message.printer.socket
imp.reload(nemubot.message.printer.socket)

View File

@ -68,21 +68,3 @@ def factory(uri, **init_args):
return IRCServer(**args)
else:
return None
def reload():
import imp
import nemubot.server.abstract
imp.reload(nemubot.server.abstract)
import nemubot.server.socket
imp.reload(nemubot.server.socket)
import nemubot.server.IRC
imp.reload(nemubot.server.IRC)
import nemubot.server.message
imp.reload(nemubot.server.message)
nemubot.server.message.reload()

View File

@ -13,29 +13,3 @@
#
# 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/>.
def reload():
import imp
import nemubot.tools.config
imp.reload(nemubot.tools.config)
import nemubot.tools.countdown
imp.reload(nemubot.tools.countdown)
import nemubot.tools.feed
imp.reload(nemubot.tools.feed)
import nemubot.tools.date
imp.reload(nemubot.tools.date)
import nemubot.tools.human
imp.reload(nemubot.tools.human)
import nemubot.tools.web
imp.reload(nemubot.tools.web)
import nemubot.tools.xmlparser
imp.reload(nemubot.tools.xmlparser)
import nemubot.tools.xmlparser.node
imp.reload(nemubot.tools.xmlparser.node)