Only print docker image list if not empty 74/13974/4
authorEric Ball <eball@linuxfoundation.org>
Thu, 13 Dec 2018 02:06:48 +0000 (18:06 -0800)
committerEric Ball <eball@linuxfoundation.org>
Thu, 13 Dec 2018 17:41:29 +0000 (09:41 -0800)
Issue: RELENG-1595
Change-Id: I516f5e6cedbe1e1bbf25f687e473ca3534c0b683
Signed-off-by: Eric Ball <eball@linuxfoundation.org>
lftools/cli/nexus.py
lftools/nexus/cmd.py

index 5576cf5..34e7ef1 100644 (file)
@@ -97,7 +97,8 @@ def list_images(ctx, settings, server, repo, pattern, csv):
     if not server and 'NEXUS_URL_ENV' in environ:
         server = environ['NEXUS_URL_ENV']
     images = nexuscmd.search(settings, server, repo, pattern)
-    nexuscmd.output_images(images, csv)
+    if images:
+        nexuscmd.output_images(images, csv)
 
 
 @docker.command(name="delete")
index 5e149ec..9195112 100644 (file)
@@ -233,14 +233,16 @@ def search(settings_file, url, repo, pattern):
 def output_images(images, csv_path=None):
     """Output a list of images to stdout, or a provided file path.
 
+    This method expects a list of dicts with, at a minimum, "name", "version",
+    and "id" fields defined in each.
     :arg list images: Images to output.
     :arg str csv_path: Path to write out csv file of matching images.
     """
-    count = len(images)
-    if not count:
+    if not images:
         log.warning("{}.{} called with empty images list".format(
             __name__, sys._getframe().f_code.co_name))
         return
+    count = len(images)
     included_keys = images[0].keys()
 
     if csv_path: