3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-24 03:29:28 +01:00

core: use a shared function for disconnecting + removing networks

This commit is contained in:
James Lu 2016-07-01 20:08:38 -07:00
parent 013891bebc
commit 847a98755f
2 changed files with 12 additions and 16 deletions

View File

@ -7,6 +7,13 @@ import os
from pylinkirc import world, utils, conf, classes from pylinkirc import world, utils, conf, classes
from pylinkirc.log import log from pylinkirc.log import log
def remove_network(ircobj):
"""Removes a network object from the pool."""
# Disable autoconnect first by setting the delay negative.
ircobj.serverdata['autoconnect'] = -1
ircobj.disconnect()
del world.networkobjects[ircobj.name]
def _shutdown(irc=None): def _shutdown(irc=None):
"""Shuts down the Pylink daemon.""" """Shuts down the Pylink daemon."""
for name, plugin in world.plugins.items(): for name, plugin in world.plugins.items():
@ -19,10 +26,8 @@ def _shutdown(irc=None):
log.exception('coreplugin: Error occurred in die() of plugin %s, skipping...', name) log.exception('coreplugin: Error occurred in die() of plugin %s, skipping...', name)
for ircobj in world.networkobjects.values(): for ircobj in world.networkobjects.values():
# Disconnect all our networks. Disable auto-connect first by setting # Disconnect all our networks.
# the time to negative. remove_network(ircobj)
ircobj.serverdata['autoconnect'] = -1
ircobj.disconnect()
def sigterm_handler(_signo, _stack_frame): def sigterm_handler(_signo, _stack_frame):
"""Handles SIGTERM gracefully by shutting down the PyLink daemon.""" """Handles SIGTERM gracefully by shutting down the PyLink daemon."""
@ -43,10 +48,7 @@ def _rehash():
log.debug('rehash: checking if %r is in new conf still.', network) log.debug('rehash: checking if %r is in new conf still.', network)
if network not in new_conf['servers']: if network not in new_conf['servers']:
log.debug('rehash: removing connection to %r (removed from config).', network) log.debug('rehash: removing connection to %r (removed from config).', network)
# Disable autoconnect first. remove_network(ircobj)
ircobj.serverdata['autoconnect'] = -1
ircobj.disconnect()
del world.networkobjects[network]
else: else:
ircobj.conf = new_conf ircobj.conf = new_conf
ircobj.serverdata = new_conf['servers'][network] ircobj.serverdata = new_conf['servers'][network]

View File

@ -3,6 +3,7 @@ import threading
from pylinkirc import utils, world, conf, classes from pylinkirc import utils, world, conf, classes
from pylinkirc.log import log from pylinkirc.log import log
from pylinkirc.coremods import control
@utils.add_cmd @utils.add_cmd
def disconnect(irc, source, args): def disconnect(irc, source, args):
@ -22,14 +23,7 @@ def disconnect(irc, source, args):
return return
irc.reply("Done. If you want to reconnect this network, use the 'rehash' command.") irc.reply("Done. If you want to reconnect this network, use the 'rehash' command.")
# Cancel autoconnect. control.remove_network(network)
network.serverdata["autoconnect"] = -1
# Abort the connection.
network.disconnect()
# Remove the dead network object.
del world.networkobjects[netname]
@utils.add_cmd @utils.add_cmd
def autoconnect(irc, source, args): def autoconnect(irc, source, args):