2015-03-19 12:55:18 -07:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import os
|
2015-04-24 22:37:07 -07:00
|
|
|
import sys
|
|
|
|
|
2015-09-27 12:11:59 -07:00
|
|
|
# This must be done before conf imports, so we get the real conf instead of testing one.
|
2015-09-19 11:55:22 -07:00
|
|
|
os.chdir(os.path.dirname(__file__))
|
2015-08-29 14:19:52 -07:00
|
|
|
import world
|
|
|
|
world.testing = False
|
|
|
|
|
2015-07-05 19:19:49 -07:00
|
|
|
import conf
|
2015-08-29 14:19:52 -07:00
|
|
|
from log import log
|
2015-06-23 19:29:53 -07:00
|
|
|
import classes
|
2015-09-28 19:12:45 -07:00
|
|
|
import utils
|
2015-07-16 21:30:25 -07:00
|
|
|
import coreplugin
|
2015-03-19 12:55:18 -07:00
|
|
|
|
2015-05-31 12:20:09 -07:00
|
|
|
if __name__ == '__main__':
|
2015-09-19 11:51:56 -07:00
|
|
|
log.info('PyLink %s starting...', world.version)
|
2015-07-12 23:28:34 -07:00
|
|
|
|
2015-07-25 16:57:21 -07:00
|
|
|
# Write a PID file.
|
2015-08-03 19:27:19 -07:00
|
|
|
with open('%s.pid' % conf.confname, 'w') as f:
|
2015-07-25 16:57:21 -07:00
|
|
|
f.write(str(os.getpid()))
|
|
|
|
|
2015-07-12 23:28:34 -07: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 12:11:59 -07:00
|
|
|
# Here, we override the module lookup and import the plugins
|
|
|
|
# dynamically depending on which were configured.
|
2015-07-12 23:28:34 -07:00
|
|
|
for plugin in to_load:
|
|
|
|
try:
|
2015-09-28 19:12:45 -07:00
|
|
|
world.plugins[plugin] = pl = utils.loadModuleFromFolder(plugin, world.plugins_folder)
|
2016-01-03 21:05:45 -08:00
|
|
|
except (OSError, ImportError) as e:
|
|
|
|
log.exception('Failed to load plugin %r: %s: %s', plugin, type(e).__name__, str(e))
|
2015-07-12 23:28:34 -07:00
|
|
|
else:
|
|
|
|
if hasattr(pl, 'main'):
|
|
|
|
log.debug('Calling main() function of plugin %r', pl)
|
|
|
|
pl.main()
|
|
|
|
|
2015-12-24 17:33:49 -08: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-15 21:50:23 -08:00
|
|
|
world.networkobjects[network] = irc = classes.Irc(network, proto, conf.conf)
|
2015-12-24 17:33:49 -08:00
|
|
|
|
|
|
|
# Call coreplugin's initialization method
|
2015-12-24 18:08:00 -08:00
|
|
|
log.debug('(%s) Calling main() function of coreplugin', irc.name)
|
2015-11-15 21:50:23 -08:00
|
|
|
coreplugin.main(irc)
|
2015-12-24 17:33:49 -08:00
|
|
|
|
2015-08-29 09:39:33 -07:00
|
|
|
world.started.set()
|
|
|
|
log.info("loaded plugins: %s", world.plugins)
|