Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 1 | #! /usr/bin/env python3 |
| 2 | |
| 3 | # Update clones of the repositories we need in KAS_REPO_REF_DIR to speed up fetches |
| 4 | |
| 5 | import sys |
| 6 | import os |
| 7 | import subprocess |
| 8 | import pathlib |
| 9 | |
| 10 | def repo_shortname(url): |
| 11 | # Taken from Kas (Repo.__getattr__) to ensure the logic is right |
| 12 | from urllib.parse import urlparse |
| 13 | url = urlparse(url) |
| 14 | return ('{url.netloc}{url.path}' |
| 15 | .format(url=url) |
| 16 | .replace('@', '.') |
| 17 | .replace(':', '.') |
| 18 | .replace('/', '.') |
| 19 | .replace('*', '.')) |
| 20 | |
| 21 | repositories = ( |
| 22 | "https://git.yoctoproject.org/git/poky", |
| 23 | "https://git.openembedded.org/meta-openembedded", |
| 24 | "https://git.yoctoproject.org/git/meta-virtualization", |
| 25 | "https://git.yoctoproject.org/git/meta-zephyr", |
| 26 | "https://github.com/kraj/meta-clang", |
| 27 | ) |
| 28 | |
| 29 | if __name__ == "__main__": |
| 30 | if "KAS_REPO_REF_DIR" not in os.environ: |
| 31 | print("KAS_REPO_REF_DIR needs to be set") |
| 32 | sys.exit(1) |
| 33 | |
| 34 | base_repodir = pathlib.Path(os.environ["KAS_REPO_REF_DIR"]) |
| 35 | |
| 36 | for repo in repositories: |
| 37 | repodir = base_repodir / repo_shortname(repo) |
| 38 | if repodir.exists(): |
| 39 | print("Updating %s..." % repo) |
| 40 | subprocess.run(["git", "-C", repodir, "fetch"], check=True) |
| 41 | else: |
| 42 | print("Cloning %s..." % repo) |
| 43 | subprocess.run(["git", "clone", "--bare", repo, repodir], check=True) |