2022-08-14 18:16:59 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2022-08-15 00:15:51 -05:00
|
|
|
import json
|
2022-08-14 18:16:59 -05:00
|
|
|
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
|
2022-08-14 18:16:59 -05:00
|
|
|
|
|
|
|
|
2022-08-15 01:01:37 -05:00
|
|
|
def get_repo_path(config, repos):
|
|
|
|
return Path(__file__).parent.parent.parent / config["paths"][repos]
|
|
|
|
|
|
|
|
|
2022-08-14 18:16:59 -05:00
|
|
|
def main():
|
|
|
|
|
2022-08-15 00:15:51 -05:00
|
|
|
config = get_config()
|
|
|
|
|
2022-08-15 01:01:37 -05:00
|
|
|
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"]:
|
2022-08-14 18:16:59 -05:00
|
|
|
continue
|
|
|
|
|
2022-08-14 18:40:37 -05:00
|
|
|
print(f"{repo} >> {dest}")
|
2022-08-14 18:16:59 -05:00
|
|
|
|
|
|
|
if dest.is_dir():
|
|
|
|
shutil.rmtree(dest)
|
|
|
|
shutil.copytree(repo, dest)
|
|
|
|
|
2022-08-15 01:01:37 -05:00
|
|
|
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)
|
|
|
|
|
2022-08-14 18:16:59 -05:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|