blob: 91ff1975847225bf9a4df8612e3b1c4a68521ed8 [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",
Brad Bishopbec4ebc2022-08-03 09:55:16 -040025 "https://github.com/kraj/meta-clang",
26)
27
28if __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)