3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-25 04:02:45 +01:00

Merge branch 'devel' into wip/unrealircd

This commit is contained in:
James Lu 2015-11-11 18:59:36 -08:00
commit 1eb7ea5116
2 changed files with 29 additions and 24 deletions

View File

@ -47,14 +47,17 @@ def validateConf(conf):
conf['login']['password'] != "changeme", "You have not set the login details correctly!"
return conf
def loadConf(fname):
def loadConf(fname, errors_fatal=True):
"""Loads a PyLink configuration file from the filename given."""
with open(fname, 'r') as f:
try:
conf = yaml.load(f)
except Exception as e:
print('ERROR: Failed to load config from %r: %s: %s' % (fname, type(e).__name__, e))
if errors_fatal:
sys.exit(4)
raise
else:
return conf
if world.testing:

View File

@ -175,18 +175,20 @@ def rehash(irc, source, args):
old_conf = conf.conf.copy()
fname = conf.fname
try:
new_conf = conf.validateConf(conf.loadConf(fname))
new_conf = conf.loadConf(fname, errors_fatal=False)
except Exception as e: # Something went wrong, abort.
log.exception("Error REHASH'ing config: ")
irc.reply("Error loading configuration file: %s: %s", type(e).__name__, e)
irc.reply("Error loading configuration file: %s: %s" % (type(e).__name__, e))
return
else:
new_conf = conf.validateConf(new_conf)
conf.conf = new_conf
for network, ircobj in world.networkobjects.copy().items():
# Server was removed from the config file, disconnect them.
log.debug('(%s) rehash: checking if %r is in new conf still.', irc.name, network)
if network not in new_conf['servers']:
# Disable autoconnect first.
log.debug('(%s) rehash: removing connection to %r (removed from config).', irc.name, network)
# Disable autoconnect first.
ircobj.serverdata['autoconnect'] = -1
ircobj.aborted.set()
del world.networkobjects[network]