[gen-otp-img] Add workaround for argparse extend action
Signed-off-by: Michael Schaffner <msf@opentitan.org>
diff --git a/util/design/gen-otp-img.py b/util/design/gen-otp-img.py
index fa48687..8b5f0da 100755
--- a/util/design/gen-otp-img.py
+++ b/util/design/gen-otp-img.py
@@ -42,6 +42,19 @@
name, new_seed))
+# TODO: this can be removed when we have moved to Python 3.8
+# in all regressions, since the extend action is only available
+# from that version onward.
+# This workaround solution has been taken verbatim from
+# https://stackoverflow.com/questions/41152799/argparse-flatten-the-result-of-action-append
+class ExtendAction(argparse.Action):
+ '''Extend action for the argument parser'''
+ def __call__(self, parser, namespace, values, option_string=None):
+ items = getattr(namespace, self.dest) or []
+ items.extend(values)
+ setattr(namespace, self.dest, items)
+
+
def main():
log.basicConfig(level=log.INFO, format="%(levelname)s: %(message)s")
@@ -57,6 +70,7 @@
prog="gen-otp-img",
description=wrapped_docstring(),
formatter_class=argparse.RawDescriptionHelpFormatter)
+ parser.register('action', 'extend', ExtendAction)
parser.add_argument('--img-seed',
type=int,
metavar='<seed>',