2016-04-02 03:21:33 +02:00
|
|
|
#!/usr/bin/env python3
|
2016-06-24 07:51:40 +02:00
|
|
|
"""
|
|
|
|
PyLink IRC Services launcher.
|
|
|
|
"""
|
2015-03-19 20:55:18 +01:00
|
|
|
|
|
|
|
import os
|
2016-06-21 19:27:36 +02:00
|
|
|
import sys
|
|
|
|
try:
|
2016-07-20 02:45:43 +02:00
|
|
|
from pylinkirc import world
|
2016-06-21 19:27:36 +02:00
|
|
|
except ImportError:
|
2016-06-21 20:03:28 +02:00
|
|
|
sys.stderr.write("ERROR: Failed to import PyLink main module (pylinkirc.world).\n\nIf you are "
|
2016-06-21 19:27:36 +02:00
|
|
|
"running PyLink from source, please install PyLink first using 'python3 "
|
|
|
|
"setup.py install [--user]'\n")
|
|
|
|
sys.exit(1)
|
2016-07-20 02:45:43 +02:00
|
|
|
from pylinkirc import conf, __version__
|
2015-03-19 20:55:18 +01:00
|
|
|
|
2015-05-31 21:20:09 +02:00
|
|
|
if __name__ == '__main__':
|
2016-06-21 19:55:42 +02:00
|
|
|
import argparse
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='Starts an instance of PyLink IRC Services.')
|
|
|
|
parser.add_argument('config', help='specifies the path to the config file (defaults to pylink.yml)', nargs='?', default='pylink.yml')
|
|
|
|
parser.add_argument("-v", "--version", help="displays the program version and exits", action='store_true')
|
|
|
|
parser.add_argument("-n", "--no-pid", help="skips generating PID files", action='store_true')
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2016-06-21 20:03:28 +02:00
|
|
|
if args.version: # Display version and exit
|
2016-07-03 09:26:03 +02:00
|
|
|
print('PyLink ' + __version__)
|
2016-06-21 20:03:28 +02:00
|
|
|
sys.exit()
|
|
|
|
|
2016-06-21 19:55:42 +02:00
|
|
|
# Load the config
|
|
|
|
conf.loadConf(args.config)
|
|
|
|
|
|
|
|
from pylinkirc.log import log
|
2016-06-24 07:51:40 +02:00
|
|
|
from pylinkirc import classes, utils, coremods
|
2016-07-03 09:26:03 +02:00
|
|
|
log.info('PyLink %s starting...', __version__)
|
2015-07-13 08:28:34 +02:00
|
|
|
|
2016-06-21 20:03:28 +02:00
|
|
|
# Write a PID file unless specifically told not to.
|
|
|
|
if not args.no_pid:
|
|
|
|
with open('%s.pid' % conf.confname, 'w') as f:
|
|
|
|
f.write(str(os.getpid()))
|
2015-07-26 01:57:21 +02:00
|
|
|
|
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:
|
2016-07-03 08:57:20 +02:00
|
|
|
world.plugins[plugin] = pl = utils.loadPlugin(plugin)
|
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())))
|