2015-03-19 20:55:18 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import imp
|
|
|
|
import os
|
2015-04-25 07:37:07 +02:00
|
|
|
import sys
|
|
|
|
|
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.
|
2015-09-19 20:55:22 +02:00
|
|
|
os.chdir(os.path.dirname(__file__))
|
2015-08-29 23:19:52 +02:00
|
|
|
import world
|
|
|
|
world.testing = False
|
|
|
|
|
2015-07-06 04:19:49 +02:00
|
|
|
import conf
|
2015-08-29 23:19:52 +02:00
|
|
|
from log import log
|
2015-06-24 04:29:53 +02:00
|
|
|
import classes
|
2015-09-29 04:12:45 +02:00
|
|
|
import utils
|
2015-07-17 06:30:25 +02:00
|
|
|
import coreplugin
|
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)
|
2015-07-13 08:28:34 +02:00
|
|
|
except ImportError as e:
|
2015-08-23 06:00:29 +02:00
|
|
|
if str(e) == ('No module named %r' % plugin):
|
|
|
|
log.error('Failed to load plugin %r: The plugin could not be found.', plugin)
|
2015-07-13 08:28:34 +02:00
|
|
|
else:
|
2015-08-23 06:00:29 +02:00
|
|
|
log.error('Failed to load plugin %r: ImportError: %s', plugin, 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-07-10 03:29:00 +02:00
|
|
|
for network in conf.conf['servers']:
|
2015-09-29 04:12:45 +02:00
|
|
|
proto = utils.getProtoModule(conf.conf['servers'][network]['protocol'])
|
|
|
|
world.networkobjects[network] = classes.Irc(network, proto, conf.conf)
|
2015-08-29 18:39:33 +02:00
|
|
|
world.started.set()
|
|
|
|
log.info("loaded plugins: %s", world.plugins)
|