]> code.ossystems Code Review - openembedded-core.git/commitdiff
wic: override ArgumentParser.error
authorEd Bartosh <ed.bartosh@linux.intel.com>
Mon, 18 Jan 2016 12:22:45 +0000 (14:22 +0200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 19 Jan 2016 16:35:38 +0000 (16:35 +0000)
Overriden error method to throw exception instead of
printing usage error message. Exception is caught by
KickStart code to add .ks file name and line number.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
scripts/lib/wic/kickstart.py

index 5d3a572a77621a12b70f4f2837361109bc723967..7dbe0527148201521166109c65e68ef6e1ea36e5 100644 (file)
@@ -34,6 +34,14 @@ from wic.partition import Partition
 class KickStartError(Exception):
     pass
 
+class KickStartParser(ArgumentParser):
+    """
+    This class overwrites error method to throw exception
+    instead of producing usage message(default argparse behavior).
+    """
+    def error(self, message):
+        raise ArgumentError(None, message)
+
 def sizetype(arg):
     """
     Custom type for ArgumentParser
@@ -77,7 +85,7 @@ class KickStart(object):
         self.bootloader = None
         self.lineno = 0
 
-        parser = ArgumentParser()
+        parser = KickStartParser()
         subparsers = parser.add_subparsers()
 
         part = subparsers.add_parser('part')