bad = create_color_func("BAD")
from portage.sets import SETPREFIX
from portage.sets.base import InternalPackageSet
-from portage.util import cmp_sort_key, writemsg
+from portage.util import cmp_sort_key, writemsg, writemsg_stdout
from _emerge.AtomArg import AtomArg
from _emerge.Blocker import Blocker
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)
+ writemsg_stdout(bold('*'+revision) + '\n' + text)
sys.stdout.flush()
return os.EX_OK
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
+ writemsg_stdout(filename + ":\n" + comment + "\n")
shown_comments.add(comment)
portdb = root_config.trees["porttree"].dbapi
for l in missing_licenses:
writemsg("!!! File Not Found: '%s'\n" % file_path, noiselevel=-1)
continue
- # TODO: Make getconfig() return unicode.
- unicode_config = {}
- for k, v in myconfig.iteritems():
- if not isinstance(k, unicode):
- k = unicode(k, encoding='utf8', errors='replace')
- if not isinstance(v, unicode):
- v = unicode(v, encoding='utf8', errors='replace')
- unicode_config[k] = v
- myconfig = unicode_config
- del unicode_config
-
config_list.append(myconfig)
if "SPACE_SEPARATED" in myconfig:
space_separated.update(myconfig["SPACE_SEPARATED"].split())
# backupenv is used for calculating incremental variables.
if env is None:
env = os.environ
- self.backupenv = env.copy()
+
+ # Avoid potential UnicodeDecodeError exceptions later.
+ env_unicode = {}
+ for k, v in env.iteritems():
+ if not isinstance(k, unicode):
+ k = unicode(k, encoding='utf_8', errors='replace')
+ if not isinstance(v, unicode):
+ v = unicode(v, encoding='utf_8', errors='replace')
+ env_unicode[k] = v
+
+ self.backupenv = env_unicode
if env_d:
# Remove duplicate values so they don't override updated
"set a value; will be thrown away at reset() time"
if not isinstance(myvalue, basestring):
raise ValueError("Invalid type being used as a value: '%s': '%s'" % (str(mykey),str(myvalue)))
+
+ # Avoid potential UnicodeDecodeError exceptions later.
+ if not isinstance(mykey, unicode):
+ mykey = unicode(mykey, encoding='utf_8', errors='replace')
+ if not isinstance(myvalue, unicode):
+ myvalue = unicode(myvalue, encoding='utf_8', errors='replace')
+
self.modifying()
- self.modifiedkeys += [mykey]
+ self.modifiedkeys.append(mykey)
self.configdict["env"][mykey]=myvalue
def environ(self):
destdir = destdir.encode('utf_8', 'replace')
size = 0
+ counted_inodes = set()
for parent, dirs, files in os.walk(destdir):
for fname in chain(dirs, files):
fpath = os.path.join(parent, fname)
mystat = os.lstat(fpath)
- if stat.S_ISREG(mystat.st_mode):
+ if stat.S_ISREG(mystat.st_mode) and \
+ mystat.st_ino not in counted_inodes:
+ counted_inodes.add(mystat.st_ino)
size += mystat.st_size
if mystat.st_uid != portage_uid and \
mystat.st_gid != portage_gid:
continue
repo_name_path = os.path.join(path, REPO_NAME_LOC)
try:
- repo_name = open(repo_name_path, 'r').readline().strip()
+ repo_name = codecs.open(repo_name_path, mode='r',
+ encoding='utf_8', errors='replace').readline().strip()
except EnvironmentError:
# warn about missing repo_name at some other time, since we
# don't want to see a warning every time the portage module is
def filter_loglevels(logentries, loglevels):
# remove unwanted entries from all logentries
rValue = {}
- loglevels = map(str.upper, loglevels)
+ loglevels = [x.upper() for x in loglevels]
for phase in logentries:
for msgtype, msgcontent in logentries[phase]:
if msgtype.upper() in loglevels or "*" in loglevels:
def filter_phases(logentries, phases):
rValue1 = {}
rValue2 = {}
- phases = map(str.lower, phases)
+ phases = [x.lower() for x in phases]
for phase in logentries:
if phase in phases:
rValue1[phase] = logentries[phase]
if isinstance(mycommand, basestring):
mycommand = mycommand.split()
+ # Avoid a potential UnicodeEncodeError from os.execve().
+ env_bytes = {}
+ for k, v in env.iteritems():
+ if isinstance(k, unicode):
+ k = k.encode('utf_8', 'replace')
+ if isinstance(v, unicode):
+ v = v.encode('utf_8', 'replace')
+ env_bytes[k] = v
+ 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.
binary = mycommand[0]
This is equivalent to shlex.split but it temporarily encodes unicode
strings to bytes since shlex.split() doesn't handle unicode strings.
"""
- is_unicode = isinstance(s, unicode)
+ is_unicode = sys.hexversion < 0x3000000 and isinstance(s, unicode)
if is_unicode:
s = s.encode('utf_8', 'replace')
rval = shlex.split(s)
# trailing newline after the source statement
# NOTE: shex doesn't seem to supported unicode objects
# (produces spurious \0 characters with python-2.6.2)
- content = open(mycfg).read()
+ if sys.hexversion < 0x3000000:
+ content = open(mycfg, 'rb').read()
+ else:
+ content = open(mycfg, mode='r',
+ encoding='utf_8', errors='replace').read()
if content and content[-1] != '\n':
content += '\n'
except IOError, e:
raise portage.exception.CorruptionError("ParseError: Unexpected EOF: "+str(mycfg)+": line "+str(lex.lineno))
else:
return mykeys
+ if not isinstance(key, unicode):
+ key = unicode(key, encoding='utf_8', errors='replace')
+ if not isinstance(val, unicode):
+ val = unicode(val, encoding='utf_8', errors='replace')
if expand:
mykeys[key] = varexpand(val, expand_map)
expand_map[key] = mykeys[key]