519def main():
520 parser = argparse.ArgumentParser(description="Generate ADC web posts from ldms json stream files.")
521 parser.add_argument("--url", default=None, help="where to post messages (or full path for debug output)")
522 try:
523 parser.add_argument("--validate", default=False, help="verify input is well-formed json before posting", action=argparse.BooleanOptionalAction)
524 parser.add_argument("--retry", default=False, help="whether to publish the retry indices found in retry-dir files instead of all indices", action=argparse.BooleanOptionalAction)
525 except:
526 print("Need python with argparse.BooleanOptionalAction; usually py >= 3.9")
527 return 1
528 parser.add_argument("--completed-dir", default=None, help="where to put index numbers of messages that the server accepted that were not json.")
529 parser.add_argument("--retry-dir", default=None, help="where to put index numbers and files of json messages the server was unavailable for or unhappy with.")
530 parser.add_argument("--error-dir", default=None, help="where to log index numbers of json messages that provoked errors")
531 parser.add_argument("--log-dir", default=None, help="log file directory")
532 parser.add_argument('files', nargs='+')
533 args = parser.parse_args()
534 if args.retry:
535 print("ERROR: retry not implemented yet")
536 sys.exit(1)
537 if args.completed_dir and not os.path.isdir(args.completed_dir):
538 print("ERROR: completed-dir %s missing" % args.completed_dir)
539 sys.exit(1)
540 if args.retry_dir and not os.path.isdir(args.retry_dir):
541 print("ERROR: retry-dir %s is missing" % args.retry_dir)
542 sys.exit(1)
543 if args.error_dir and not os.path.isdir(args.error_dir):
544 print("ERROR: error-dir %s is missing" % args.error_dir)
545 sys.exit(1)
546 if args.log_dir and not os.path.isdir(args.log_dir):
547 print("ERROR: log-dir %s is missing" % args.log_dir)
548 sys.exit(1)
549 for f in args.files:
550 if args.validate:
551 print("with validation");
552 print("Processing " + f)
553 if not args.completed_dir:
554 compdir = os.path.join(os.path.dirname(f),"COMPLETED")
555 else:
556 compdir = args.completed_dir
557 if not args.retry_dir:
558 retdir = os.path.join(os.path.dirname(f),"RETRY")
559 else:
560 retdir = args.retry_dir
561
562
563
564 maxerr = process_file(f, args.url, compdir, retdir, args.error_dir, args.log_dir, args.retry, args.validate)
565 if maxerr < 2:
566 print("Processed {}".format(f))
567 else:
568 print("Retry maybe needed for {} in {}: maxerr {}".format(os.path.basename(f), retdir, maxerr))
569
570 return 0
571