From: mar77i Date: Tue, 28 Nov 2023 04:08:10 +0000 (+0100) Subject: gitweb_configs.py: add and remove git repos in gitweb X-Git-Url: https://git.mar77i.info/?a=commitdiff_plain;h=9d0613540d9f2bddea5edbea64931ec7d483b4c9;p=admin gitweb_configs.py: add and remove git repos in gitweb --- diff --git a/gitweb_configs.py b/gitweb_configs.py index 21b9fa1..0616f6d 100755 --- a/gitweb_configs.py +++ b/gitweb_configs.py @@ -3,6 +3,7 @@ import os import sys from pathlib import Path +from shutil import rmtree from subprocess import CalledProcessError, check_output, run GITWEB_CONFIGS = { @@ -19,17 +20,19 @@ GITWEB_CONFIGS = { def main(): base_dir = Path.home() / "git" - mismatched = set(GITWEB_CONFIGS) ^ {p.name for p in base_dir.iterdir() if p.is_dir()} - if mismatched: - print( - f"Warning: gitweb_configs mismatch: {', '.join(mismatched)}", - file=sys.stderr, - ) + for p in base_dir.iterdir(): + if p.is_dir() and p.name not in GITWEB_CONFIGS: + rmtree(p) + print(f"removed {p.name}") for repository, configs in GITWEB_CONFIGS.items(): p = base_dir / repository if not p.exists(): - continue - os.chdir(p) + p.mkdir(0o755) + os.chdir(p) + run(["git", "init", "--bare"]) + print(f"created {p.name}") + else: + os.chdir(p) description = p / "description" if description.exists(): description.unlink()