update-repos 1.6 KB

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