23from .
import __title__, __version__, __version_date__, api, inputs, outputs, search
109 (__title__, __version__, __version_date__),
129 dest=
"WRITE_OPTIONS", default=argparse.SUPPRESS, help=argparse.SUPPRESS),
357 dest=
"TIMESCALE", metavar=
"FACTOR", nargs=
"?", type=float, const=1, default=0,
408 """Imports and initializes plugins from auto-load folder and from arguments."""
410 (
"overwrite=true|false",
"overwrite existing file\nin bag output\n"
411 "instead of appending to if bag or database\n"
412 "or appending unique counter to file name\n"
415 ] + outputs.RolloverSinkMixin.get_write_options(
"bag"))
417 if "--plugin" in cli_args:
418 args, _ = ArgumentUtil.make_parser(ARGUMENTS).parse_known_args(cli_args)
419 args = ArgumentUtil.flatten(args)
420 try: plugins.init(args)
421 except ImportWarning: sys.exit(1)
425 """Returns thread exception handler: function(text, exc) prints error, stops application."""
426 def thread_excepthook(text, exc):
427 """Prints error, sets exitcode flag, shuts down ROS node if any, interrupts main thread."""
428 ConsolePrinter.error(text)
429 if args.VERBOSE: traceback.print_exc()
430 exitcode_dict[
"value"] = 1
432 os.kill(os.getpid(), signal.SIGINT)
433 return thread_excepthook
437 """Parses command-line arguments and runs search."""
439 CLI_ARGS = sys.argv[1:]
440 MatchMarkers.populate(
"%08x" % random.randint(1, 10**9))
442 argparser = ArgumentUtil.make_parser(ARGUMENTS)
444 argparser.print_usage()
447 atexit.register(flush_stdout)
448 args = argparser.parse_args(CLI_ARGS)
450 argparser.print_help()
453 BREAK_EXS = (KeyboardInterrupt, )
454 try: BREAK_EXS += (BrokenPipeError, )
455 except NameError:
pass
457 exitcode = {
"value": 0}
458 source, sink =
None,
None
460 ConsolePrinter.configure({
"always":
True,
"never":
False}.get(args.COLOR))
462 args = ArgumentUtil.validate(args, cli=
True)
464 source = plugins.load(
"source", args)
or \
466 if not source.validate():
469 sink.sinks.extend(filter(bool, plugins.load(
"sink", args, collect=
True)))
470 if not sink.validate():
475 grepper.work(source, sink)
477 try: sink
and sink.close()
478 except (Exception, KeyboardInterrupt):
pass
479 try: source
and source.close()
480 except (Exception, KeyboardInterrupt):
pass
482 try: os.dup2(os.open(os.devnull, os.O_WRONLY), sys.stdout.fileno())
483 except (Exception, KeyboardInterrupt):
pass
484 sys.exit(exitcode[
"value"])
485 except Exception
as e:
486 ConsolePrinter.error(e)
487 if args.VERBOSE: traceback.print_exc()
489 sink
and sink.close()
490 source
and source.close()
491 try: api.shutdown_node()
492 except BREAK_EXS:
pass
make_thread_excepthook(args, exitcode_dict)
preload_plugins(cli_args)