#!/usr/bin/env python3 import os import sys from pathlib import Path from shutil import rmtree from subprocess import CalledProcessError, check_output, run GITWEB_CONFIGS = { "admin": { "owner": "mar77i ", "description": "admin scripts", }, "mar77i.info": { "owner": "mar77i ", "description": "mar77i.info website", }, "hublib": { "owner": "mar77i ", "description": "base for websocket toys", }, "laptop-config": { "owner": "mar77i ", "description": "laptop screen configuration", }, "rcfiles": { "owner": "mar77i ", "description": "user configuration files", }, "bigintmandel": { "owner": "mar77i ", "description": "Qt mandelbrot toy, with big integers only", }, } def main(): base_dir = Path.home() / "git" 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(): 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() assert set(configs) == {"owner", "description"} for key, value in configs.items(): try: output = check_output( ["git", "config", "--get", f"gitweb.{key}"], universal_newlines=True ) except CalledProcessError: output = None if output != f"{value}\n": run(["git", "config", f"gitweb.{key}", value]) if __name__ == "__main__": main()