Sync ctx 59d617a (part 2)
Browse filesGitHub commit: 59d617a5251ad4aa8624e883d6fe21102e66cce6
- src/ctx_init.py +39 -0
src/ctx_init.py
CHANGED
|
@@ -615,6 +615,11 @@ def _extract_graph_archive_to_dir(
|
|
| 615 |
) -> None:
|
| 616 |
target_dir.mkdir(parents=True, exist_ok=True)
|
| 617 |
target_root = target_dir.resolve()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 618 |
extracted_required: set[str] = set()
|
| 619 |
with tarfile.open(archive, "r:gz") as tf:
|
| 620 |
for member in tf:
|
|
@@ -641,6 +646,40 @@ def _extract_graph_archive_to_dir(
|
|
| 641 |
extracted_required.add(safe_name)
|
| 642 |
|
| 643 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 644 |
def _graph_install_complete(wiki_dir: Path) -> bool:
|
| 645 |
try:
|
| 646 |
_validate_graph_install_tree(wiki_dir)
|
|
|
|
| 615 |
) -> None:
|
| 616 |
target_dir.mkdir(parents=True, exist_ok=True)
|
| 617 |
target_root = target_dir.resolve()
|
| 618 |
+
if install_mode == "full" and _extract_full_graph_archive_with_system_tar(
|
| 619 |
+
archive,
|
| 620 |
+
target_dir,
|
| 621 |
+
):
|
| 622 |
+
return
|
| 623 |
extracted_required: set[str] = set()
|
| 624 |
with tarfile.open(archive, "r:gz") as tf:
|
| 625 |
for member in tf:
|
|
|
|
| 646 |
extracted_required.add(safe_name)
|
| 647 |
|
| 648 |
|
| 649 |
+
def _extract_full_graph_archive_with_system_tar(
|
| 650 |
+
archive: Path,
|
| 651 |
+
target_dir: Path,
|
| 652 |
+
) -> bool:
|
| 653 |
+
tar_path = shutil.which("tar")
|
| 654 |
+
if tar_path is None:
|
| 655 |
+
return False
|
| 656 |
+
_validate_graph_archive_for_system_extract(archive)
|
| 657 |
+
result = subprocess.run(
|
| 658 |
+
[tar_path, "-xzf", str(archive), "-C", str(target_dir)],
|
| 659 |
+
capture_output=True,
|
| 660 |
+
text=True,
|
| 661 |
+
check=False,
|
| 662 |
+
)
|
| 663 |
+
if result.returncode == 0:
|
| 664 |
+
return True
|
| 665 |
+
_clear_directory(target_dir)
|
| 666 |
+
return False
|
| 667 |
+
|
| 668 |
+
|
| 669 |
+
def _validate_graph_archive_for_system_extract(archive: Path) -> None:
|
| 670 |
+
with tarfile.open(archive, "r:gz") as tf:
|
| 671 |
+
for member in tf:
|
| 672 |
+
_validate_graph_tar_member(member)
|
| 673 |
+
|
| 674 |
+
|
| 675 |
+
def _clear_directory(path: Path) -> None:
|
| 676 |
+
for child in path.iterdir():
|
| 677 |
+
if child.is_dir() and not child.is_symlink():
|
| 678 |
+
shutil.rmtree(child)
|
| 679 |
+
else:
|
| 680 |
+
child.unlink()
|
| 681 |
+
|
| 682 |
+
|
| 683 |
def _graph_install_complete(wiki_dir: Path) -> bool:
|
| 684 |
try:
|
| 685 |
_validate_graph_install_tree(wiki_dir)
|