diff options
author | Peter Kjellerstedt <peter.kjellerstedt@axis.com> | 2019-05-23 20:42:54 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-05-27 17:06:34 +0100 |
commit | c1b73ad2eb37c30406f0a28a65f350ef65a20320 (patch) | |
tree | a1e6f09348302f72579dd319d5e4ac83ab91a4ac | |
parent | cf5dd9812c3a10f936ae7f48a9d9520994ddffce (diff) | |
download | poky-c1b73ad2eb37c30406f0a28a65f350ef65a20320.tar.gz |
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: 60e8de529eb0dfd546d96af3c2cdd7f23041ab45)
Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/recipes-extended/texinfo-dummy-native/texinfo-dummy/template.py | 55 |
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 @@ | |||
28 | # of the executable from argv[0] and emulate the corresponding program, so | 28 | # of the executable from argv[0] and emulate the corresponding program, so |
29 | # multiple copies of this script will exist under different names. | 29 | # multiple copies of this script will exist under different names. |
30 | 30 | ||
31 | import sys, os | 31 | import sys, os, argparse |
32 | 32 | ||
33 | olong = "--output=" | ||
34 | Elong = "--macro-expand=" | ||
35 | 33 | ||
36 | this_binary = sys.argv[0].split("/")[-1] | 34 | this_binary = sys.argv[0].split("/")[-1] |
37 | 35 | ||
@@ -61,18 +59,9 @@ complex_binaries = "makeinfo texi2any".split() | |||
61 | 59 | ||
62 | valid_binaries = simple_binaries + complex_binaries | 60 | valid_binaries = simple_binaries + complex_binaries |
63 | 61 | ||
64 | # For generating blank output files. | ||
65 | def touch_file(path): | ||
66 | with open(path, "w"): | ||
67 | pass | ||
68 | |||
69 | assert this_binary in valid_binaries, \ | 62 | assert this_binary in valid_binaries, \ |
70 | this_binary + " is not one of " + ', '.join(valid_binaries) | 63 | this_binary + " is not one of " + ', '.join(valid_binaries) |
71 | 64 | ||
72 | if "--version" in sys.argv: | ||
73 | print(version_str) | ||
74 | sys.exit(0) | ||
75 | |||
76 | # For debugging | 65 | # For debugging |
77 | log_interceptions = False | 66 | log_interceptions = False |
78 | if log_interceptions: | 67 | if log_interceptions: |
@@ -81,35 +70,27 @@ if log_interceptions: | |||
81 | 70 | ||
82 | # Look through the options and flags, and if necessary, touch any output | 71 | # Look through the options and flags, and if necessary, touch any output |
83 | # files. | 72 | # files. |
84 | arg_idx = 1 | 73 | p = argparse.ArgumentParser() |
85 | while arg_idx < len(sys.argv): | 74 | if this_binary in complex_binaries: |
86 | arg = sys.argv [arg_idx] | 75 | p.add_argument('-E', '--macro-expand', metavar='FILE') |
87 | 76 | p.add_argument('-o', '--output', metavar='DEST') | |
88 | if arg == "--": | 77 | p.add_argument('--version', action='store_true') |
89 | break | ||
90 | 78 | ||
91 | # Something like -I . can result in a need for this (specifically the .) | 79 | args, unknown = p.parse_known_args() |
92 | elif len(arg) < 2: | ||
93 | pass | ||
94 | |||
95 | # Check if -o or --output is specified. These can be used at most once. | ||
96 | elif arg[0] == '-' and arg[1] != '-' and arg[len(arg) - 1] == 'o': | ||
97 | touch_file(sys.argv[arg_idx + 1]) | ||
98 | sys.exit(0) | ||
99 | elif arg.startswith(olong): | ||
100 | touch_file(arg.split("=")[1]) | ||
101 | sys.exit(0) | ||
102 | 80 | ||
103 | # Check for functionality that isn't implemented yet. | 81 | if args.version: |
104 | else: | 82 | print(version_str) |
105 | assert arg[0] != '-' or arg[1] == '-' or 'E' not in arg or \ | 83 | sys.exit(0) |
106 | this_binary in simple_binaries, \ | ||
107 | "-E option not yet supported" + stub_msg | ||
108 | 84 | ||
109 | assert not arg.startswith(Elong), \ | 85 | # Check for functionality that isn't implemented yet. |
110 | Elong[:-1] + " option not yet supported" + stub_msg | 86 | assert not getattr(args, 'macro_expand', None), \ |
87 | "-E/--macro-expand option not yet supported" + stub_msg | ||
111 | 88 | ||
112 | arg_idx += 1 | 89 | # Check if -o or --output is specified. |
90 | if args.output: | ||
91 | with open(args.output, 'w'): | ||
92 | pass | ||
93 | sys.exit(0) | ||
113 | 94 | ||
114 | # The -o/--output option overrides the default. For makeinfo and texi2any, | 95 | # The -o/--output option overrides the default. For makeinfo and texi2any, |
115 | # that default is to look for a @setfilename command in the input file. | 96 | # that default is to look for a @setfilename command in the input file. |