#!/usr/bin/env python3 # Synchronize Cryptech git repositories by extracting URLs from the # Alpha release engineering repository's .gitmodules file. This # yields the same tree structure as used by releng/alpha, but without # the git submodule complexities. import sys, urllib.request, urllib.parse, subprocess from configparser import ConfigParser, DEFAULTSECT from pathlib import Path errs = 0 url = "https://git.cryptech.is/releng/alpha/plain/.gitmodules" cfg = ConfigParser(interpolation = None) cfg.read_string(urllib.request.urlopen(url).read().decode()) for section in cfg: if section == DEFAULTSECT: continue url = cfg[section]["url"] repo = Path(urllib.parse.urlparse(url).path).relative_to("/").with_suffix("") try: if repo.is_dir(): subprocess.run(("git", "-C", repo, "fetch", "--all", "--prune"), check = True) subprocess.run(("git", "-C", repo, "merge", "--ff-only"), check = True) else: repo.parent.mkdir(parents = True, exist_ok = True) subprocess.run(("git", "-C", repo.parent, "clone", url), check = True) except: print("** Error for repo", repo) errs += 1 sys.exit(errs)