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.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):
|
||||
"""Shuts down the Pylink daemon."""
|
||||
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)
|
||||
|
||||
for ircobj in world.networkobjects.values():
|
||||
# Disconnect all our networks. Disable auto-connect first by setting
|
||||
# the time to negative.
|
||||
ircobj.serverdata['autoconnect'] = -1
|
||||
ircobj.disconnect()
|
||||
# Disconnect all our networks.
|
||||
remove_network(ircobj)
|
||||
|
||||
def sigterm_handler(_signo, _stack_frame):
|
||||
"""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)
|
||||
if network not in new_conf['servers']:
|
||||
log.debug('rehash: removing connection to %r (removed from config).', network)
|
||||
# Disable autoconnect first.
|
||||
ircobj.serverdata['autoconnect'] = -1
|
||||
ircobj.disconnect()
|
||||
del world.networkobjects[network]
|
||||
remove_network(ircobj)
|
||||
else:
|
||||
ircobj.conf = new_conf
|
||||
ircobj.serverdata = new_conf['servers'][network]
|
||||
|
@ -3,6 +3,7 @@ import threading
|
||||
|
||||
from pylinkirc import utils, world, conf, classes
|
||||
from pylinkirc.log import log
|
||||
from pylinkirc.coremods import control
|
||||
|
||||
@utils.add_cmd
|
||||
def disconnect(irc, source, args):
|
||||
@ -22,14 +23,7 @@ def disconnect(irc, source, args):
|
||||
return
|
||||
irc.reply("Done. If you want to reconnect this network, use the 'rehash' command.")
|
||||
|
||||
# Cancel autoconnect.
|
||||
network.serverdata["autoconnect"] = -1
|
||||
|
||||
# Abort the connection.
|
||||
network.disconnect()
|
||||
|
||||
# Remove the dead network object.
|
||||
del world.networkobjects[netname]
|
||||
control.remove_network(network)
|
||||
|
||||
@utils.add_cmd
|
||||
def autoconnect(irc, source, args):
|
||||
|
Loading…
Reference in New Issue
Block a user