summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Kjellerstedt <peter.kjellerstedt@axis.com>2019-06-19 17:45:05 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-06-30 22:34:23 +0100
commit5155d08e7e3e8295e6b9317c856061480c6010f9 (patch)
treeee7c84561bdb73c8c928e4b70297524730834812
parented7379718823b30ae9c85c1000c227fb84b29977 (diff)
downloadpoky-5155d08e7e3e8295e6b9317c856061480c6010f9.tar.gz
poky-5155d08e7e3e8295e6b9317c856061480c6010f9.tar.bz2
poky-5155d08e7e3e8295e6b9317c856061480c6010f9.zip
texinfo-dummy-native: Rewrite template.py to use argparse
The original version of template.py parses the arguments manually. This fails when looking for the -E option if, e.g., an -I option is specified without any space before its argument, and that argument contains the letter 'E'. A minor difference to the original version is that it parsed the arguments in the order they were specified on the command line whereas this version will always handle -E before -o. (From OE-Core rev: c4949e0109cc823101f56fc192474d3ceaa7d916) Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> Signed-off-by: Armin Kuster <akuster808@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-extended/texinfo-dummy-native/texinfo-dummy/template.py55
1 files changed, 18 insertions, 37 deletions
diff --git a/meta/recipes-extended/texinfo-dummy-native/texinfo-dummy/template.py b/meta/recipes-extended/texinfo-dummy-native/texinfo-dummy/template.py
index fcc28548af..86c7c1811a 100644
--- a/meta/recipes-extended/texinfo-dummy-native/texinfo-dummy/template.py
+++ b/meta/recipes-extended/texinfo-dummy-native/texinfo-dummy/template.py
@@ -28,10 +28,8 @@
# of the executable from argv[0] and emulate the corresponding program, so
# multiple copies of this script will exist under different names.
-import sys, os
+import sys, os, argparse
-olong = "--output="
-Elong = "--macro-expand="
this_binary = sys.argv[0].split("/")[-1]
@@ -61,18 +59,9 @@ complex_binaries = "makeinfo texi2any".split()
valid_binaries = simple_binaries + complex_binaries
-# For generating blank output files.
-def touch_file(path):
- with open(path, "w"):
- pass
-
assert this_binary in valid_binaries, \
this_binary + " is not one of " + ', '.join(valid_binaries)
-if "--version" in sys.argv:
- print(version_str)
- sys.exit(0)
-
# For debugging
log_interceptions = False
if log_interceptions:
@@ -81,35 +70,27 @@ if log_interceptions:
# Look through the options and flags, and if necessary, touch any output
# files.
-arg_idx = 1
-while arg_idx < len(sys.argv):
- arg = sys.argv [arg_idx]
-
- if arg == "--":
- break
+p = argparse.ArgumentParser()
+if this_binary in complex_binaries:
+ p.add_argument('-E', '--macro-expand', metavar='FILE')
+p.add_argument('-o', '--output', metavar='DEST')
+p.add_argument('--version', action='store_true')
- # Something like -I . can result in a need for this (specifically the .)
- elif len(arg) < 2:
- pass
-
- # Check if -o or --output is specified. These can be used at most once.
- elif arg[0] == '-' and arg[1] != '-' and arg[len(arg) - 1] == 'o':
- touch_file(sys.argv[arg_idx + 1])
- sys.exit(0)
- elif arg.startswith(olong):
- touch_file(arg.split("=")[1])
- sys.exit(0)
+args, unknown = p.parse_known_args()
- # Check for functionality that isn't implemented yet.
- else:
- assert arg[0] != '-' or arg[1] == '-' or 'E' not in arg or \
- this_binary in simple_binaries, \
- "-E option not yet supported" + stub_msg
+if args.version:
+ print(version_str)
+ sys.exit(0)
- assert not arg.startswith(Elong), \
- Elong[:-1] + " option not yet supported" + stub_msg
+# Check for functionality that isn't implemented yet.
+assert not getattr(args, 'macro_expand', None), \
+ "-E/--macro-expand option not yet supported" + stub_msg
- arg_idx += 1
+# Check if -o or --output is specified.
+if args.output:
+ with open(args.output, 'w'):
+ pass
+ sys.exit(0)
# The -o/--output option overrides the default. For makeinfo and texi2any,
# that default is to look for a @setfilename command in the input file.