[OE-core] [PATCH 28/30] argparse_oe: Add int_positive type
Aníbal Limón
anibal.limon at linux.intel.com
Tue Jul 11 20:23:43 UTC 2017
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)
+
+def int_positive(value):
+ ivalue = int(value)
+ if ivalue <= 0:
+ raise argparse.ArgumentTypeError(
+ "%s is not a positive int value" % value)
+ return ivalue
--
2.11.0
More information about the Openembedded-core
mailing list