Remove unnecessary functions and rename unpack

This commit is contained in:
Samuel Sloniker 2024-07-01 10:29:53 -07:00
parent 0844604554
commit 1e3a6e6e3b

View File

@ -207,28 +207,7 @@ def _vacuum(root: str, delete_this: bool = False) -> None:
pass
def vacuum(target: str, paths: Iterable[str] = ("lib",)) -> None:
"""
Remove empty directories under `paths`, each relative to `target`.
"""
for path in paths:
_vacuum(f"{target}/{path}")
def parse_spec(spec_text: str) -> dict[str, tuple[str, str]]:
spec = {}
for full_line in spec_text.split("\n"):
line = full_line.strip()
if line:
name, version_hash, repo = line.split(",")
spec[name] = (version_hash, repo)
return spec
def get_status(records: str) -> dict[str, str]:
def _get_status(records: str) -> dict[str, str]:
status = {}
for name in os.listdir(records):
@ -241,15 +220,23 @@ def get_status(records: str) -> dict[str, str]:
def install_spec(
spec_text: str, target: str, records: str, paths: Iterable[str] = ("lib",)
) -> None:
spec = parse_spec(spec_text)
status = get_status(records)
spec = {}
for full_line in spec_text.split("\n"):
line = full_line.strip()
if line:
name, version_hash, repo = line.split(",")
spec[name] = (version_hash, repo)
status = _get_status(records)
for name, version in status.items():
if not name in spec or spec[name][0] != version:
uninstall(name, target, records)
vacuum(target, paths)
status = get_status(records)
for path in paths:
_vacuum(f"{target}/{path}")
status = _get_status(records)
for name, version_repo in spec.items():
version, repo = version_repo