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 |
Andrew Geissler | 2daf84b | 2023-03-31 09:57:23 -0500 | [diff] [blame] | 7 | import shutil |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 8 | import subprocess |
| 9 | import pathlib |
| 10 | |
| 11 | def repo_shortname(url): |
| 12 | # Taken from Kas (Repo.__getattr__) to ensure the logic is right |
| 13 | from urllib.parse import urlparse |
| 14 | url = urlparse(url) |
| 15 | return ('{url.netloc}{url.path}' |
| 16 | .format(url=url) |
| 17 | .replace('@', '.') |
| 18 | .replace(':', '.') |
| 19 | .replace('/', '.') |
| 20 | .replace('*', '.')) |
| 21 | |
| 22 | repositories = ( |
| 23 | "https://git.yoctoproject.org/git/poky", |
| 24 | "https://git.openembedded.org/meta-openembedded", |
| 25 | "https://git.yoctoproject.org/git/meta-virtualization", |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 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"]) |
Andrew Geissler | 220dafd | 2023-10-04 10:18:08 -0500 | [diff] [blame] | 35 | failed = False |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 36 | |
| 37 | for repo in repositories: |
| 38 | repodir = base_repodir / repo_shortname(repo) |
Andrew Geissler | 2daf84b | 2023-03-31 09:57:23 -0500 | [diff] [blame] | 39 | |
| 40 | if "CI_CLEAN_REPOS" in os.environ: |
| 41 | print("Cleaning %s..." % repo) |
| 42 | shutil.rmtree(repodir, ignore_errors=True) |
| 43 | |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 44 | if repodir.exists(): |
Andrew Geissler | 220dafd | 2023-10-04 10:18:08 -0500 | [diff] [blame] | 45 | try: |
| 46 | print("Updating %s..." % repo) |
| 47 | subprocess.run(["git", "-C", repodir, "-c", "gc.autoDetach=false", "fetch"], check=True) |
| 48 | except subprocess.CalledProcessError as e: |
| 49 | print(e) |
| 50 | failed = True |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 51 | else: |
| 52 | print("Cloning %s..." % repo) |
| 53 | subprocess.run(["git", "clone", "--bare", repo, repodir], check=True) |
Andrew Geissler | 220dafd | 2023-10-04 10:18:08 -0500 | [diff] [blame] | 54 | |
| 55 | if failed: |
| 56 | sys.exit(128) |