mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-27 21:19:31 +01:00
core: use a shared function for disconnecting + removing networks
This commit is contained in:
parent
013891bebc
commit
847a98755f
@ -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]
|
||||||
|
@ -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):
|
||||||
|
Loading…
Reference in New Issue
Block a user