3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 01:09:22 +01:00
PyLink/pylink

51 lines
1.8 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env python3
2015-03-19 20:55:18 +01:00
import os
import sys
# This must be done before conf imports, so we get the real conf instead of testing one.
try:
from pylinkirc import world
except ImportError:
sys.stderr.write("ERROR: Failed to import PyLink main module (pylinkirc.world).\n\nIf you are "
"running PyLink from source, please install PyLink first using 'python3 "
"setup.py install [--user]'\n")
sys.exit(1)
world.testing = False
from pylinkirc import conf, classes, utils, coreplugin
from pylinkirc.log import log
2015-03-19 20:55:18 +01:00
if __name__ == '__main__':
2015-09-19 20:51:56 +02:00
log.info('PyLink %s starting...', world.version)
2015-07-26 01:57:21 +02:00
# Write a PID file.
with open('%s.pid' % conf.confname, 'w') as f:
2015-07-26 01:57:21 +02:00
f.write(str(os.getpid()))
# Import plugins first globally, because they can listen for events
# that happen before the connection phase.
to_load = conf.conf['plugins']
# Here, we override the module lookup and import the plugins
# dynamically depending on which were configured.
for plugin in to_load:
try:
world.plugins[plugin] = pl = utils.loadModuleFromFolder(plugin, world.plugins_folder)
except (OSError, ImportError) as e:
log.exception('Failed to load plugin %r: %s: %s', plugin, type(e).__name__, str(e))
else:
if hasattr(pl, 'main'):
log.debug('Calling main() function of plugin %r', pl)
pl.main()
# Initialize all the networks one by one
for network, sdata in conf.conf['servers'].items():
protoname = sdata['protocol']
# Fetch the correct protocol module
proto = utils.getProtocolModule(protoname)
world.networkobjects[network] = irc = classes.Irc(network, proto, conf.conf)
world.started.set()
log.info("Loaded plugins: %s", ', '.join(sorted(world.plugins.keys())))