The corresponding Bash script is dropped.
After this patch's rewrite, the Makefile's original image listing
target remains intact only to notify the user to use the Python helper
instead.

Signed-off-by: Erik Skultety <eskul...@redhat.com>
---
 ci/Makefile       | 12 +-----------
 ci/helper         | 37 ++++++++++++++++++++++++++++++++++++-
 ci/list-images.sh | 14 --------------
 3 files changed, 37 insertions(+), 26 deletions(-)
 delete mode 100644 ci/list-images.sh

diff --git a/ci/Makefile b/ci/Makefile
index f83ecac1e5..7720dddfb9 100644
--- a/ci/Makefile
+++ b/ci/Makefile
@@ -211,16 +211,7 @@ ci-build@%:
 ci-test@%:
        $(MAKE) -C $(CI_ROOTDIR) ci-build@$* CI_NINJA_ARGS=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
-       @echo
+ci-list-images: help
 
 help:
        @echo
@@ -241,7 +232,6 @@ help:
        @echo "    ci-build@\$$IMAGE - run a default 'ninja' build"
        @echo "    ci-test@\$$IMAGE  - run a 'ninja test'"
        @echo "    ci-shell@\$$IMAGE - run an interactive shell"
-       @echo "    ci-list-images  - list available images"
        @echo "    help            - show this help message"
        @echo
        @echo "Available make variables:"
diff --git a/ci/helper b/ci/helper
index abac686d22..1b7675c58a 100755
--- a/ci/helper
+++ b/ci/helper
@@ -11,6 +11,8 @@ import shutil
 import subprocess
 import sys
 
+import util
+
 
 class Parser:
     def __init__(self):
@@ -66,6 +68,20 @@ class Parser:
             help="path to lcitool binary",
         )
 
+        # Options that are common to actions communicating with a GitLab
+        # instance
+        gitlabparser = argparse.ArgumentParser(add_help=False)
+        gitlabparser.add_argument(
+            "--namespace",
+            default="libvirt/libvirt",
+            help="GitLab project namespace"
+        )
+        gitlabparser.add_argument(
+            "--gitlab-uri",
+            default="https://gitlab.com";,
+            help="base GitLab URI"
+        )
+
         # Main parser
         self.parser = argparse.ArgumentParser()
         self.parser.add_argument(
@@ -111,6 +127,7 @@ class Parser:
         listimagesparser = subparsers.add_parser(
             "list-images",
             help="list known container images",
+            parents=[gitlabparser],
             formatter_class=argparse.ArgumentDefaultsHelpFormatter,
         )
         listimagesparser.set_defaults(func=Application.action_list_images)
@@ -249,7 +266,25 @@ class Application:
         self.make_run(f"ci-shell@{self.args.target}")
 
     def action_list_images(self):
-        self.make_run(f"ci-list-images")
+        registry_uri = util.get_registry_uri(self.args.namespace,
+                                             self.args.gitlab_uri)
+        images = util.get_registry_images(registry_uri)
+
+        # skip the "ci-" prefix each of our container images' name has
+        name_prefix = "ci-"
+        names = [i["name"][len(name_prefix):] for i in images]
+        names.sort()
+
+        native = [name for name in names if "-cross-" not in name]
+        cross = [name for name in names if "-cross-" in name]
+
+        print("Available x86 container images:\n")
+        print("\t" + "\n\t".join(native))
+
+        if cross:
+            print()
+            print("Available cross-compiler container images:\n")
+            print("\t" + "\n\t".join(cross))
 
     def action_refresh(self):
         self.refresh_containers()
diff --git a/ci/list-images.sh b/ci/list-images.sh
deleted file mode 100644
index b85b132253..0000000000
--- a/ci/list-images.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh
-
-prefix="${1##registry.gitlab.com/}"
-
-PROJECT_ID=192693
-
-all_repos() {
-  curl -s 
"https://gitlab.com/api/v4/projects/$PROJECT_ID/registry/repositories?per_page=100";
 \
-    | tr , '\n' | grep '"path":' | sed 's,"path":",,g;s,"$,,g'
-}
-
-all_repos | grep "^$prefix" | sed "s,^$prefix,,g" | while read repo; do
-    echo "    $repo"
-done | sort -u
-- 
2.29.2

Reply via email to