]> code.ossystems Code Review - openembedded-core.git/commitdiff
argparse_oe: Add int_positive type
authorAníbal Limón <anibal.limon@linux.intel.com>
Tue, 11 Jul 2017 16:16:28 +0000 (09:16 -0700)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 21 Jul 2017 07:44:20 +0000 (08:44 +0100)
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@linux.intel.com>
scripts/lib/argparse_oe.py

index bf6eb17197b89f4502eb3523b577517aa886b5a1..9bdfc1ceca2e6426e5eb5dda16444705d6a08581 100644 (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