sys.path.insert(0, pym_path)
import portage
+ args = sys.argv[2:]
+ if args and not isinstance(args[0], unicode):
+ for i in xrange(len(args)):
+ args[i] = unicode(args[i], encoding='utf_8', errors='replace')
+
try:
if uses_root:
- sys.argv[2] = portage.settings["ROOT"]
- retval = function(sys.argv[2:])
+ args[0] = portage.settings["ROOT"]
+ retval = function(args)
if retval:
sys.exit(retval)
except portage.exception.PermissionDenied, e:
# Distributed under the terms of the GNU General Public License v2
# $Id$
+import codecs
import logging
import os
import sys
return self._pkg(cpv, type_name, root_config, installed=installed)
def _append_to_log_path(self, log_path, msg):
- f = open(log_path, 'a')
+ f = codecs.open(log_path, mode='a',
+ encoding='utf_8', errors='replace')
try:
f.write(msg)
finally:
background = self._background
if 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:
log_path = self._locate_failure_log(failed_pkg)
if log_path is not None:
try:
- log_file = open(log_path)
+ log_file = codecs.open(log_path, mode='r',
+ encoding='utf_8', errors='replace')
except IOError:
pass
if myaction is None and myoptions.deselect is True:
myaction = 'deselect'
+ if myargs and not isinstance(myargs[0], unicode):
+ for i in xrange(len(myargs)):
+ myargs[i] = unicode(myargs[i], encoding='utf_8', errors='replace')
+
myfiles += myargs
return myaction, myopts, myfiles
self._accept_chost_re = None
self._accept_license = None
self._accept_license_str = None
+ self._license_groups = {}
self.virtuals = {}
self.virts_p = {}
self._accept_license = copy.deepcopy(clone._accept_license)
self._plicensedict = copy.deepcopy(clone._plicensedict)
+ self._license_groups = copy.deepcopy(clone._license_groups)
else:
def check_var_directory(varname, var):
self.pprovideddict[mycatpkg]=[x]
# parse licensegroups
- self._license_groups = {}
for x in locations:
self._license_groups.update(
grabdict(os.path.join(x, "license_groups")))
from portage.cache.mappings import slot_dict_class
+import codecs
import os, re, shutil, stat, errno, copy, subprocess
import logging
import shlex
cache_mtime, metadata = pkg_data
cache_valid = cache_mtime == mydir_mtime
if cache_valid:
+ for k, v in metadata.iteritems():
+ if not isinstance(v, unicode):
+ # Migrate old metadata to unicode.
+ metadata[k] = unicode(v,
+ encoding='utf_8', errors='replace')
+
mydata.update(metadata)
pull_me.difference_update(mydata)
if not mydata['SLOT']:
# Empty slot triggers InvalidAtom exceptions when generating slot
# atoms for packages, so translate it to '0' here.
- mydata['SLOT'] = '0'
+ mydata['SLOT'] = u'0'
return [mydata[x] for x in wants]
def _aux_get(self, mycpv, wants, st=None):
results.append(long(st.st_mtime))
continue
try:
- myf = open(os.path.join(mydir, x), "r")
+ myf = codecs.open(os.path.join(mydir, x),
+ mode='r', encoding='utf_8', errors='replace')
try:
myd = myf.read()
finally:
if self._aux_multi_line_re.match(x) is None:
myd = " ".join(myd.split())
except IOError:
- myd = ""
+ myd = u''
if x == "EAPI" and not myd:
- results.append("0")
+ results.append(u'0')
else:
results.append(myd)
return results
return self.contentscache
pkgfiles = {}
try:
- myc = open(contents_file,"r")
+ myc = codecs.open(contents_file, mode='r',
+ encoding='utf_8', errors='replace')
except EnvironmentError, e:
if e.errno != errno.ENOENT:
raise
lcfile.close()
# open CONTENTS file (possibly overwriting old one) for recording
- outfile = open(os.path.join(self.dbtmpdir, "CONTENTS"),"w")
+ outfile = codecs.open(os.path.join(self.dbtmpdir, 'CONTENTS'),
+ mode='w', encoding='utf_8', errors='replace')
self.updateprotect()
tarinfo.size = 0
tar.addfile(tarinfo)
else:
- f = open(path)
+ f = open(path, 'rb')
try:
tar.addfile(tarinfo, f)
finally:
identical instances when available.
"""
def __call__(cls, s):
+ if isinstance(s, Atom):
+ return s
instance = cls._atoms.get(s)
if instance is None:
instance = super(_AtomCache, cls).__call__(s)
return repr(self._str)
def __str__(self):
- return str(self._str)
+ return self._str
def endswith(self, *pargs, **kargs):
return self._str.endswith(*pargs, **kargs)
if d[:1] == '.':
dirs.remove(d)
for filename in files:
+ if not isinstance(filename, unicode):
+ filename = unicode(filename,
+ encoding='utf_8', errors='replace')
if filename[:1] == '.':
continue
if filename.endswith(".metadata"):
if fd is None:
fd = sys.stderr
if noiselevel <= noiselimit:
+ if sys.hexversion < 0x3000000 and isinstance(mystr, unicode):
+ # avoid potential UnicodeEncodeError
+ mystr = mystr.encode('utf_8', 'replace')
fd.write(mystr)
fd.flush()
prefix="@prefix@"
exec_prefix="@exec_prefix@"
-# for bug #279550 we have to do some nasty trick to make sure that sed
+# For bug #279550 we have to do some nasty trick to make sure that sed
# doesn't strip the backslash in the replacement value (because it can
-# be a backreference) and hence escape those.
+# be a backreference) and hence escape those. Eventually in strings we
+# need to escape the backslash too, such that the single backslash
+# doesn't get lost when considered an invalid escape
rootuser="@rootuser@"
portagegroup="@portagegroup@"
portageuser="@portageuser@"
rootuser=${rootuser//\\/\\\\}
-portagegroup=${portagegroup//\\/\\\\}
-portageuser=${portageuser//\\/\\\\}
+portagegroup=${portagegroup//\\/\\\\\\\\}
+portageuser=${portageuser//\\/\\\\\\\\}
# there are many ways to do this all dynamic, but we only care for raw
# speed here, so let configure fill in this list and be done with it