def modpack_file(path: Path) -> Generator[ModPack, None, None]:
"""Context manager for manipulation of existing mod-pack.
Keyword arguments:
path: Path to the existing ModPack file, which should be provided.
Yields:
ModPack loaded from path. If no exception occurs, the provided modpack
is written (with changes) back to the file on context exit.
"""
with path.open(encoding='utf-8', mode='r') as istream:
mp = ModPack.load(istream)
yield mp
with path.open(encoding='utf-8', mode='w') as ostream:
mp.dump(ostream)
评论列表
文章目录