parameterize soft-serve update script

This commit is contained in:
Daylin Morgan 2022-08-15 05:15:51 +00:00
parent c3276ca5e4
commit f1b714bc89
2 changed files with 30 additions and 12 deletions

10
soft-serve.config.json Normal file
View File

@ -0,0 +1,10 @@
{
"paths": {
"src": "./gitea/git/repositories/daylin",
"dest": "./soft/repos"
},
"repos": {
"src": ["dotfiles", "git-server"],
"dest": ["config"]
}
}

View File

@ -1,21 +1,29 @@
#!/usr/bin/env python3
import json
from pathlib import Path
import shutil
GITEA_REPOS = Path(__file__).parent / "gitea/git/repositories/daylin"
SOFT_REPOS = Path(__file__).parent / "soft/repos"
allowed = ["dotfiles", "git-server"]
soft_serve_only = ["config"]
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():
for repo in GITEA_REPOS.iterdir():
name = repo.name.replace(".git", "")
dest = SOFT_REPOS / name
if name not in [*allowed, *soft_serve_only]:
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
print(f"{repo} >> {dest}")
@ -24,10 +32,10 @@ def main():
shutil.rmtree(dest)
shutil.copytree(repo, dest)
for repo in SOFT_REPOS.iterdir():
name = repo.name.replace(".git", "")
dest = SOFT_REPOS / name
if name not in [*allowed, *soft_serve_only]:
for repo in Path(config["paths"]["dest"]).iterdir():
name, dest = get_name(config, repo)
if name not in [*config["repos"]["src"], *config["repos"]["dest"]]:
print(f"pruning {name}")
shutil.rmtree(repo)