|
5 | 5 |
|
6 | 6 | from . import logger |
7 | 7 |
|
| 8 | +def assert_valid_txt_path(path: Path): |
| 9 | + """Assert that the path is valid.""" |
| 10 | + assert path.exists(), f"Path does not exist: {path}" |
| 11 | + assert path.is_file(), f"Path is not a file: {path}" |
| 12 | + assert path.suffix == ".txt", f"Expected .txt file, got {path.suffix}" |
| 13 | + |
| 14 | + |
8 | 15 | if __name__ == '__main__': |
9 | 16 | parser = argparse.ArgumentParser( |
10 | 17 | description="Combine estimated poses from multiple scenes / devices in a zip file for evaluation." |
|
45 | 52 | default=None, |
46 | 53 | help="File containing the HGE HoloLens estimated poses.", |
47 | 54 | ) |
| 55 | + parser.add_argument( |
| 56 | + "--description_path", |
| 57 | + type=Path, |
| 58 | + required=True, |
| 59 | + help="Path to a text file containing description of the submission.", |
| 60 | + ) |
48 | 61 | parser.add_argument( |
49 | 62 | "--output_dir", |
50 | 63 | type=Path, |
51 | | - help="Output directory where the zip will be saved.", |
52 | 64 | required=True, |
| 65 | + help="Output directory where the zip will be saved.", |
53 | 66 | ) |
54 | 67 | args = parser.parse_args().__dict__ |
55 | 68 | output_dir = args.pop("output_dir") |
| 69 | + description_path = args.pop("description_path") |
56 | 70 |
|
57 | 71 | # Generate timestamp for the zip file name. |
58 | 72 | timestamp = datetime.datetime.now().strftime("%Y.%m.%d_%H.%M.%S") |
|
62 | 76 | logger.info(f"Creating zip file at {zip_filename}") |
63 | 77 | output_dir.mkdir(parents=True, exist_ok=True) |
64 | 78 | with zipfile.ZipFile(zip_filename, "w", zipfile.ZIP_DEFLATED) as zipf: |
| 79 | + # Add the description file to the zip. |
| 80 | + logger.info(f"Adding description file from {description_path} to zip") |
| 81 | + assert_valid_txt_path(description_path) |
| 82 | + zipf.write(description_path, arcname="description.txt") |
65 | 83 | for name, path in args.items(): |
66 | 84 | split = name.split("_") |
67 | 85 | assert len(split) == 3 |
|
70 | 88 | if path is None: |
71 | 89 | logger.warning(f"No path provided for [{split}], skipping...") |
72 | 90 | continue |
73 | | - assert path.exists() |
74 | | - assert path.is_file() |
75 | | - assert path.suffix == ".txt", f"Expected .txt file, got {path.suffix}" |
76 | 91 | logger.info(f"Adding [{split}] file from {path} to zip") |
| 92 | + assert_valid_txt_path(path) |
77 | 93 | zipf.write(path, arcname=f"{split[0].upper()}_query_{split[1]}.txt") |
78 | 94 | logger.info(f"Successfully created zip file at {zip_filename}") |
0 commit comments