[libvirt] [jenkins-ci PATCH v2 03/20] quayadmin: Tweak quiet logic

Andrea Bolognani posted 20 patches 6 years, 5 months ago
[libvirt] [jenkins-ci PATCH v2 03/20] quayadmin: Tweak quiet logic
Posted by Andrea Bolognani 6 years, 5 months ago
If we've been asked not to produce any output, we can bail
early: doing so means we don't need to increase indentation
for subsequent code, and in some cases we can even avoid
fetching the JSON data from the response object.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
---
 guests/quayadmin | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/guests/quayadmin b/guests/quayadmin
index 5dc5eff..3e6cc87 100755
--- a/guests/quayadmin
+++ b/guests/quayadmin
@@ -83,9 +83,12 @@ def run_show_repo(args):
                  .format(args.namespace, args.repo)):
         return 1
 
+    if args.quiet:
+        return 0
+
     info = res.json()
-    if not args.quiet:
-        print("{}/{}: {}".format(args.namespace, args.repo, info["description"]))
+
+    print("{}/{}: {}".format(args.namespace, args.repo, info["description"]))
 
 
 def run_create_repo(args):
@@ -101,8 +104,10 @@ def run_create_repo(args):
                  .format(args.namespace, args.repo)):
         return 1
 
-    if not args.quiet:
-        print("Repository {}/{} created".format(args.namespace, args.repo))
+    if args.quiet:
+        return 0
+
+    print("Repository {}/{} created".format(args.namespace, args.repo))
 
 
 def run_delete_repo(args):
@@ -112,8 +117,10 @@ def run_delete_repo(args):
                  .format(args.namespace, args.repo)):
         return 1
 
-    if not args.quiet:
-        print("Repository {}/{} deleted".format(args.namespace, args.repo))
+    if args.quiet:
+        return 0
+
+    print("Repository {}/{} deleted".format(args.namespace, args.repo))
 
 
 def add_arg_namespace(parser):
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [jenkins-ci PATCH v2 03/20] quayadmin: Tweak quiet logic
Posted by Daniel P. Berrangé 6 years, 5 months ago
On Wed, Jul 17, 2019 at 03:49:12PM +0200, Andrea Bolognani wrote:
> If we've been asked not to produce any output, we can bail
> early: doing so means we don't need to increase indentation
> for subsequent code, and in some cases we can even avoid
> fetching the JSON data from the response object.

Unless I'm mis-reading the last point doesn't seem to affect
this patch - we're still fetching JSON, which is good I think,
as it means we check the response is well formed, and not an
error of some kind

> 
> Signed-off-by: Andrea Bolognani <abologna@redhat.com>
> ---
>  guests/quayadmin | 19 +++++++++++++------
>  1 file changed, 13 insertions(+), 6 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

> 
> diff --git a/guests/quayadmin b/guests/quayadmin
> index 5dc5eff..3e6cc87 100755
> --- a/guests/quayadmin
> +++ b/guests/quayadmin
> @@ -83,9 +83,12 @@ def run_show_repo(args):
>                   .format(args.namespace, args.repo)):
>          return 1
>  
> +    if args.quiet:
> +        return 0
> +
>      info = res.json()
> -    if not args.quiet:
> -        print("{}/{}: {}".format(args.namespace, args.repo, info["description"]))
> +
> +    print("{}/{}: {}".format(args.namespace, args.repo, info["description"]))
>  
>  
>  def run_create_repo(args):
> @@ -101,8 +104,10 @@ def run_create_repo(args):
>                   .format(args.namespace, args.repo)):
>          return 1
>  
> -    if not args.quiet:
> -        print("Repository {}/{} created".format(args.namespace, args.repo))
> +    if args.quiet:
> +        return 0
> +
> +    print("Repository {}/{} created".format(args.namespace, args.repo))
>  
>  
>  def run_delete_repo(args):
> @@ -112,8 +117,10 @@ def run_delete_repo(args):
>                   .format(args.namespace, args.repo)):
>          return 1
>  
> -    if not args.quiet:
> -        print("Repository {}/{} deleted".format(args.namespace, args.repo))
> +    if args.quiet:
> +        return 0
> +
> +    print("Repository {}/{} deleted".format(args.namespace, args.repo))
>  
>  
>  def add_arg_namespace(parser):
> -- 
> 2.21.0
> 
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [jenkins-ci PATCH v2 03/20] quayadmin: Tweak quiet logic
Posted by Andrea Bolognani 6 years, 5 months ago
On Wed, 2019-07-17 at 18:14 +0100, Daniel P. Berrangé wrote:
> On Wed, Jul 17, 2019 at 03:49:12PM +0200, Andrea Bolognani wrote:
> > If we've been asked not to produce any output, we can bail
> > early: doing so means we don't need to increase indentation
> > for subsequent code, and in some cases we can even avoid
> > fetching the JSON data from the response object.
> 
> Unless I'm mis-reading the last point doesn't seem to affect
> this patch - we're still fetching JSON, which is good I think,
> as it means we check the response is well formed, and not an
> error of some kind

We skip calling res.json() when all we need the JSON for is some
data to be displayed and we're in quiet mode. All the usual checks
on the return code still happens. I assume res.json() needs to do
some processing when it's called, and now we can skip that.

Either way that's a secondary concern, it was mostly about the
indentation :)

Thanks for the review, and for getting the script started in the
first place! The entire series has been pushed now.

-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list