From: Eric Ball Date: Thu, 13 Dec 2018 02:06:48 +0000 (-0800) Subject: Only print docker image list if not empty X-Git-Tag: v0.20.0~15 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F74%2F13974%2F4;p=releng%2Flftools.git Only print docker image list if not empty Issue: RELENG-1595 Change-Id: I516f5e6cedbe1e1bbf25f687e473ca3534c0b683 Signed-off-by: Eric Ball --- diff --git a/lftools/cli/nexus.py b/lftools/cli/nexus.py index 5576cf5e..34e7ef1d 100644 --- a/lftools/cli/nexus.py +++ b/lftools/cli/nexus.py @@ -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") diff --git a/lftools/nexus/cmd.py b/lftools/nexus/cmd.py index 5e149ece..9195112c 100644 --- a/lftools/nexus/cmd.py +++ b/lftools/nexus/cmd.py @@ -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: