Gentoo Archives: gentoo-portage-dev

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

Replies