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 "
|
2016-07-21 09:02:37 +02:00
|
|
|
"setup.py install' (global install) or 'python3 setup.py install --user'"
|
|
|
|
" (local install)\n")
|
2016-06-21 19:27:36 +02:00
|
|
|
sys.exit(1)
|
2016-08-23 16:28:48 +02:00
|
|
|
from pylinkirc import conf, __version__, real_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')
|
2016-11-15 06:38:02 +01:00
|
|
|
parser.add_argument("-c", "--no-check-pid", help="disables PID file checking", action='store_true')
|
2016-06-21 19:55:42 +02:00
|
|
|
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-08-23 16:28:48 +02:00
|
|
|
print('PyLink %s (in VCS: %s)' % (__version__, real_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-10-15 22:09:35 +02:00
|
|
|
# Check for a pid file, unless told not to,
|
|
|
|
# this stops instance overlap, which wrecks clientbots
|
2016-11-17 06:52:07 +01:00
|
|
|
if not args.no_check_pid:
|
2016-10-15 22:09:35 +02:00
|
|
|
config = conf.confname
|
|
|
|
if os.path.exists("%s.pid" % config):
|
2016-10-15 23:34:21 +02:00
|
|
|
log.error("PID file exists; aborting! If PyLink didn't shut down cleanly last time it "
|
|
|
|
"was run, or you're upgrading from PyLink < 1.1-dev, delete %s.pid and try "
|
|
|
|
"again." % config)
|
2016-10-15 23:23:29 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
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():
|
|
|
|
|
2016-07-29 06:33:13 +02:00
|
|
|
try:
|
|
|
|
protoname = sdata['protocol']
|
|
|
|
except (KeyError, TypeError):
|
|
|
|
log.error("(%s) Configuration error: No protocol module specified, aborting.", network)
|
|
|
|
else:
|
|
|
|
# Fetch the correct protocol module
|
|
|
|
proto = utils.getProtocolModule(protoname)
|
|
|
|
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())))
|
2016-08-25 21:07:55 +02:00
|
|
|
|
|
|
|
from pylinkirc import coremods
|
|
|
|
coremods.permissions.resetPermissions()
|