]> git.mar77i.info Git - admin/commitdiff
gitweb_configs.py: add and remove git repos in gitweb
authormar77i <mar77i@protonmail.ch>
Tue, 28 Nov 2023 04:08:10 +0000 (05:08 +0100)
committermar77i <mar77i@protonmail.ch>
Tue, 28 Nov 2023 04:10:55 +0000 (05:10 +0100)
gitweb_configs.py

index 21b9fa1194c6e4ebfe001179b3e44b84c9ac956d..0616f6d1743cbdc2253a53dff29a9a3b64eec2bd 100755 (executable)
@@ -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()