commit:     f6369a67d33fd5e95e02cf9b3cee41213a3b8804
Author:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Thu Nov  7 18:16:09 2019 +0000
Commit:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Fri Nov  8 15:59:47 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=f6369a67

install.py: ignore -Z / --context

The --context option accepts an optional argument, but only if it is
passed via --context=arg. The argparse module does not deal with this
properly.

To work around this, have argparse ignore this option, and filter out
any remaining arguments that start with a hyphen and do not occur after
a "--" delimiter.

Bug: https://bugs.gentoo.org/699548
Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>
Reviewed-by: Zec Medico <zmedico <AT> gentoo.org>

 bin/install.py | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/bin/install.py b/bin/install.py
index d3789ed96..495534d33 100755
--- a/bin/install.py
+++ b/bin/install.py
@@ -111,12 +111,6 @@ def parse_args(args):
                action="store_true",
                dest="no_target_directory"
        )
-       parser.add_argument(
-               "--context",
-               "-Z",
-               action="store",
-               dest="context"
-       )
        parser.add_argument(
                "--verbose",
                "-v",
@@ -143,11 +137,21 @@ def parse_args(args):
        # for known options in order for argparse to correctly
        # separate option arguments from file arguments in all
        # cases (it also allows for optparse compatibility).
-       parsed_args = parser.parse_known_args()
+       (opts, args) = parser.parse_known_args(args)
+
+       files = []
+       i = 0
+       while i < len(args):
+               if args[i] == "--":
+                       i += 1
+                       break
+               if not args[i].startswith("-"):
+                       files.append(args[i])
+               i += 1
 
-       opts  = parsed_args[0]
-       files = parsed_args[1]
-       files = [f for f in files if f != "--"] # filter out "--"
+       while i < len(args):
+               files.append(args[i])
+               i += 1
 
        return (opts, files)
 

Reply via email to