[libvirt PATCH 2/4] ci: Rewrite list-images from Bash to Python

Erik Skultety eskultet at redhat.com
Wed Feb 10 17:24:34 UTC 2021


Convert the script to some human readable form. Speed-wise, both are
comparable.

Signed-off-by: Erik Skultety <eskultet at redhat.com>
---
 ci/Makefile       |  8 +-------
 ci/list-images.py | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 7 deletions(-)
 create mode 100644 ci/list-images.py

diff --git a/ci/Makefile b/ci/Makefile
index 1f71701047..92032e8ca0 100644
--- a/ci/Makefile
+++ b/ci/Makefile
@@ -217,13 +217,7 @@ ci-test@%:
 
 ci-list-images:
 	@echo
-	@echo "Available x86 container images:"
-	@echo
-	@sh list-images.sh "$(CI_IMAGE_PREFIX)" | grep -v cross
-	@echo
-	@echo "Available cross-compiler container images:"
-	@echo
-	@sh list-images.sh "$(CI_IMAGE_PREFIX)" | grep cross
+	@python3 list-images.py
 	@echo
 
 help:
diff --git a/ci/list-images.py b/ci/list-images.py
new file mode 100644
index 0000000000..6862ac347f
--- /dev/null
+++ b/ci/list-images.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+import json
+import urllib.request as urllib
+
+PROJECT_ID = 192693
+DOMAIN = "https://gitlab.com"
+API = "api/v4"
+
+uri = f"{DOMAIN}/{API}/projects/{PROJECT_ID}/registry/repositories"
+r = urllib.urlopen(uri + "?per_page=100")
+
+# read the HTTP response and load the JSON part of it
+data = json.loads(r.read().decode())
+
+# skip the "ci-" prefix each of our container images' name has
+names = [i["name"][3:] for i in data]
+names.sort()
+
+names_native = [name for name in names if "cross" not in name]
+names_cross = [name for name in names if "cross" in name]
+
+print("Available x86 container images:\n")
+print("\t" + "\n\t".join(names_native))
+
+if names_cross:
+    print()
+    print("Available cross-compiler container images:\n")
+    print("\t" + "\n\t".join(names_cross))
-- 
2.29.2




More information about the libvir-list mailing list