Extract a third-party archive into dst_third_party/prefix. Typical structure inside the archive is a single top-level directory like "mbedtls- /". We extract under dst_third_party, then rename that directory to a stable name dst_third_party/prefix.
(prefix: str, zip_path: Path, dst_third_party: Path)
| 12 | |
| 13 | |
| 14 | def extract_zip(prefix: str, zip_path: Path, dst_third_party: Path): |
| 15 | """Extract a third-party archive into dst_third_party/prefix. |
| 16 | |
| 17 | Typical structure inside the archive is a single top-level directory like |
| 18 | "mbedtls-<ver>/". We extract under dst_third_party, then rename that |
| 19 | directory to a stable name dst_third_party/prefix. |
| 20 | """ |
| 21 | ensure_dir(dst_third_party) |
| 22 | with zipfile.ZipFile(zip_path, 'r') as zf: |
| 23 | # Determine the top-level directory inside the archive |
| 24 | names = zf.namelist() |
| 25 | top_candidates = {n.split('/', 1)[0] for n in names if '/' in n} |
| 26 | top_dir = next((n for n in sorted(top_candidates) if n.startswith(f"{prefix}-")), None) |
| 27 | if top_dir is None: # There is no versioned top-level dir, create one |
| 28 | top_dir = prefix |
| 29 | extract_parent_dir = dst_third_party / prefix |
| 30 | if not extract_parent_dir.exists(): |
| 31 | extract_parent_dir.mkdir() |
| 32 | else: |
| 33 | extract_parent_dir = dst_third_party |
| 34 | print(f"Extracting {zip_path} -> {extract_parent_dir} (top_dir: {top_dir})") |
| 35 | zf.extractall(extract_parent_dir) |
| 36 | |
| 37 | extracted_dir = dst_third_party / top_dir |
| 38 | target_dir = dst_third_party / prefix |
| 39 | if extracted_dir.exists() and extracted_dir != target_dir: |
| 40 | if target_dir.exists(): |
| 41 | shutil.rmtree(target_dir) |
| 42 | extracted_dir.rename(target_dir) |
| 43 | |
| 44 | def find_single_subdir(root: Path) -> Path: |
| 45 | entries = [p for p in root.iterdir() if p.is_dir()] |
no test coverage detected
searching dependent graphs…