wic: override ArgumentParser.error

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.

(From OE-Core rev: 373016ba08c2ec4dbcd44649d9c8cd57d5574402)

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ed Bartosh
2016-01-18 14:22:45 +02:00
committed by Richard Purdie
parent d652203b2f
commit 3bb6ea63fc

View 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')