()
| 374 | |
| 375 | |
| 376 | def main(): |
| 377 | args = parse_args() |
| 378 | configure_logging(use_debug=args.debug) |
| 379 | logging.debug("Original options: %s", " ".join(sys.argv)) |
| 380 | |
| 381 | if not os.path.exists(args.out_dir): |
| 382 | os.mkdir(args.out_dir) |
| 383 | |
| 384 | # generate thread arguments |
| 385 | subdir_q = Queue() |
| 386 | cnt_q = Queue() |
| 387 | for subdir in os.listdir(args.in_dir): |
| 388 | if os.path.isdir(os.path.join(args.in_dir, subdir)): |
| 389 | subdir_q.put(subdir) |
| 390 | |
| 391 | threads = [] |
| 392 | nthreads = min(max(subdir_q.qsize(), 1), args.num_threads) |
| 393 | |
| 394 | # Start up the threads. |
| 395 | for _ in range(nthreads): |
| 396 | t = Thread( |
| 397 | target=post_process, |
| 398 | args=( |
| 399 | args.in_dir, subdir_q, args.out_dir, args.num_sessions, args.no_human_readable, |
| 400 | not args.no_fabricate_proxy_requests, cnt_q)) |
| 401 | t.start() |
| 402 | threads.append(t) |
| 403 | |
| 404 | # Wait for them to finish. |
| 405 | for t in threads: |
| 406 | t.join() |
| 407 | |
| 408 | # Retrieve the counts |
| 409 | session_count = 0 |
| 410 | transaction_count = 0 |
| 411 | errors = defaultdict(int) |
| 412 | for count_tuple in list(cnt_q.queue): |
| 413 | session_count += count_tuple[0] |
| 414 | transaction_count += count_tuple[1] |
| 415 | for e in count_tuple[2]: |
| 416 | errors[e] += count_tuple[2][e] |
| 417 | summary = f"Total {session_count} sessions and {transaction_count} transactions." |
| 418 | logging.info(summary) |
| 419 | if errors: |
| 420 | logging.info("Total errors:") |
| 421 | for e in errors: |
| 422 | logging.info(f"{e}: {errors[e]}") |
| 423 | else: |
| 424 | logging.info("Total errors: 0") |
| 425 | |
| 426 | with open(f"{args.out_dir}/summary.txt", "w", encoding="ascii") as f: |
| 427 | f.write(f"{summary}\n") |
| 428 | |
| 429 | |
| 430 | if __name__ == "__main__": |
no test coverage detected