# This is a special version of the os module, wrapped for unicode support.
from portage import os
-from portage import _content_encoding
-from portage import _fs_encoding
-from portage import _merge_encoding
+from portage import _encodings
from portage import _os_merge
from portage import _selinux_merge
from portage import _unicode_decode
self._data = None
try:
self._data = pickle.load(
- open(_unicode_encode(self._filename), 'rb'))
+ open(_unicode_encode(self._filename,
+ encoding=_encodings['fs'], errors='strict'), 'rb'))
except (ValueError, pickle.UnpicklingError), e:
writemsg_level(_("!!! Error loading '%s': %s\n") % \
(self._filename, e), level=logging.ERROR, noiselevel=-1)
raise CommandNotFound(args[0])
else:
for l in proc.stdout:
- l = portage._unicode_decode(l)
+ try:
+ l = _unicode_decode(l,
+ encoding=_encodings['content'], errors='strict')
+ except UnicodeDecodeError:
+ l = _unicode_decode(l,
+ encoding=_encodings['content'], errors='replace')
+ writemsg_level(_("\nError decoding characters " \
+ "returned from scanelf: %s\n\n") % (l,),
+ level=logging.ERROR, noiselevel=-1)
l = l[3:].rstrip("\n")
if not l:
continue
now has a categories property that is generated from the
available packages.
"""
- self.root = portage._unicode_decode(root)
+ self.root = _unicode_decode(root,
+ encoding=_encodings['content'], errors='strict')
#cache for category directory mtimes
self.mtdircache = {}
except KeyError:
continue
h.update(_unicode_encode(counter,
- encoding=_content_encoding, errors='replace'))
+ encoding=_encodings['repo.content'],
+ errors='backslashreplace'))
return h.hexdigest()
def cpv_inject(self, mycpv):
# python-2.x, but buffering makes it much worse.
open_kwargs["buffering"] = 0
try:
- f = open(_unicode_encode(self._aux_cache_filename),
+ f = open(_unicode_encode(self._aux_cache_filename,
+ encoding=_encodings['fs'], errors='strict'),
mode='rb', **open_kwargs)
mypickle = pickle.Unpickler(f)
try:
if cache_valid:
# Migrate old metadata to unicode.
for k, v in metadata.iteritems():
- metadata[k] = portage._unicode_decode(v)
+ metadata[k] = _unicode_decode(v,
+ encoding=_encodings['repo.content'], errors='replace')
mydata.update(metadata)
pull_me.difference_update(mydata)
try:
myf = codecs.open(
_unicode_encode(os.path.join(mydir, x),
- encoding=_fs_encoding, errors='strict'),
- mode='r', encoding=_content_encoding, errors='replace')
+ encoding=_encodings['fs'], errors='strict'),
+ mode='r', encoding=_encodings['repo.content'],
+ errors='replace')
try:
myd = myf.read()
finally:
try:
cfile = codecs.open(
_unicode_encode(self._counter_path,
- encoding=_fs_encoding, errors='strict'),
- mode='r', encoding=_content_encoding, errors='replace')
+ encoding=_encodings['fs'], errors='strict'),
+ mode='r', encoding=_encodings['repo.content'],
+ errors='replace')
except EnvironmentError, e:
new_vdb = not bool(self.cpv_all())
if not new_vdb:
removed = 0
for filename in paths:
- filename = portage._unicode_decode(filename)
+ filename = _unicode_decode(filename,
+ encoding=_encodings['content'], errors='strict')
filename = normalize_path(filename)
if relative_paths:
relative_filename = filename
# Always use a constant utf_8 encoding here, since
# the "default" encoding can change.
h.update(_unicode_encode(s,
- encoding=_content_encoding, errors='replace'))
+ encoding=_encodings['repo.content'],
+ errors='backslashreplace'))
h = h.hexdigest()
h = h[-self._hex_chars:]
h = int(h, 16)
pkgfiles = {}
try:
myc = codecs.open(_unicode_encode(contents_file,
- encoding=_content_encoding, errors='strict'),
- mode='r', encoding=_content_encoding, errors='replace')
+ encoding=_encodings['fs'], errors='strict'),
+ mode='r', encoding=_encodings['repo.content'],
+ errors='replace')
except EnvironmentError, e:
if e.errno != errno.ENOENT:
raise
obj = normalize_path(objkey)
if os is _os_merge:
try:
- _unicode_encode(obj, encoding=_merge_encoding, errors='strict')
+ _unicode_encode(obj,
+ encoding=_encodings['merge'], errors='strict')
except UnicodeEncodeError:
# The package appears to have been merged with a
# different value of sys.getfilesystemencoding(),
# so fall back to utf_8 if appropriate.
try:
- _unicode_encode(obj, encoding=_fs_encoding, errors='strict')
+ _unicode_encode(obj,
+ encoding=_encodings['fs'], errors='strict')
except UnicodeEncodeError:
pass
else:
os = _os_merge
- filename = portage._unicode_decode(filename)
+ filename = _unicode_decode(filename,
+ encoding=_encodings['content'], errors='strict')
- destroot = portage._unicode_decode(destroot)
+ destroot = _unicode_decode(destroot,
+ encoding=_encodings['content'], errors='strict')
destfile = normalize_path(
os.path.join(destroot, filename.lstrip(os.path.sep)))
new_contents = self.getcontents().copy()
old_contents = self._installed_instance.getcontents()
for f in sorted(preserve_paths):
- f = portage._unicode_decode(f, encoding=_merge_encoding)
+ f = _unicode_decode(f,
+ encoding=_encodings['content'], errors='strict')
f_abs = os.path.join(root, f.lstrip(os.sep))
contents_entry = old_contents.get(f_abs)
if contents_entry is None:
os = _os_merge
- srcroot = portage._unicode_decode(srcroot)
- destroot = portage._unicode_decode(destroot)
- inforoot = portage._unicode_decode(inforoot)
- myebuild = portage._unicode_decode(myebuild)
+ srcroot = _unicode_decode(srcroot,
+ encoding=_encodings['content'], errors='strict')
+ destroot = _unicode_decode(destroot,
+ encoding=_encodings['content'], errors='strict')
+ inforoot = _unicode_decode(inforoot,
+ encoding=_encodings['content'], errors='strict')
+ myebuild = _unicode_decode(myebuild,
+ encoding=_encodings['content'], errors='strict')
showMessage = self._display_merge
scheduler = self._scheduler
try:
val = codecs.open(_unicode_encode(
os.path.join(inforoot, var_name),
- encoding=_fs_encoding, errors='strict'),
- mode='r', encoding=_content_encoding, errors='replace'
- ).readline().strip()
+ encoding=_encodings['fs'], errors='strict'),
+ mode='r', encoding=_encodings['repo.content'],
+ errors='replace').readline().strip()
except EnvironmentError, e:
if e.errno != errno.ENOENT:
raise
for parent, dirs, files in os.walk(srcroot, onerror=onerror):
try:
parent = _unicode_decode(parent,
- encoding=_merge_encoding, errors='strict')
+ encoding=_encodings['merge'], errors='strict')
except UnicodeDecodeError:
new_parent = _unicode_decode(parent,
- encoding=_merge_encoding, errors='replace')
+ encoding=_encodings['merge'], errors='replace')
new_parent = _unicode_encode(new_parent,
- encoding=_merge_encoding, errors='backslashreplace')
+ encoding=_encodings['merge'], errors='backslashreplace')
new_parent = _unicode_decode(new_parent,
- encoding=_merge_encoding, errors='replace')
+ encoding=_encodings['merge'], errors='replace')
os.rename(parent, new_parent)
unicode_error = True
unicode_errors.append(new_parent[srcroot_len:])
for fname in files:
try:
fname = _unicode_decode(fname,
- encoding=_merge_encoding, errors='strict')
+ encoding=_encodings['merge'], errors='strict')
except UnicodeDecodeError:
fpath = portage._os.path.join(
- parent.encode(_merge_encoding), fname)
+ parent.encode(_encodings['merge']), fname)
new_fname = _unicode_decode(fname,
- encoding=_merge_encoding, errors='replace')
+ encoding=_encodings['merge'], errors='replace')
new_fname = _unicode_encode(new_fname,
- encoding=_merge_encoding, errors='backslashreplace')
+ encoding=_encodings['merge'], errors='backslashreplace')
new_fname = _unicode_decode(new_fname,
- encoding=_merge_encoding, errors='replace')
+ encoding=_encodings['merge'], errors='replace')
new_fpath = os.path.join(parent, new_fname)
os.rename(fpath, new_fpath)
unicode_error = True
# write local package counter for recording
counter = self.vartree.dbapi.counter_tick(self.myroot, mycpv=self.mycpv)
- open(_unicode_encode(os.path.join(self.dbtmpdir, 'COUNTER')),
- 'w').write(str(counter))
+ codecs.open(_unicode_encode(os.path.join(self.dbtmpdir, 'COUNTER'),
+ encoding=_encodings['fs'], errors='strict'),
+ 'w', encoding=_encodings['repo.content'], errors='backslashreplace'
+ ).write(str(counter))
# open CONTENTS file (possibly overwriting old one) for recording
outfile = codecs.open(_unicode_encode(
os.path.join(self.dbtmpdir, 'CONTENTS'),
- encoding=_fs_encoding, errors='strict'),
- mode='w', encoding=_content_encoding, errors='replace')
+ encoding=_encodings['fs'], errors='strict'),
+ mode='w', encoding=_encodings['repo.content'],
+ errors='backslashreplace')
self.updateprotect()
# unlinking no longer necessary; "movefile" will overwrite symlinks atomically and correctly
mymtime = movefile(mysrc, mydest, newmtime=thismtime,
sstat=mystat, mysettings=self.settings,
- encoding=_merge_encoding)
+ encoding=_encodings['merge'])
if mymtime != None:
showMessage(">>> %s -> %s\n" % (mydest, myto))
outfile.write("sym "+myrealdest+" -> "+myto+" "+str(mymtime)+"\n")
# a non-directory and non-symlink-to-directory. Won't work for us. Move out of the way.
if movefile(mydest, mydest+".backup",
mysettings=self.settings,
- encoding=_merge_encoding) is None:
+ encoding=_encodings['merge']) is None:
return 1
showMessage(_("bak %s %s.backup\n") % (mydest, mydest),
level=logging.ERROR, noiselevel=-1)
mymtime = movefile(mysrc, mydest, newmtime=thismtime,
sstat=mystat, mysettings=self.settings,
hardlink_candidates=hardlink_candidates,
- encoding=_merge_encoding)
+ encoding=_encodings['merge'])
if mymtime is None:
return 1
if hardlink_candidates is not None:
# destination doesn't exist
if movefile(mysrc, mydest, newmtime=thismtime,
sstat=mystat, mysettings=self.settings,
- encoding=_merge_encoding) is not None:
+ encoding=_encodings['merge']) is not None:
zing = ">>>"
else:
return 1
return ""
mydata = codecs.open(
_unicode_encode(os.path.join(self.dbdir, name),
- encoding=_fs_encoding, errors='strict'),
- mode='r', encoding=_content_encoding, errors='replace'
+ encoding=_encodings['fs'], errors='strict'),
+ mode='r', encoding=_encodings['repo.content'], errors='replace'
).read().split()
return " ".join(mydata)
if not os.path.exists(self.dbdir+"/"+fname):
return ""
return codecs.open(_unicode_encode(os.path.join(self.dbdir, fname),
- encoding=_fs_encoding, errors='strict'),
- mode='r', encoding=_content_encoding, errors='replace').read()
+ encoding=_encodings['fs'], errors='strict'),
+ mode='r', encoding=_encodings['repo.content'], errors='replace'
+ ).read()
def setfile(self,fname,data):
- mode = 'w'
+ kwargs = {}
if fname == 'environment.bz2' or not isinstance(data, basestring):
- mode = 'wb'
- write_atomic(os.path.join(self.dbdir, fname), data, mode=mode)
+ kwargs['mode'] = 'wb'
+ else:
+ kwargs['mode'] = 'w'
+ kwargs['encoding'] = _encodings['repo.content']
+ write_atomic(os.path.join(self.dbdir, fname), data, **kwargs)
def getelements(self,ename):
if not os.path.exists(self.dbdir+"/"+ename):
return []
mylines = codecs.open(_unicode_encode(
os.path.join(self.dbdir, ename),
- encoding=_fs_encoding, errors='strict'),
- mode='r', encoding=_content_encoding, errors='replace').readlines()
+ encoding=_encodings['fs'], errors='strict'),
+ mode='r', encoding=_encodings['repo.content'], errors='replace'
+ ).readlines()
myreturn = []
for x in mylines:
for y in x[:-1].split():
def setelements(self,mylist,ename):
myelement = codecs.open(_unicode_encode(
os.path.join(self.dbdir, ename),
- encoding=_fs_encoding, errors='strict'), mode='w',
- encoding=_content_encoding, errors='replace')
+ encoding=_encodings['fs'], errors='strict'),
+ mode='w', encoding=_encodings['repo.content'],
+ errors='backslashreplace')
for x in mylist:
myelement.write(x+"\n")
myelement.close()
tarinfo.size = 0
tar.addfile(tarinfo)
else:
- f = open(_unicode_encode(path, encoding=_merge_encoding), 'rb')
+ f = open(_unicode_encode(path,
+ encoding=_encodings['merge'], errors='strict'), 'rb')
try:
tar.addfile(tarinfo, f)
finally: