|
51 | 51 | help="Output directory where the zip will be saved.", |
52 | 52 | required=True, |
53 | 53 | ) |
54 | | - args = parser.parse_args() |
55 | | - |
56 | | - # Define all arguments and their human-readable names. |
57 | | - arg_paths = { |
58 | | - ("CAB", "phone"): args.cab_phone_path, |
59 | | - ("LIN", "phone"): args.lin_phone_path, |
60 | | - ("HGE", "phone"): args.hge_phone_path, |
61 | | - ("CAB", "hololens"): args.cab_hololens_path, |
62 | | - ("LIN", "hololens"): args.lin_hololens_path, |
63 | | - ("HGE", "hololens"): args.hge_hololens_path, |
64 | | - } |
65 | | - |
| 54 | + args = parser.parse_args().__dict__ |
| 55 | + output_dir = args.pop("output_dir") |
| 56 | + |
66 | 57 | # Generate timestamp for the zip file name. |
67 | 58 | timestamp = datetime.datetime.now().strftime("%Y.%m.%d_%H.%M.%S") |
68 | | - zip_filename = args.output_dir / f"result_{timestamp}.zip" |
| 59 | + zip_filename = output_dir / f"result_{timestamp}.zip" |
69 | 60 |
|
70 | 61 | # Create the zip file with existing paths. |
71 | 62 | logger.info(f"Creating zip file at {zip_filename}") |
72 | | - args.output_dir.mkdir(parents=True, exist_ok=True) |
| 63 | + output_dir.mkdir(parents=True, exist_ok=True) |
73 | 64 | with zipfile.ZipFile(zip_filename, "w", zipfile.ZIP_DEFLATED) as zipf: |
74 | | - for split, path in arg_paths.items(): |
| 65 | + for name, path in args.items(): |
| 66 | + split = name.split("_") |
| 67 | + assert len(split) == 3 |
| 68 | + assert split[-1] == "path" |
| 69 | + split = split[:-1] |
75 | 70 | if path is None: |
76 | | - logger.warning(f"No path provided for [{split}], skipping") |
| 71 | + logger.warning(f"No path provided for [{split}], skipping...") |
77 | 72 | continue |
78 | 73 | assert path.exists() |
79 | 74 | assert path.is_file() |
80 | 75 | assert path.suffix == ".txt", f"Expected .txt file, got {path.suffix}" |
81 | 76 | logger.info(f"Adding [{split}] file from {path} to zip") |
82 | | - zipf.write(path, arcname=f"{split[0]}_query_{split[1]}.txt") |
| 77 | + zipf.write(path, arcname=f"{split[0].upper()}_query_{split[1]}.txt") |
83 | 78 | logger.info(f"Successfully created zip file at {zip_filename}") |
0 commit comments