Python 3.1: pass bytes to Popen
[portage.git] / pym / portage / util / __init__.py
index 7c16b7bae67a60a18e5e425cc873a04cbe345d7f..69459b827678d2a1b851747006d2f5abdd90d821 100644 (file)
@@ -1698,10 +1698,17 @@ def find_updated_config_files(target_root, config_protect):
                                                os.path.split(x.rstrip(os.path.sep))
                        mycommand += " ! -name '.*~' ! -iname '.*.bak' -print0"
                        cmd = shlex_split(mycommand)
-                       if sys.hexversion < 0x3000000 or sys.hexversion >= 0x3020000:
-                               # Python 3.1 does not support bytes in Popen args.
-                               cmd = [_unicode_encode(arg, encoding=encoding, errors='strict')
-                                       for arg in cmd]
+
+                       if sys.hexversion < 0x3020000 and sys.hexversion >= 0x3000000:
+                               # Python 3.1 _execvp throws TypeError for non-absolute executable
+                               # path passed as bytes (see http://bugs.python.org/issue8513).
+                               fullname = portage.process.find_binary(cmd[0])
+                               if fullname is None:
+                                       raise portage.exception.CommandNotFound(cmd[0])
+                               cmd[0] = fullname
+
+                       cmd = [_unicode_encode(arg, encoding=encoding, errors='strict')
+                               for arg in cmd]
                        proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT)
                        output = _unicode_decode(proc.communicate()[0], encoding=encoding)