[libvirt PATCH 02/11] ci: util: Replace get_image_distro() with get_image_info()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a more flexible function that parses the name of the
container image into its components: distro name and, where
applicable, target architecture for cross-building.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 ci/util.py | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/ci/util.py b/ci/util.py
index 304d0d4af8..e4e0955098 100644
--- a/ci/util.py
+++ b/ci/util.py
@@ -39,24 +39,32 @@ def get_registry_images(uri: str) -> List[Dict]:
     return json.loads(r.read().decode())
 
 
-def get_image_distro(image_name: str) -> str:
+def get_image_info(image_name: str) -> Dict[str, str]:
     """
-    Extract the name of the distro in the GitLab image registry name, e.g.
-        ci-debian-9-cross-mipsel --> debian-9
+    Extract information about the image from its name, e.g.
+
+        "ci-debian-9-cross-mipsel"
+            => { "distro": "debian-9", "cross": "mipsel" }
+
+        "ci-centos-8"
+            => { "distro": "centos-8", "cross": None }
 
     :param image_name: name of the GitLab registry image
-    :return: distro name as a string
+    :return: image information
     """
-    name_prefix = "ci-"
-    name_suffix = "-cross-"
+    distro_prefix = "ci-"
+    cross_prefix = "-cross-"
 
-    distro = image_name[len(name_prefix):]
+    distro = image_name[len(distro_prefix):]
 
-    index = distro.find(name_suffix)
-    if index > 0:
-        distro = distro[:index]
+    cross_index = distro.find(cross_prefix)
+    if cross_index > 0:
+        cross = distro[cross_index + len(cross_prefix):]
+        distro = distro[:cross_index]
+    else:
+        cross = None
 
-    return distro
+    return {"distro": distro, "cross": cross}
 
 
 def get_registry_stale_images(registry_uri: str,
@@ -74,7 +82,8 @@ def get_registry_stale_images(registry_uri: str,
 
     stale_images = {}
     for img in images:
-        if get_image_distro(img["name"]) not in supported_distros:
+        info = get_image_info(img["name"])
+        if info["distro"] not in supported_distros:
             stale_images[img["name"]] = img["id"]
 
     return stale_images
-- 
2.26.3




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux