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 pass
def vacuum(target: str, paths: Iterable[str] = ("lib",)) -> None: def _get_status(records: str) -> dict[str, str]:
"""
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]:
status = {} status = {}
for name in os.listdir(records): for name in os.listdir(records):
@ -241,15 +220,23 @@ def get_status(records: str) -> dict[str, str]:
def install_spec( def install_spec(
spec_text: str, target: str, records: str, paths: Iterable[str] = ("lib",) spec_text: str, target: str, records: str, paths: Iterable[str] = ("lib",)
) -> None: ) -> None:
spec = parse_spec(spec_text) spec = {}
status = get_status(records)
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(): for name, version in status.items():
if not name in spec or spec[name][0] != version: if not name in spec or spec[name][0] != version:
uninstall(name, target, records) uninstall(name, target, records)
vacuum(target, paths) for path in paths:
status = get_status(records) _vacuum(f"{target}/{path}")
status = _get_status(records)
for name, version_repo in spec.items(): for name, version_repo in spec.items():
version, repo = version_repo version, repo = version_repo