Merged from trunk -r13909:13919
authorFabian Groffen <grobian@gentoo.org>
Wed, 5 Aug 2009 18:11:44 +0000 (18:11 -0000)
committerFabian Groffen <grobian@gentoo.org>
Wed, 5 Aug 2009 18:11:44 +0000 (18:11 -0000)
   | 13910   | Avoid UnicodeEncodeError with unicode package.mask comments. |
   | zmedico | Thanks to Thanks to Scott Moreau (soreau) for reporting.     |

   | 13911   | Fix bindbapi.aux_get and aux_update to work with             |
   | zmedico | py3k/unicode.                                                |

   | 13912   | Open all files in binary mode for py3k compatibility.        |
   | zmedico |                                                              |

   | 13913   | Open file in text mode (unicode) where appropriate.          |
   | zmedico |                                                              |

   | 13914   | In _check_build_log(), open the log in text mode (unicode).  |
   | zmedico |                                                              |

   | 13915   | Open ld.so.conf as text (unicode).                           |
   | zmedico |                                                              |

   | 13916   | Fix the FEATURES=parse-eapi-ebuild-head regex to handle      |
   | zmedico | comments on the same line, like this: EAPI=2 #foo Thanks to  |
   |         | Markus Meier <maekke@gentoo.org> for reporting.              |

   | 13917   | s/utf8/utf_8/ for consistency                                |
   | zmedico |                                                              |

   | 13919   | Fix insert_optional_args() to properly handle thinks like    |
   | zmedico | -Dk which require multiple substitutions of default          |
   |         | arguments.                                                   |

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

13 files changed:
pym/_emerge/Binpkg.py
pym/_emerge/BinpkgVerifier.py
pym/_emerge/EbuildBuild.py
pym/_emerge/EbuildFetcher.py
pym/_emerge/EbuildPhase.py
pym/_emerge/PackageUninstall.py
pym/_emerge/changelog.py
pym/_emerge/depgraph.py
pym/_emerge/emergelog.py
pym/_emerge/main.py
pym/portage/__init__.py
pym/portage/dbapi/bintree.py
pym/portage/xpak.py

index 9a11e0835d9a43ea682719582d62170d48448146..c538c4e09fb9ff7781fae1b45ff992a498b0fcac 100644 (file)
@@ -11,6 +11,7 @@ from _emerge.EbuildMerge import EbuildMerge
 from _emerge.EbuildBuildDir import EbuildBuildDir
 from portage.util import writemsg
 # for an explanation on this logic, see pym/_emerge/__init__.py
+import codecs
 import os
 import sys
 if os.environ.__contains__("PORTAGE_PYTHONPATH"):
@@ -36,7 +37,8 @@ class Binpkg(CompositeTask):
 
                log_path = self.settings.get("PORTAGE_LOG_FILE")
                if  log_path is not None:
-                       f = open(log_path, 'a')
+                       f = codecs.open(log_path, mode='a',
+                               encoding='utf_8', errors='replace')
                        try:
                                f.write(msg)
                        finally:
@@ -229,7 +231,8 @@ class Binpkg(CompositeTask):
                        else:
                                continue
 
-                       f = open(os.path.join(infloc, k), 'wb')
+                       f = codecs.open(os.path.join(infloc, k), mode='w',
+                               encoding='utf_8', errors='replace')
                        try:
                                f.write(v + "\n")
                        finally:
index 56190a60bbfe98febe85d03d8509c506cd7d1fcf..b4a4b8f423c42d0df90b5ffd9806998dcd7b3e8e 100644 (file)
@@ -6,6 +6,7 @@ from _emerge.AsynchronousTask import AsynchronousTask
 from portage.util import writemsg
 import sys
 # for an explanation on this logic, see pym/_emerge/__init__.py
+import codecs
 import os
 import sys
 if os.environ.__contains__("PORTAGE_PYTHONPATH"):
@@ -31,7 +32,8 @@ class BinpkgVerifier(AsynchronousTask):
                stderr_orig = sys.stderr
                log_file = None
                if self.background and self.logfile is not None:
-                       log_file = open(self.logfile, 'a')
+                       log_file = codecs.open(self.logfile, mode='a',
+                               encoding='utf_8', errors='replace')
                try:
                        if log_file is not None:
                                sys.stdout = log_file
index d7e769482ac4578443034a6563d6945e54226cd2..18c7c59f848c6380fb21d078bb74da0e4b9fe6e4 100644 (file)
@@ -12,6 +12,7 @@ from _emerge.EbuildFetchonly import EbuildFetchonly
 from _emerge.EbuildBuildDir import EbuildBuildDir
 from portage.util import writemsg
 # for an explanation on this logic, see pym/_emerge/__init__.py
+import codecs
 import os
 import sys
 if os.environ.__contains__("PORTAGE_PYTHONPATH"):
@@ -188,7 +189,8 @@ class EbuildBuild(CompositeTask):
 
                        log_path = self.settings.get("PORTAGE_LOG_FILE")
                        if log_path is not None:
-                               log_file = open(log_path, 'a')
+                               log_file = codecs.open(log_path, mode='a',
+                                       encoding='utf_8', errors='replace')
                                try:
                                        log_file.write(msg)
                                finally:
index b17484565e8a19e3654f26eee17df379fd5bd6c7..a292c6cdddfa3cd6fa5b503ce5ae64382137bf1c 100644 (file)
@@ -12,6 +12,7 @@ if os.environ.__contains__("PORTAGE_PYTHONPATH"):
 else:
        sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "pym"))
 import portage
+import codecs
 import os
 from portage.elog.messages import eerror
 class EbuildFetcher(SpawnProcess):
@@ -92,7 +93,8 @@ class EbuildFetcher(SpawnProcess):
                                elog_out = None
                                if self.logfile is not None:
                                        if self.background:
-                                               elog_out = open(self.logfile, 'a')
+                                               elog_out = codecs.open(self.logfile, mode='a',
+                                                       encoding='utf_8', errors='replace')
                                msg = "Fetch failed for '%s'" % (self.pkg.cpv,)
                                if self.logfile is not None:
                                        msg += ", Log file:"
index d88f9e77ab8201285ef2ba28827175d02c99c8a3..3df6248591c99a7470fd7b437aac6456ee786b3f 100644 (file)
@@ -7,6 +7,7 @@ from _emerge.EbuildProcess import EbuildProcess
 from _emerge.CompositeTask import CompositeTask
 from portage.util import writemsg
 # for an explanation on this logic, see pym/_emerge/__init__.py
+import codecs
 import os
 import sys
 if os.environ.__contains__("PORTAGE_PYTHONPATH"):
@@ -36,7 +37,8 @@ class EbuildPhase(CompositeTask):
                        log_path = self.settings.get("PORTAGE_LOG_FILE")
                        log_file = None
                        if self.background and log_path is not None:
-                               log_file = open(log_path, 'a')
+                               log_file = codecs.open(log_path, mode='a',
+                                       encoding='utf_8', errors='replace')
                                out = log_file
                        try:
                                portage._check_build_log(self.settings, out=out)
index dee26d2f30d5bc0b3fdb284e24ffc613ccc08e03..d430a4709fedc750982ef2649ac1278966dade2a 100644 (file)
@@ -2,6 +2,7 @@
 # Distributed under the terms of the GNU General Public License v2
 # $Id$
 
+import codecs
 import logging
 # for an explanation on this logic, see pym/_emerge/__init__.py
 import os
@@ -46,7 +47,8 @@ class PackageUninstall(AsynchronousTask):
                                portage.util.writemsg_level(msg,
                                        level=level, noiselevel=noiselevel)
 
-                       f = open(log_path, 'a')
+                       f = codecs.open(log_path, mode='a',
+                               encoding='utf_8', errors='replace')
                        try:
                                f.write(msg)
                        finally:
index 65427b23a5eb9831012614fc8ceaee1f0cc1effd..8fb25e01e4bc64a994838926716e1deba34dde29 100644 (file)
@@ -2,6 +2,7 @@
 # Distributed under the terms of the GNU General Public License v2
 # $Id$
 
+import codecs
 import os
 import re
 
@@ -25,7 +26,8 @@ def calc_changelog(ebuildpath,current,next):
                next = next[:-3]
        changelogpath = os.path.join(os.path.split(ebuildpath)[0],'ChangeLog')
        try:
-               changelog = open(changelogpath).read()
+               changelog = codecs.open(changelogpath, mode='r',
+                       encoding='utf_8', errors='replace').read()
        except SystemExit, e:
                raise # Needed else can't exit
        except:
index f9363df9f9d6325c76d6745b2e1e15f36980a158..8a5fba520f866fe41430b0ba790adbd60789df63 100644 (file)
@@ -4356,6 +4356,14 @@ class depgraph(object):
                if "--changelog" in self._frozen_config.myopts:
                        print
                        for revision,text in changelogs:
+
+                               if sys.hexversion < 0x3000000:
+                                       # avoid potential UnicodeEncodeError
+                                       if isinstance(revision, unicode):
+                                               revision = revision.encode('utf_8', 'replace')
+                                       if isinstance(text, unicode):
+                                               text = text.encode('utf_8', 'replace')
+
                                print bold('*'+revision)
                                sys.stdout.write(text)
 
@@ -5113,6 +5121,11 @@ def show_masked_packages(masked_packages):
                                pass
 
                print "- "+cpv+" (masked by: "+", ".join(mreasons)+")"
+
+               if sys.hexversion < 0x3000000 and isinstance(comment, unicode):
+                       # avoid potential UnicodeEncodeError
+                       comment = comment.encode('utf_8', 'replace')
+
                if comment and comment not in shown_comments:
                        print filename+":"
                        print comment
index 4c8f5471932948d924dbc9891713c74452b171b8..67aa3f00ee4b90019d14b71c0a7a9128b2c38430 100644 (file)
@@ -2,6 +2,7 @@
 # Distributed under the terms of the GNU General Public License v2
 # $Id$
 
+import codecs
 import os
 import sys
 import time
@@ -27,7 +28,8 @@ def emergelog(xterm_titles, mystr, short_msg=None):
                xtermTitle(short_msg)
        try:
                file_path = os.path.join(_emerge_log_dir, 'emerge.log')
-               mylogfile = open(file_path, "a")
+               mylogfile = codecs.open(file_path, mode='a',
+                       encoding='utf_8', errors='replace')
                portage.util.apply_secpass_permissions(file_path,
                        uid=portage.portage_uid, gid=portage.portage_gid,
                        mode=0660)
index 2113c1b6ef53fa78984011ab98a1da83724fbd08..5edb4c5ab7e13f7106822d46794feede49810765 100644 (file)
@@ -487,7 +487,9 @@ def insert_optional_args(args):
                        new_args.append(opt_arg)
 
                if saved_opts is not None:
-                       new_args.append("-" + saved_opts)
+                       # Recycle these on arg_stack since they
+                       # might contain another match.
+                       arg_stack.append("-" + saved_opts)
 
        return new_args
 
index d884f8cb8d173902f2bd2d558437d5062d46bf3d..873b3eb331d09111f0235bec5827228c3e9904e6 100644 (file)
@@ -727,7 +727,8 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
 
        ldsoconf_path = os.path.join(target_root, EPREFIX_LSTRIP, "etc", "ld.so.conf")
        try:
-               myld = open(ldsoconf_path)
+               myld = codecs.open(ldsoconf_path, mode='r',
+                       encoding='utf_8', errors='replace')
                myldlines=myld.readlines()
                myld.close()
                oldld=[]
@@ -5034,7 +5035,8 @@ def _check_build_log(mysettings, out=None):
        if logfile is None:
                return
        try:
-               f = open(logfile)
+               f = codecs.open(logfile, mode='r',
+                       encoding='utf_8', errors='replace')
        except EnvironmentError:
                return
 
@@ -5295,7 +5297,7 @@ def eapi_is_supported(eapi):
 # the ebuild.
 _validate_cache_for_unsupported_eapis = True
 
-_parse_eapi_ebuild_head_re = re.compile(r'^EAPI=[\'"]?([^\'"]*)')
+_parse_eapi_ebuild_head_re = re.compile(r'^EAPI=[\'"]?([^\'"#]*)')
 _parse_eapi_ebuild_head_max_lines = 30
 
 def _parse_eapi_ebuild_head(f):
index 6bd47ec1faf28dd49f886e619c91d16f4972321e..313a41598e0c57ee49ca855124d0d601d0db9b0e 100644 (file)
@@ -25,6 +25,7 @@ from portage import dep_expand, listdir, _check_distfile, _movefile
 import codecs
 import os, errno, stat
 import re
+import sys
 from itertools import chain, izip
 
 class bindbapi(fakedbapi):
@@ -68,7 +69,12 @@ class bindbapi(fakedbapi):
                        tbz2_path = self.bintree.getname(mycpv)
                        if not os.path.exists(tbz2_path):
                                raise KeyError(mycpv)
-                       getitem = portage.xpak.tbz2(tbz2_path).getfile
+                       tbz2 = portage.xpak.tbz2(tbz2_path)
+                       def getitem(k):
+                               v = tbz2.getfile(k)
+                               if v is not None and not isinstance(v, unicode):
+                                       v = unicode(v, encoding='utf_8', errors='replace')
+                               return v
                else:
                        getitem = self.bintree._remotepkgs[mycpv].get
                mydata = {}
@@ -81,15 +87,16 @@ class bindbapi(fakedbapi):
                        # or the tbz2 is corrupt.
                        if myval:
                                mydata[x] = " ".join(myval.split())
-               if "EAPI" in mykeys:
-                       if not mydata.setdefault("EAPI", "0"):
-                               mydata["EAPI"] = "0"
+
+               if not mydata.setdefault('EAPI', u'0'):
+                       mydata['EAPI'] = u'0'
+
                if cache_me:
                        aux_cache = self._aux_cache_slot_dict()
                        for x in self._aux_cache_keys:
-                               aux_cache[x] = mydata.get(x, "")
+                               aux_cache[x] = mydata.get(x, u'')
                        self._aux_cache[mycpv] = aux_cache
-               return [mydata.get(x, "") for x in wants]
+               return [mydata.get(x, u'') for x in wants]
 
        def aux_update(self, cpv, values):
                if not self.bintree.populated:
@@ -99,7 +106,23 @@ class bindbapi(fakedbapi):
                        raise KeyError(cpv)
                mytbz2 = portage.xpak.tbz2(tbz2path)
                mydata = mytbz2.get_data()
-               mydata.update(values)
+
+               if sys.hexversion < 0x3000000:
+                       for k, v in values.iteritems():
+                               if isinstance(k, unicode):
+                                       k = k.encode('utf_8', 'replace')
+                               if isinstance(v, unicode):
+                                       v = v.encode('utf_8', 'replace')
+                               mydata[k] = v
+
+               else:
+                       for k, v in values.iteritems():
+                               if isinstance(k, str):
+                                       k = k.encode('utf_8', 'replace')
+                               if isinstance(v, str):
+                                       v = v.encode('utf_8', 'replace')
+                               mydata[k] = v
+
                for k, v in mydata.items():
                        if not v:
                                del mydata[k]
@@ -1083,7 +1106,7 @@ class binarytree(object):
                pkgindex = self._new_pkgindex()
                try:
                        f = codecs.open(self._pkgindex_file, 
-                               encoding='utf8', errors='replace')
+                               encoding='utf_8', errors='replace')
                except EnvironmentError:
                        pass
                else:
index e24da3010501f1a3b82616a55f0100cfa3581f49..a1516e0338abd4db77a1888bb8fd90fc65329206 100644 (file)
@@ -68,14 +68,14 @@ def xpak(rootdir,outfile=None):
        mylist.sort()
        mydata = {}
        for x in mylist:
-               a = open(x, "r")
+               a = open(x, 'rb')
                mydata[x] = a.read()
                a.close()
        os.chdir(origdir)
 
        xpak_segment = xpak_mem(mydata)
        if outfile:
-               outf = open(outfile, "w")
+               outf = open(outfile, 'wb')
                outf.write(xpak_segment)
                outf.close()
        else:
@@ -104,7 +104,7 @@ def xsplit(infile):
        """(infile) -- Splits the infile into two files.
        'infile.index' contains the index segment.
        'infile.dat' contails the data segment."""
-       myfile=open(infile,"r")
+       myfile = open(infile, 'rb')
        mydat=myfile.read()
        myfile.close()
        
@@ -112,10 +112,10 @@ def xsplit(infile):
        if not splits:
                return False
        
-       myfile=open(infile+".index","w")
+       myfile = open(infile + '.index', 'wb')
        myfile.write(splits[0])
        myfile.close()
-       myfile=open(infile+".dat","w")
+       myfile = open(infile + '.dat', 'wb')
        myfile.write(splits[1])
        myfile.close()
        return True
@@ -130,7 +130,7 @@ def xsplit_mem(mydat):
 
 def getindex(infile):
        """(infile) -- grabs the index segment from the infile and returns it."""
-       myfile=open(infile,"r")
+       myfile = open(infile, 'rb')
        myheader=myfile.read(16)
        if myheader[0:8]!="XPAKPACK":
                myfile.close()
@@ -143,7 +143,7 @@ def getindex(infile):
 def getboth(infile):
        """(infile) -- grabs the index and data segments from the infile.
        Returns an array [indexSegment,dataSegment]"""
-       myfile=open(infile,"r")
+       myfile = open(infile, 'rb')
        myheader=myfile.read(16)
        if myheader[0:8]!="XPAKPACK":
                myfile.close()
@@ -217,7 +217,7 @@ def xpand(myid,mydest):
                if dirname:
                        if not os.path.exists(dirname):
                                os.makedirs(dirname)
-               mydat=open(myname,"w")
+               mydat = open(myname, 'wb')
                mydat.write(mydata[datapos:datapos+datalen])
                mydat.close()
                startpos=startpos+namelen+12
@@ -262,7 +262,7 @@ class tbz2(object):
 
        def recompose_mem(self, xpdata):
                self.scan() # Don't care about condition... We'll rewrite the data anyway.
-               myfile=open(self.file,"a+")
+               myfile = open(self.file, 'ab+')
                if not myfile:
                        raise IOError
                myfile.seek(-self.xpaksize,2) # 0,2 or -0,2 just mean EOF.
@@ -298,7 +298,7 @@ class tbz2(object):
                                if not changed:
                                        return 1
                        self.filestat=mystat
-                       a=open(self.file,"r")
+                       a = open(self.file, 'rb')
                        a.seek(-16,2)
                        trailer=a.read()
                        self.infosize=0
@@ -341,7 +341,7 @@ class tbz2(object):
                myresult=searchindex(self.index,myfile)
                if not myresult:
                        return mydefault
-               a=open(self.file,"r")
+               a = open(self.file, 'rb')
                a.seek(self.datapos+myresult[0],0)
                myreturn=a.read(myresult[1])
                a.close()
@@ -365,7 +365,7 @@ class tbz2(object):
                except:
                        os.chdir("/")
                        origdir="/"
-               a=open(self.file,"r")
+               a = open(self.file, 'rb')
                if not os.path.exists(mydest):
                        os.makedirs(mydest)
                os.chdir(mydest)
@@ -379,7 +379,7 @@ class tbz2(object):
                        if dirname:
                                if not os.path.exists(dirname):
                                        os.makedirs(dirname)
-                       mydat=open(myname,"w")
+                       mydat = open(myname, 'wb')
                        a.seek(self.datapos+datapos)
                        mydat.write(a.read(datalen))
                        mydat.close()
@@ -392,7 +392,7 @@ class tbz2(object):
                """Returns all the files from the dataSegment as a map object."""
                if not self.scan():
                        return 0
-               a = open(self.file, "r")
+               a = open(self.file, 'rb')
                mydata = {}
                startpos=0
                while ((startpos+8)<self.indexsize):
@@ -411,7 +411,7 @@ class tbz2(object):
                if not self.scan():
                        return None
 
-               a = open(self.file,"r")
+               a = open(self.file, 'rb')
                a.seek(self.datapos)
                mydata =a.read(self.datasize)
                a.close()