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

49 lines
1.1 KiB
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):
2023-07-25 10:56:34 -05:00
name = repo.name.replace(".git","")
dest = Path(config["paths"]["dest"]) / repo.name
2022-08-15 00:15:51 -05:00
return name, dest
def get_repo_path(config, repos):
return Path(__file__).parent.parent.parent / config["paths"][repos]
def main():
2022-08-15 00:15:51 -05:00
config = get_config()
for repo in get_repo_path(config, "src").iterdir():
2022-08-15 00:15:51 -05:00
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)
for repo in get_repo_path(config, "dest").iterdir():
2022-08-15 00:15:51 -05:00
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()