Merged from trunk -r14358:14368
authorFabian Groffen <grobian@gentoo.org>
Thu, 24 Sep 2009 17:22:25 +0000 (17:22 -0000)
committerFabian Groffen <grobian@gentoo.org>
Thu, 24 Sep 2009 17:22:25 +0000 (17:22 -0000)
   | 14361   | Fix decodeint() for py3k compat, since bytes are a sequence  |
   | zmedico | of integers instead of characters.                           |

   | 14362   | Temporarily disable use of pty in py3k since it triggers an  |
   | zmedico | unresolved issue, http://bugs.python.org/issue5380. With     |
   |         | this workaround,                                             |
   |         | portage.tests.ebuild.test_spawn.SpawnTestCase.testLogfile()  |
   |         | does not raise IOError.                                      |

   | 14363   | Don't encode the env in py3k since it expects strings for    |
   | zmedico | the env that's passed into os.execve().                      |

   | 14364   | Make find_binary() use os.environ.get instead of os.getenv,  |
   | zmedico | since os.getenv isn't behaving correctly in py3k (maybe a    |
   |         | unicode wrapper issue?).                                     |

   | 14365   | Fix PORTAGE_WORKDIR_MODE parsing code so it doesn't store    |
   | zmedico | python's octal syntax in the environment variable.           |

   | 14366   | In _unicode_func_wrapper, only encode keyword argument       |
   | zmedico | values, and not the keys.                                    |

   | 14367   | Encode/decode names from the xpak index where appropriate.   |
   | zmedico |                                                              |

   | 14368   | Fix sorted() keyword arg for py3k.                           |
   | zmedico |                                                              |

svn path=/main/branches/prefix/; revision=14403

pym/portage/__init__.py
pym/portage/getbinpkg.py
pym/portage/process.py
pym/portage/xpak.py

index 57976895dd9eb3db9e27f6ad6c7fa8b72546cf02..8366664280795f47d28231902785b928fb19c890 100644 (file)
@@ -183,8 +183,7 @@ class _unicode_func_wrapper(object):
                        for x in args]
                if kwargs:
                        wrapped_kwargs = dict(
-                               (_unicode_encode(k, encoding=encoding, errors='strict'),
-                               _unicode_encode(v, encoding=encoding, errors='strict'))
+                               (k, _unicode_encode(v, encoding=encoding, errors='strict'))
                                for k, v in kwargs.items())
                else:
                        wrapped_kwargs = {}
@@ -3763,6 +3762,10 @@ if platform.system() in ["SunOS"]:
 else:
        _disable_openpty = False
 
+if sys.hexversion >= 0x3000000:
+       # This is a temporary workaround for http://bugs.python.org/issue5380.
+       _disable_openpty = True
+
 def _create_pty_or_pipe(copy_term_size=None):
        """
        Try to create a pty and if then fails then create a normal
@@ -6307,7 +6310,7 @@ def _prepare_workdir(mysettings):
                        writemsg("%s\n" % e)
                writemsg(_("!!! Unable to parse PORTAGE_WORKDIR_MODE='%s', using %s.\n") % \
                (mysettings["PORTAGE_WORKDIR_MODE"], oct(workdir_mode)))
-       mysettings["PORTAGE_WORKDIR_MODE"] = oct(workdir_mode)
+       mysettings["PORTAGE_WORKDIR_MODE"] = oct(workdir_mode).replace('o', '')
        try:
                apply_secpass_permissions(mysettings["WORKDIR"],
                uid=portage_uid, gid=portage_gid, mode=workdir_mode)
index af010577af7bdf16f82e4d3e42c140f15547bf89..62e76b4f336b27f73edb09fdd71afefabe8bf524 100644 (file)
@@ -822,7 +822,8 @@ class PackageIndex(object):
                keys.sort()
                self._writepkgindex(pkgfile, [(k, self.header[k]) \
                        for k in keys if self.header[k]])
-               for metadata in sorted(self.packages, _cmp_cpv):
+               for metadata in sorted(self.packages,
+                       key=portage.util.cmp_sort_key(_cmp_cpv)):
                        metadata = metadata.copy()
                        cpv = metadata["CPV"]
                        if self._inherited_keys:
index 428c66f4cb51432f7702839426adc288c57f3664..e7f09cd2d212a5c37b10a17746a0ad1b5b77ec0c 100644 (file)
@@ -188,13 +188,14 @@ def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
        if isinstance(mycommand, basestring):
                mycommand = mycommand.split()
 
-       # Avoid a potential UnicodeEncodeError from os.execve().
-       env_bytes = {}
-       for k, v in env.items():
-               env_bytes[_unicode_encode(k, encoding=_encodings['content'])] = \
-                       _unicode_encode(v, encoding=_encodings['content'])
-       env = env_bytes
-       del env_bytes
+       if sys.hexversion < 0x3000000:
+               # Avoid a potential UnicodeEncodeError from os.execve().
+               env_bytes = {}
+               for k, v in env.items():
+                       env_bytes[_unicode_encode(k, encoding=_encodings['content'])] = \
+                               _unicode_encode(v, encoding=_encodings['content'])
+               env = env_bytes
+               del env_bytes
 
        # If an absolute path to an executable file isn't given
        # search for it unless we've been told not to.
@@ -373,13 +374,8 @@ def _exec(binary, mycommand, opt_name, fd_pipes, env, gid, groups, uid, umask,
        if pre_exec:
                pre_exec()
 
-       # Decode all keys for compatibility with Python 3.
-       env_decoded = {}
-       for k, v in env.items():
-               env_decoded[_unicode_decode(k)] = v
-
        # And switch to the new process.
-       os.execve(binary, myargs, env_decoded)
+       os.execve(binary, myargs, env)
 
 def find_binary(binary):
        """
@@ -390,8 +386,7 @@ def find_binary(binary):
        @rtype: None or string
        @returns: full path to binary or None if the binary could not be located.
        """
-       
-       for path in os.getenv("PATH", "").split(":"):
+       for path in os.environ.get("PATH", "").split(":"):
                filename = "%s/%s" % (path, binary)
                if os.access(filename, os.X_OK) and os.path.isfile(filename):
                        return filename
index b5878befb5c14194a9d719fda315aafc5594432e..b753f2490c0e54b3951a699f3390d49cfbb80a50 100644 (file)
@@ -19,6 +19,7 @@
 import array
 import errno
 import shutil
+import sys
 
 from portage import os
 from portage import normalize_path
@@ -65,11 +66,13 @@ def encodeint(myint):
 def decodeint(mystring):
        """Takes a 4 byte string and converts it into a 4 byte integer.
        Returns an integer."""
-       myint=0
-       myint=myint+ord(mystring[3])
-       myint=myint+(ord(mystring[2]) << 8)
-       myint=myint+(ord(mystring[1]) << 16)
-       myint=myint+(ord(mystring[0]) << 24)
+       if sys.hexversion < 0x3000000:
+               mystring = [ord(x) for x in mystring]
+       myint = 0
+       myint += mystring[3]
+       myint += mystring[2] << 8
+       myint += mystring[1] << 16
+       myint += mystring[0] << 24
        return myint
 
 def xpak(rootdir,outfile=None):
@@ -206,6 +209,8 @@ def getindex_mem(myindex):
 def searchindex(myindex,myitem):
        """(index,item) -- Finds the offset and length of the file 'item' in the
        datasegment via the index 'index' provided."""
+       myitem = _unicode_encode(myitem,
+               encoding=_encodings['repo.content'], errors='backslashreplace')
        mylen=len(myitem)
        myindexlen=len(myindex)
        startpos=0
@@ -413,6 +418,8 @@ class tbz2(object):
                        datapos=decodeint(self.index[startpos+4+namelen:startpos+8+namelen]);
                        datalen=decodeint(self.index[startpos+8+namelen:startpos+12+namelen]);
                        myname=self.index[startpos+4:startpos+4+namelen]
+                       myname = _unicode_decode(myname,
+                               encoding=_encodings['repo.content'], errors='replace')
                        dirname=os.path.dirname(myname)
                        if dirname:
                                if not os.path.exists(dirname):