[libvirt PATCH 2/2] ci: Avoid use of magic constants

Andrea Bolognani posted 2 patches 4 years, 5 months ago
[libvirt PATCH 2/2] ci: Avoid use of magic constants
Posted by Andrea Bolognani 4 years, 5 months ago
The value 3 is the length of the "ci-" prefix, which is present
in the items returned by get_registry_images() but not in those
returned by get_dockerfiles().

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
---
 ci/util.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/ci/util.py b/ci/util.py
index d8be6631eb..f9f3c550db 100644
--- a/ci/util.py
+++ b/ci/util.py
@@ -68,10 +68,11 @@ def get_registry_stale_images(registry_uri: str, base_dir: str) -> Dict[str, int
 
     dockerfiles = get_dockerfiles(base_dir)
     images = get_registry_images(registry_uri)
+    name_prefix = "ci-"
 
     stale_images = {}
     for img in images:
-        if img["name"][3:] not in dockerfiles:
+        if img["name"][len(name_prefix):] not in dockerfiles:
             stale_images[img["name"]] = img["id"]
 
     return stale_images
-- 
2.31.1

Re: [libvirt PATCH 2/2] ci: Avoid use of magic constants
Posted by Beraldo Leal 4 years, 4 months ago
On Fri, Sep 10, 2021 at 03:59:55PM +0200, Andrea Bolognani wrote:
> The value 3 is the length of the "ci-" prefix, which is present
> in the items returned by get_registry_images() but not in those
> returned by get_dockerfiles().
> 
> Signed-off-by: Andrea Bolognani <abologna@redhat.com>
> ---
>  ci/util.py | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/ci/util.py b/ci/util.py
> index d8be6631eb..f9f3c550db 100644
> --- a/ci/util.py
> +++ b/ci/util.py
> @@ -68,10 +68,11 @@ def get_registry_stale_images(registry_uri: str, base_dir: str) -> Dict[str, int
>  
>      dockerfiles = get_dockerfiles(base_dir)
>      images = get_registry_images(registry_uri)
> +    name_prefix = "ci-"
>  
>      stale_images = {}
>      for img in images:
> -        if img["name"][3:] not in dockerfiles:
> +        if img["name"][len(name_prefix):] not in dockerfiles:
>              stale_images[img["name"]] = img["id"]
>  
>      return stale_images
> -- 
> 2.31.1
> 

Reviewed-by: Beraldo Leal <bleal@redhat.com>

--
Beraldo