2016-04-02 03:21:33 +02:00
|
|
|
#!/usr/bin/env python3
|
2015-03-19 20:55:18 +01:00
|
|
|
|
|
|
|
import os
|
2016-06-21 19:27:36 +02:00
|
|
|
import sys
|
|
|
|
try:
|
2016-06-21 19:55:42 +02:00
|
|
|
from pylinkirc import conf
|
2016-06-21 19:27:36 +02:00
|
|
|
except ImportError:
|
2016-06-21 19:55:42 +02:00
|
|
|
sys.stderr.write("ERROR: Failed to import PyLink main module (pylinkirc.conf).\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)
|
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()
|
|
|
|
|
|
|
|
# Load the config
|
|
|
|
conf.loadConf(args.config)
|
|
|
|
|
|
|
|
from pylinkirc.log import log
|
|
|
|
from pylinkirc import classes, utils, coreplugin, world
|
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)
|
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())))
|