[libvirt-ci PATCH] lcitool: Catch exceptions earlier

Andrea Bolognani abologna at redhat.com
Mon May 11 12:52:17 UTC 2020


On Mon, 2020-05-11 at 14:03 +0200, Erik Skultety wrote:
> On Thu, May 07, 2020 at 05:41:57PM +0200, Andrea Bolognani wrote:
> > -        installparser.set_defaults(func=self._action_install)
> > +        installparser.set_defaults(action="install")
> 
> please, keep the usage of the 'func' attribute:
> .set_defaults(func=Application._action_install)
> 
> > -    def run(self):
> > -        args = self._parser.parse_args()
> > -        if args.debug:
> > -            args.func(args)
> > -        else:
> > -            try:
> > -                args.func(args)
> > -            except Exception as err:
> > -                sys.stderr.write("{}: {}\n".format(sys.argv[0], err))
> > -                sys.exit(1)
> > +    def run(self, args):
> > +        getattr(self, "_action_" + args.action)(args)
> 
> Okay, ^this is obfuscation:
> 1) the action attribute should not be misused for your own metadata, it defines
>    a small set of actions to take when the option was seen on the cmdline [1]
>    - for arbitrary actions, instantiate argparse.Action instead (also to be
>      seen found at [1]) - you don't want to do this either in this case,
> instead, respect the meaning of the 'func' attribute

I did not realize "action" and "func" had special meaning for
argparse. I'll adopt your suggestion.

-- 
Andrea Bolognani / Red Hat / Virtualization




More information about the libvir-list mailing list