1 |
On 11/7/19 1:18 PM, Mike Gilbert wrote: |
2 |
> The --context option accepts an optional argument, but only if it is |
3 |
> passed via --context=arg. The argparse module does not deal with this |
4 |
> properly. |
5 |
> |
6 |
> To work around this, have argparse ignore this option, and filter out |
7 |
> any remaining arguments that start with a hyphen and do not occur after |
8 |
> a "--" delimiter. |
9 |
> |
10 |
> Bug: https://bugs.gentoo.org/699548 |
11 |
> Signed-off-by: Mike Gilbert <floppym@g.o> |
12 |
> --- |
13 |
> |
14 |
> If there is a cleaner way to do this, suggestions are welcome. |
15 |
> |
16 |
> diff --git a/bin/install.py b/bin/install.py |
17 |
> index d3789ed96..495534d33 100755 |
18 |
> --- a/bin/install.py |
19 |
> +++ b/bin/install.py |
20 |
> @@ -111,12 +111,6 @@ def parse_args(args): |
21 |
> action="store_true", |
22 |
> dest="no_target_directory" |
23 |
> ) |
24 |
> - parser.add_argument( |
25 |
> - "--context", |
26 |
> - "-Z", |
27 |
> - action="store", |
28 |
> - dest="context" |
29 |
> - ) |
30 |
> parser.add_argument( |
31 |
> "--verbose", |
32 |
> "-v", |
33 |
> @@ -143,11 +137,21 @@ def parse_args(args): |
34 |
> # for known options in order for argparse to correctly |
35 |
> # separate option arguments from file arguments in all |
36 |
> # cases (it also allows for optparse compatibility). |
37 |
> - parsed_args = parser.parse_known_args() |
38 |
> + (opts, args) = parser.parse_known_args(args) |
39 |
> + |
40 |
> + files = [] |
41 |
> + i = 0 |
42 |
> + while i < len(args): |
43 |
> + if args[i] == "--": |
44 |
> + i += 1 |
45 |
> + break |
46 |
> + if not args[i].startswith("-"): |
47 |
> + files.append(args[i]) |
48 |
> + i += 1 |
49 |
> |
50 |
> - opts = parsed_args[0] |
51 |
> - files = parsed_args[1] |
52 |
> - files = [f for f in files if f != "--"] # filter out "--" |
53 |
> + while i < len(args): |
54 |
> + files.append(args[i]) |
55 |
> + i += 1 |
56 |
> |
57 |
> return (opts, files) |
58 |
> |
59 |
> |
60 |
|
61 |
Looks good. Please merge. |
62 |
-- |
63 |
Thanks, |
64 |
Zac |