[OE-core] [PATCH 28/30] argparse_oe: Add int_positive type

Leonardo Sandoval leonardo.sandoval.gonzalez at linux.intel.com
Wed Jul 12 14:33:04 UTC 2017


On Tue, 2017-07-11 at 15:23 -0500, Aníbal Limón wrote:
> Sometimes only expect positive values from cmdline so it's better
> to filter at parsing cmdline step instead of validate later.
> 
> Signed-off-by: Aníbal Limón <anibal.limon at linux.intel.com>
> ---
>  scripts/lib/argparse_oe.py | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/scripts/lib/argparse_oe.py b/scripts/lib/argparse_oe.py
> index bf6eb17197b..9bdfc1ceca2 100644
> --- a/scripts/lib/argparse_oe.py
> +++ b/scripts/lib/argparse_oe.py
> @@ -167,3 +167,10 @@ class OeHelpFormatter(argparse.HelpFormatter):
>              return '\n'.join(lines)
>          else:
>              return super(OeHelpFormatter, self)._format_action(action)
> +


when adding an argument into a script, one can define the type expected
so and the library itself does what you are doing for free, so not sure
if this is needed.



> +def int_positive(value):
> +    ivalue = int(value)
> +    if ivalue <= 0:
> +        raise argparse.ArgumentTypeError(
> +                "%s is not a positive int value" % value)
> +    return ivalue





More information about the Openembedded-core mailing list