|
3 | 3 | import signal |
4 | 4 | import sys |
5 | 5 | from argparse import ArgumentParser |
| 6 | +from hashlib import sha1 |
6 | 7 | from pathlib import Path |
7 | 8 |
|
8 | 9 | if "QT_QPA_PLATFORM_PLUGIN_PATH" not in os.environ: |
@@ -103,6 +104,39 @@ def resolve_runtime_path(raw_path: str) -> str: |
103 | 104 | return raw_path |
104 | 105 |
|
105 | 106 |
|
| 107 | +def default_workspace_root() -> Path: |
| 108 | + return Path.home() / "scutie" |
| 109 | + |
| 110 | + |
| 111 | +def sha1_file(path: Path, chunk_size: int = 1024 * 1024) -> str: |
| 112 | + digest = sha1() |
| 113 | + with path.open("rb") as handle: |
| 114 | + while True: |
| 115 | + chunk = handle.read(chunk_size) |
| 116 | + if not chunk: |
| 117 | + break |
| 118 | + digest.update(chunk) |
| 119 | + return digest.hexdigest() |
| 120 | + |
| 121 | + |
| 122 | +def resolve_workspace(args) -> str | None: |
| 123 | + if args.workspace is not None: |
| 124 | + return args.workspace |
| 125 | + |
| 126 | + workspace_root = default_workspace_root() |
| 127 | + workspace_root.mkdir(parents=True, exist_ok=True) |
| 128 | + |
| 129 | + if args.video is not None: |
| 130 | + video_path = Path(args.video).expanduser().resolve() |
| 131 | + return str(workspace_root / sha1_file(video_path)) |
| 132 | + |
| 133 | + if args.images is not None: |
| 134 | + images_path = Path(args.images).expanduser().resolve() |
| 135 | + return str(workspace_root / images_path.name) |
| 136 | + |
| 137 | + return None |
| 138 | + |
| 139 | + |
106 | 140 | if __name__ in "__main__": |
107 | 141 | args = get_arguments() |
108 | 142 |
|
@@ -133,6 +167,9 @@ def resolve_runtime_path(raw_path: str) -> str: |
133 | 167 |
|
134 | 168 | args.device = resolve_device(args.device) |
135 | 169 | log.info(f"Using ONNX Runtime device: {args.device}") |
| 170 | + args.video = resolve_runtime_path(args.video) if args.video is not None else None |
| 171 | + args.images = resolve_runtime_path(args.images) if args.images is not None else None |
| 172 | + args.workspace = resolve_workspace(args) |
136 | 173 |
|
137 | 174 | args_dict = vars(args) |
138 | 175 | for key in ("onnx_encoder", "onnx_memory_write", "onnx_read_decode", "ritm_onnx"): |
|
0 commit comments