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", |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 25 | "https://github.com/kraj/meta-clang", |
| 26 | ) |
| 27 | |
| 28 | if __name__ == "__main__": |
| 29 | if "KAS_REPO_REF_DIR" not in os.environ: |
| 30 | print("KAS_REPO_REF_DIR needs to be set") |
| 31 | sys.exit(1) |
| 32 | |
| 33 | base_repodir = pathlib.Path(os.environ["KAS_REPO_REF_DIR"]) |
| 34 | |
| 35 | for repo in repositories: |
| 36 | repodir = base_repodir / repo_shortname(repo) |
| 37 | if repodir.exists(): |
| 38 | print("Updating %s..." % repo) |
| 39 | subprocess.run(["git", "-C", repodir, "fetch"], check=True) |
| 40 | else: |
| 41 | print("Cloning %s..." % repo) |
| 42 | subprocess.run(["git", "clone", "--bare", repo, repodir], check=True) |