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 19:44:52 +02:00
|
|
|
# cd into the PyLink root directory first...
|
2015-09-19 20:55:22 +02:00
|
|
|
os.chdir(os.path.dirname(__file__))
|
2015-09-27 19:44:52 +02:00
|
|
|
|
2015-08-29 23:19:52 +02:00
|
|
|
import world
|
2015-09-27 19:44:52 +02:00
|
|
|
|
|
|
|
# This must be set before conf imports, so we get the real conf instead of testing one.
|
2015-08-29 23:19:52 +02:00
|
|
|
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-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-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)
|
2015-09-27 19:44:52 +02:00
|
|
|
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.
|
|
|
|
to_load = conf.conf['plugins']
|
2015-09-27 19:44:52 +02:00
|
|
|
plugins_folder = os.path.join(os.getcwd(), 'plugins')
|
|
|
|
sys.path.extend([plugins_folder, protocols_folder])
|
2015-07-13 08:28:34 +02:00
|
|
|
for plugin in to_load:
|
|
|
|
try:
|
2015-09-27 19:44:52 +02:00
|
|
|
world.plugins[plugin] = pl = __import__(plugin)
|
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:
|
2015-09-27 19:44:52 +02:00
|
|
|
proto = __import__(protoname)
|
2015-07-10 03:29:00 +02:00
|
|
|
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-09-27 19:44:52 +02:00
|
|
|
world.networkobjects[network] = irc = classes.Irc(network, proto)
|
|
|
|
irc.plugins_folder = plugins_folder
|
2015-08-29 18:39:33 +02:00
|
|
|
world.started.set()
|
|
|
|
log.info("loaded plugins: %s", world.plugins)
|