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>
Reviewed-by: Andrea Bolognani <abolo...@redhat.com>
---
 ci/Makefile       | 12 ------------
 ci/helper         | 38 +++++++++++++++++++++++++++++++++++++-
 ci/list-images.sh | 14 --------------
 3 files changed, 37 insertions(+), 27 deletions(-)
 delete mode 100644 ci/list-images.sh

diff --git a/ci/Makefile b/ci/Makefile
index 72f5bda942..02ce0df7ee 100644
--- a/ci/Makefile
+++ b/ci/Makefile
@@ -211,17 +211,6 @@ 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-help:
        @echo
        @echo
@@ -241,7 +230,6 @@ ci-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 "    ci-help         - show this help message"
        @echo
        @echo "Available make variables:"
diff --git a/ci/helper b/ci/helper
index 53baef3cb1..31cf72fbdf 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()
         subparsers = self.parser.add_subparsers(
@@ -105,6 +121,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,26 @@ 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]
+
+        spacing = 4 * " "
+        print("Available x86 container images:\n")
+        print(spacing + ("\n" + spacing).join(native))
+
+        if cross:
+            print()
+            print("Available cross-compiler container images:\n")
+            print(spacing + ("\n" + spacing).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