argparse_oe: Add int_positive type

Sometimes only expect positive values from cmdline so it's better
to filter at parsing cmdline step instead of validate later.

(From OE-Core rev: 3ef5b518febd047bf90a0955fa2b9fb78ba6dde5)

Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Aníbal Limón 2017-07-11 09:16:28 -07:00 committed by Richard Purdie
parent c8330a053b
commit 3aa299d51b

View File

@ -167,3 +167,10 @@ class OeHelpFormatter(argparse.HelpFormatter):
return '\n'.join(lines)
else:
return super(OeHelpFormatter, self)._format_action(action)
def int_positive(value):
ivalue = int(value)
if ivalue <= 0:
raise argparse.ArgumentTypeError(
"%s is not a positive int value" % value)
return ivalue