diff --git a/launcher.py b/launcher.py index 3233660..f4e164d 100644 --- a/launcher.py +++ b/launcher.py @@ -14,32 +14,9 @@ try: except ImportError: psutil = None -def main(): - 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("-c", "--check-pid", help="no-op; kept for compatiblity with PyLink 1.x", action='store_true') - parser.add_argument("-n", "--no-pid", help="skips generating and checking PID files", action='store_true') - parser.add_argument("-r", "--restart", help="restarts the PyLink instance with the given config file", action='store_true') - parser.add_argument("-s", "--stop", help="stops the PyLink instance with the given config file", action='store_true') - parser.add_argument("-R", "--rehash", help="rehashes the PyLink instance with the given config file", action='store_true') - parser.add_argument("-d", "--daemonize", help="[experimental] daemonizes the PyLink instance on POSIX systems", action='store_true') - args = parser.parse_args() - - if args.version: # Display version and exit - print('PyLink %s (in VCS: %s)' % (__version__, real_version)) - sys.exit() - - # XXX: repetitive - elif args.no_pid and (args.restart or args.stop or args.rehash): - print('ERROR: --no-pid cannot be combined with --restart or --stop') - sys.exit(1) - elif args.rehash and os.name != 'posix': - print('ERROR: Rehashing via the command line is not supported outside Unix.') - sys.exit(1) +args = {} +def _main(): # FIXME: we can't pass logging on to conf until we set up the config... conf.load_conf(args.config) @@ -178,3 +155,42 @@ def main(): world.started.set() log.info("Loaded plugins: %s", ', '.join(sorted(world.plugins.keys()))) selectdriver.start() + +def main(): + import argparse + + global args + + 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("-c", "--check-pid", help="no-op; kept for compatiblity with PyLink 1.x", action='store_true') + parser.add_argument("-n", "--no-pid", help="skips generating and checking PID files", action='store_true') + parser.add_argument("-r", "--restart", help="restarts the PyLink instance with the given config file", action='store_true') + parser.add_argument("-s", "--stop", help="stops the PyLink instance with the given config file", action='store_true') + parser.add_argument("-R", "--rehash", help="rehashes the PyLink instance with the given config file", action='store_true') + parser.add_argument("-d", "--daemonize", help="[experimental] daemonizes the PyLink instance on POSIX systems", action='store_true') + parser.add_argument("-t", "--trace", help="traces through running Python code; do not use in production instances!", action='store_true') + parser.add_argument('--trace-ignore-mods', help='comma-separated list of extra modules to ignore when tracing', action='store', default='') + parser.add_argument('--trace-ignore-dirs', help='comma-separated list of extra directories to ignore when tracing', action='store', default='') + args = parser.parse_args() + + if args.version: # Display version and exit + print('PyLink %s (in VCS: %s)' % (__version__, real_version)) + sys.exit() + + # XXX: repetitive + elif args.no_pid and (args.restart or args.stop or args.rehash): + print('ERROR: --no-pid cannot be combined with --restart or --stop') + sys.exit(1) + elif args.rehash and os.name != 'posix': + print('ERROR: Rehashing via the command line is not supported outside Unix.') + sys.exit(1) + + if args.trace: + import trace + tracer = trace.Trace(ignoremods=args.trace_ignore_mods.split(','), + ignoredirs=args.trace_ignore_dirs.split(',')) + tracer.runctx('_main()', globals=globals(), locals=locals()) + else: + _main()