2016-04-02 03:21:33 +02:00
|
|
|
#!/usr/bin/env python3
|
2015-03-19 20:55:18 +01:00
|
|
|
|
|
|
|
import os
|
2016-03-28 06:24:55 +02:00
|
|
|
|
2015-09-27 21:11:59 +02:00
|
|
|
# This must be done before conf imports, so we get the real conf instead of testing one.
|
2016-06-21 03:18:54 +02:00
|
|
|
from pylinkirc import world
|
2015-08-29 23:19:52 +02:00
|
|
|
world.testing = False
|
|
|
|
|
2016-06-21 03:18:54 +02:00
|
|
|
from pylinkirc import conf, classes, utils, coreplugin
|
|
|
|
from pylinkirc.log import log
|
2015-03-19 20:55:18 +01:00
|
|
|
|
2015-05-31 21:20:09 +02:00
|
|
|
if __name__ == '__main__':
|
2015-09-19 20:51:56 +02:00
|
|
|
log.info('PyLink %s starting...', world.version)
|
2015-07-13 08:28:34 +02:00
|
|
|
|
2015-07-26 01:57:21 +02:00
|
|
|
# Write a PID file.
|
2015-08-04 04:27:19 +02:00
|
|
|
with open('%s.pid' % conf.confname, 'w') as f:
|
2015-07-26 01:57:21 +02:00
|
|
|
f.write(str(os.getpid()))
|
|
|
|
|
2015-07-13 08:28:34 +02:00
|
|
|
# Import plugins first globally, because they can listen for events
|
|
|
|
# that happen before the connection phase.
|
|
|
|
to_load = conf.conf['plugins']
|
2015-09-27 21:11:59 +02:00
|
|
|
# Here, we override the module lookup and import the plugins
|
|
|
|
# dynamically depending on which were configured.
|
2015-07-13 08:28:34 +02:00
|
|
|
for plugin in to_load:
|
|
|
|
try:
|
2015-09-29 04:12:45 +02:00
|
|
|
world.plugins[plugin] = pl = utils.loadModuleFromFolder(plugin, world.plugins_folder)
|
2016-01-04 06:05:45 +01:00
|
|
|
except (OSError, ImportError) as e:
|
|
|
|
log.exception('Failed to load plugin %r: %s: %s', plugin, type(e).__name__, str(e))
|
2015-07-13 08:28:34 +02:00
|
|
|
else:
|
|
|
|
if hasattr(pl, 'main'):
|
|
|
|
log.debug('Calling main() function of plugin %r', pl)
|
|
|
|
pl.main()
|
|
|
|
|
2015-12-25 02:33:49 +01:00
|
|
|
# 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)
|
2015-11-16 06:50:23 +01:00
|
|
|
world.networkobjects[network] = irc = classes.Irc(network, proto, conf.conf)
|
2015-12-25 02:33:49 +01:00
|
|
|
|
2015-08-29 18:39:33 +02:00
|
|
|
world.started.set()
|
2016-03-27 00:29:17 +01:00
|
|
|
log.info("Loaded plugins: %s", ', '.join(sorted(world.plugins.keys())))
|