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-07-05 22:22:17 +02:00
|
|
|
from log import log
|
2015-07-06 04:19:49 +02:00
|
|
|
import conf
|
2015-06-24 04:29:53 +02:00
|
|
|
import classes
|
2015-07-10 03:29:00 +02:00
|
|
|
import utils
|
2015-07-17 06:30:25 +02:00
|
|
|
import coreplugin
|
2015-08-29 04:27:38 +02:00
|
|
|
import world
|
2015-03-19 20:55:18 +01:00
|
|
|
|
2015-05-31 21:20:09 +02:00
|
|
|
if __name__ == '__main__':
|
2015-08-29 04:27:38 +02:00
|
|
|
world.testing = False
|
2015-07-05 22:44:48 +02:00
|
|
|
log.info('PyLink starting...')
|
2015-07-06 04:19:49 +02:00
|
|
|
if conf.conf['login']['password'] == 'changeme':
|
2015-07-05 22:44:48 +02:00
|
|
|
log.critical("You have not set the login details correctly! Exiting...")
|
2015-06-17 05:05:41 +02:00
|
|
|
sys.exit(2)
|
|
|
|
protocols_folder = [os.path.join(os.getcwd(), 'protocols')]
|
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.
|
2015-08-29 18:39:33 +02:00
|
|
|
world.plugins.append(coreplugin)
|
2015-07-13 08:28:34 +02:00
|
|
|
to_load = conf.conf['plugins']
|
|
|
|
plugins_folder = [os.path.join(os.getcwd(), 'plugins')]
|
|
|
|
# Here, we override the module lookup and import the plugins
|
|
|
|
# dynamically depending on which were configured.
|
|
|
|
for plugin in to_load:
|
|
|
|
try:
|
|
|
|
moduleinfo = imp.find_module(plugin, plugins_folder)
|
|
|
|
pl = imp.load_source(plugin, moduleinfo[1])
|
2015-08-29 18:39:33 +02:00
|
|
|
world.plugins.append(pl)
|
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']:
|
|
|
|
protoname = conf.conf['servers'][network]['protocol']
|
|
|
|
try:
|
|
|
|
moduleinfo = imp.find_module(protoname, protocols_folder)
|
|
|
|
proto = imp.load_source(protoname, moduleinfo[1])
|
|
|
|
except ImportError as e:
|
2015-08-23 06:00:29 +02:00
|
|
|
if str(e) == ('No module named %r' % protoname):
|
|
|
|
log.critical('Failed to load protocol module %r: The file could not be found.', protoname)
|
2015-07-10 03:29:00 +02:00
|
|
|
else:
|
2015-08-23 06:00:29 +02:00
|
|
|
log.critical('Failed to load protocol module: ImportError: %s', protoname, str(e))
|
2015-07-10 03:29:00 +02:00
|
|
|
sys.exit(2)
|
2015-06-17 05:05:41 +02:00
|
|
|
else:
|
2015-08-29 23:18:00 +02:00
|
|
|
world.networkobjects[network] = classes.Irc(network, proto)
|
2015-08-29 18:39:33 +02:00
|
|
|
world.started.set()
|
|
|
|
log.info("loaded plugins: %s", world.plugins)
|
2015-07-13 08:28:34 +02:00
|
|
|
|