Re: [libvirt-ci PATCH] lcitool: Catch exceptions earlier

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux