blob: a68257bbabeb4dcf59ee300e9b442a66538bc3be [file] [log] [blame]
Brad Bishopbec4ebc2022-08-03 09:55:16 -04001#! /usr/bin/env python3
2
3# Update clones of the repositories we need in KAS_REPO_REF_DIR to speed up fetches
4
5import sys
6import os
7import subprocess
8import pathlib
9
10def 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
21repositories = (
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
29if __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)