From 373016ba08c2ec4dbcd44649d9c8cd57d5574402 Mon Sep 17 00:00:00 2001 From: Ed Bartosh Date: Mon, 18 Jan 2016 14:22:45 +0200 Subject: 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. Signed-off-by: Ed Bartosh Signed-off-by: Richard Purdie --- scripts/lib/wic/kickstart.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'scripts/lib/wic') diff --git a/scripts/lib/wic/kickstart.py b/scripts/lib/wic/kickstart.py index 5d3a572a77..7dbe052714 100644 --- a/scripts/lib/wic/kickstart.py +++ b/scripts/lib/wic/kickstart.py @@ -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') -- cgit v1.2.3