git-server/update-soft-serve-repos.py

45 lines
970 B
Python
Raw Normal View History

#!/usr/bin/env python3
2022-08-15 00:15:51 -05:00
import json
from pathlib import Path
import shutil
2022-08-15 00:15:51 -05:00
def get_config():
with (Path(__file__).parent / "soft-serve.config.json").open("r") as f:
return json.load(f)
def get_name(config, repo):
name = repo.name.replace(".git", "")
dest = Path(config["paths"]["dest"]) / name
return name, dest
def main():
2022-08-15 00:15:51 -05:00
config = get_config()
for repo in Path(config["paths"]["src"]).iterdir():
name, dest = get_name(config, repo)
if name not in config["repos"]["src"]:
continue
2022-08-14 18:40:37 -05:00
print(f"{repo} >> {dest}")
if dest.is_dir():
shutil.rmtree(dest)
shutil.copytree(repo, dest)
2022-08-15 00:15:51 -05:00
for repo in Path(config["paths"]["dest"]).iterdir():
name, dest = get_name(config, repo)
if name not in [*config["repos"]["src"], *config["repos"]["dest"]]:
2022-08-14 18:40:37 -05:00
print(f"pruning {name}")
shutil.rmtree(repo)
if __name__ == "__main__":
main()