#!/usr/bin/python
-# Copyright 2010 Gentoo Foundation
+# Copyright 2010-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-import codecs
+import io
import optparse
import os
import sys
if not (os.WIFEXITED(ret) and os.WEXITSTATUS(ret) == os.EX_OK):
return 1
- infile = codecs.open(portage._unicode_encode(src_pkgs_index,
+ infile = io.open(portage._unicode_encode(src_pkgs_index,
encoding=portage._encodings['fs'], errors='strict'),
mode='r', encoding=portage._encodings['repo.content'],
errors='strict')
except KeyboardInterrupt:
sys.exit(128 + signal.SIGINT)
-import codecs
+import io
import logging
import optparse
import subprocess
output = open(_unicode_encode(desc_path,
encoding=_encodings['fs'], errors='strict'), 'r+b')
else:
- output = codecs.open(_unicode_encode(desc_path,
+ output = io.open(_unicode_encode(desc_path,
encoding=_encodings['fs'], errors='strict'),
mode='w', encoding=_encodings['repo.content'],
- errors='replace')
+ errors='backslashreplace')
except IOError as e:
if not self._preserve_comments or \
os.path.isfile(desc_path):
level=logging.WARNING, noiselevel=-1)
self._preserve_comments = False
try:
- output = codecs.open(_unicode_encode(desc_path,
+ output = io.open(_unicode_encode(desc_path,
encoding=_encodings['fs'], errors='strict'),
mode='w', encoding=_encodings['repo.content'],
- errors='replace')
+ errors='backslashreplace')
except IOError as e:
writemsg_level(
"ERROR: failed to open output file %s: %s\n" \
# Finished probing comments in binary mode, now append
# in text mode.
- output = codecs.open(_unicode_encode(desc_path,
+ output = io.open(_unicode_encode(desc_path,
encoding=_encodings['fs'], errors='strict'),
mode='a', encoding=_encodings['repo.content'],
- errors='replace')
- output.write('\n')
+ errors='backslashreplace')
+ output.write(_unicode_decode('\n'))
else:
- output.write('''
+ output.write(_unicode_decode('''
# This file is deprecated as per GLEP 56 in favor of metadata.xml. Please add
# your descriptions to your package's metadata.xml ONLY.
# * generated automatically using egencache *
-'''.lstrip())
+'''.lstrip()))
# The cmp function no longer exists in python3, so we'll
# implement our own here under a slightly different name
resatoms = sorted(reskeys, key=cmp_sort_key(atomcmp))
resdesc = resdict[reskeys[resatoms[-1]]]
- output.write('%s:%s - %s\n' % (cp, flag, resdesc))
+ output.write(_unicode_decode(
+ '%s:%s - %s\n' % (cp, flag, resdesc)))
output.close()
def generate_changelog(self, cp):
try:
- output = codecs.open('ChangeLog',
+ output = io.open('ChangeLog',
mode='w', encoding=_encodings['repo.content'],
- errors='replace')
+ errors='backslashreplace')
except IOError as e:
writemsg_level(
"ERROR: failed to open ChangeLog for %s: %s\n" % (cp,e,),
self.returncode |= 2
return
- output.write(('''
+ output.write(_unicode_decode('''
# ChangeLog for %s
# Copyright 1999-%s Gentoo Foundation; Distributed under the GPL v2
# $Header: $
# Reverse the sort order for headers.
for c in reversed(changed):
if c.startswith('+') and c.endswith('.ebuild'):
- output.write('*%s (%s)\n' % (c[1:-7], date))
+ output.write(_unicode_decode(
+ '*%s (%s)\n' % (c[1:-7], date)))
wroteheader = True
if wroteheader:
- output.write('\n')
+ output.write(_unicode_decode('\n'))
# strip '<cp>: ', '[<cp>] ', and similar
body[0] = re.sub(r'^\W*' + re.escape(cp) + r'\W+', '', body[0])
# don't break filenames on hyphens
self._wrapper.break_on_hyphens = False
- output.write(self._wrapper.fill('%s; %s %s:' % (date, author, ', '.join(changed))))
+ output.write(_unicode_decode(
+ self._wrapper.fill(
+ '%s; %s %s:' % (date, author, ', '.join(changed)))))
# but feel free to break commit messages there
self._wrapper.break_on_hyphens = True
- output.write('\n%s\n\n' % '\n'.join([self._wrapper.fill(x) for x in body]))
+ output.write(_unicode_decode(
+ '\n%s\n\n' % '\n'.join(self._wrapper.fill(x) for x in body)))
output.close()
from __future__ import print_function
import calendar
-import codecs
import copy
import errno
import formatter
+import io
import logging
import optparse
import re
desc_path = os.path.join(path, 'profiles', 'profiles.desc')
try:
- desc_file = codecs.open(_unicode_encode(desc_path,
+ desc_file = io.open(_unicode_encode(desc_path,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'], errors='replace')
except EnvironmentError:
continue
try:
line = 1
- for l in codecs.open(_unicode_encode(os.path.join(checkdir, y),
+ for l in io.open(_unicode_encode(os.path.join(checkdir, y),
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content']):
line +=1
pkg.mtime = None
try:
# All ebuilds should have utf_8 encoding.
- f = codecs.open(_unicode_encode(full_path,
+ f = io.open(_unicode_encode(full_path,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'])
try:
commitmessage = options.commitmsg
if options.commitmsgfile:
try:
- f = codecs.open(_unicode_encode(options.commitmsgfile,
+ f = io.open(_unicode_encode(options.commitmsgfile,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='replace')
commitmessage = f.read()
import portage
from portage import os
from portage import _encodings
+from portage import _unicode_decode
from portage import _unicode_encode
-import codecs
+import io
import logging
from portage.output import colorize
else:
continue
- f = codecs.open(_unicode_encode(os.path.join(infloc, k),
+ f = io.open(_unicode_encode(os.path.join(infloc, k),
encoding=_encodings['fs'], errors='strict'),
- mode='w', encoding=_encodings['content'], errors='replace')
+ mode='w', encoding=_encodings['content'],
+ errors='backslashreplace')
try:
- f.write(v + "\n")
+ f.write(_unicode_decode(v + "\n"))
finally:
f.close()
# Store the md5sum in the vdb.
- f = codecs.open(_unicode_encode(os.path.join(infloc, 'BINPKGMD5'),
+ f = io.open(_unicode_encode(os.path.join(infloc, 'BINPKGMD5'),
encoding=_encodings['fs'], errors='strict'),
mode='w', encoding=_encodings['content'], errors='strict')
try:
- f.write(str(portage.checksum.perform_md5(pkg_path)) + "\n")
+ f.write(_unicode_decode(
+ str(portage.checksum.perform_md5(pkg_path)) + "\n"))
finally:
f.close()
-# Copyright 1999-2010 Gentoo Foundation
+# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
import traceback
from _emerge.SpawnProcess import SpawnProcess
import copy
+import io
import signal
import sys
import portage
from portage import _encodings
from portage import _unicode_encode
from portage import _unicode_decode
-import codecs
from portage.elog.messages import eerror
from portage.package.ebuild.fetch import fetch
from portage.util._pty import _create_pty_or_pipe
# fetch code will be skipped, so we need to generate equivalent
# output here.
if self.logfile is not None:
- f = codecs.open(_unicode_encode(self.logfile,
+ f = io.open(_unicode_encode(self.logfile,
encoding=_encodings['fs'], errors='strict'),
- mode='a', encoding=_encodings['content'], errors='replace')
+ mode='a', encoding=_encodings['content'],
+ errors='backslashreplace')
for filename in uri_map:
- f.write((' * %s size ;-) ...' % \
- filename).ljust(73) + '[ ok ]\n')
+ f.write(_unicode_decode((' * %s size ;-) ...' % \
+ filename).ljust(73) + '[ ok ]\n'))
f.close()
return True
from portage import _unicode_decode
from portage import _unicode_encode
import fcntl
-import codecs
+import io
class EbuildMetadataPhase(SubProcess):
if eapi is None and \
'parse-eapi-ebuild-head' in settings.features:
eapi = portage._parse_eapi_ebuild_head(
- codecs.open(_unicode_encode(ebuild_path,
+ io.open(_unicode_encode(ebuild_path,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'],
errors='replace'))
from __future__ import print_function
-import codecs
import difflib
import errno
-import gc
+import io
import logging
import re
import stat
def write_changes(root, changes, file_to_write_to):
file_contents = None
try:
- file_contents = codecs.open(
+ file_contents = io.open(
_unicode_encode(file_to_write_to,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'],
from __future__ import print_function
-import codecs
+import io
import sys
import time
import portage
from portage import os
from portage import _encodings
+from portage import _unicode_decode
from portage import _unicode_encode
from portage.data import secpass
from portage.output import xtermTitle
try:
file_path = os.path.join(_emerge_log_dir, 'emerge.log')
existing_log = os.path.isfile(file_path)
- mylogfile = codecs.open(_unicode_encode(file_path,
+ mylogfile = io.open(_unicode_encode(file_path,
encoding=_encodings['fs'], errors='strict'),
mode='a', encoding=_encodings['content'],
errors='backslashreplace')
# seek because we may have gotten held up by the lock.
# if so, we may not be positioned at the end of the file.
mylogfile.seek(0, 2)
- mylogfile.write(str(time.time())[:10]+": "+mystr+"\n")
+ mylogfile.write(_unicode_decode(
+ str(time.time())[:10]+": "+mystr+"\n"))
mylogfile.flush()
finally:
if mylock:
__all__ = (
)
-import codecs
+import io
import re
import sys
next = next[:-3]
changelogpath = os.path.join(os.path.split(ebuildpath)[0],'ChangeLog')
try:
- changelog = codecs.open(_unicode_encode(changelogpath,
+ changelog = io.open(_unicode_encode(changelogpath,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'], errors='replace'
).read()
-# Copyright: 2005 Gentoo Foundation
+# Copyright: 2005-2011 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
# Author(s): Brian Harring (ferringb@gentoo.org)
-# License: GPL2
-import codecs
from portage.cache import fs_template
from portage.cache import cache_errors
import errno
+import io
import stat
import sys
import os as _os
from portage import os
from portage import _encodings
+from portage import _unicode_decode
from portage import _unicode_encode
if sys.hexversion >= 0x3000000:
long = int
+# Coerce to unicode, in order to prevent TypeError when writing
+# raw bytes to TextIOWrapper with python2.
+_setitem_fmt = _unicode_decode("%s=%s\n")
+
class database(fs_template.FsBased):
autocommits = True
# Don't use os.path.join, for better performance.
fp = self.location + _os.sep + cpv
try:
- myf = codecs.open(_unicode_encode(fp,
+ myf = io.open(_unicode_encode(fp,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'],
errors='replace')
s = cpv.rfind("/")
fp = os.path.join(self.location,cpv[:s],".update.%i.%s" % (os.getpid(), cpv[s+1:]))
try:
- myf = codecs.open(_unicode_encode(fp,
+ myf = io.open(_unicode_encode(fp,
encoding=_encodings['fs'], errors='strict'),
mode='w', encoding=_encodings['repo.content'],
errors='backslashreplace')
if errno.ENOENT == e.errno:
try:
self._ensure_dirs(cpv)
- myf = codecs.open(_unicode_encode(fp,
+ myf = io.open(_unicode_encode(fp,
encoding=_encodings['fs'], errors='strict'),
mode='w', encoding=_encodings['repo.content'],
errors='backslashreplace')
v = values.get(k)
if not v:
continue
- myf.write("%s=%s\n" % (k, v))
+ myf.write(_setitem_fmt % (k, v))
finally:
myf.close()
self._ensure_access(fp)
+# Copyright 2005-2011 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
from portage.cache import fs_template
from portage.cache import cache_errors
from portage import os
from portage import _encodings
+from portage import _unicode_decode
from portage import _unicode_encode
-import codecs
import errno
+import io
import stat
import sys
if sys.hexversion >= 0x3000000:
long = int
+# Coerce to unicode, in order to prevent TypeError when writing
+# raw bytes to TextIOWrapper with python2.
+_setitem_fmt = _unicode_decode("%s\n")
+
# store the current key order *here*.
class database(fs_template.FsBased):
def _getitem(self, cpv):
d = {}
try:
- myf = codecs.open(_unicode_encode(os.path.join(self.location, cpv),
+ myf = io.open(_unicode_encode(os.path.join(self.location, cpv),
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'],
errors='replace')
s = cpv.rfind("/")
fp=os.path.join(self.location,cpv[:s],".update.%i.%s" % (os.getpid(), cpv[s+1:]))
try:
- myf = codecs.open(_unicode_encode(fp,
+ myf = io.open(_unicode_encode(fp,
encoding=_encodings['fs'], errors='strict'),
mode='w', encoding=_encodings['repo.content'],
errors='backslashreplace')
if errno.ENOENT == e.errno:
try:
self._ensure_dirs(cpv)
- myf = codecs.open(_unicode_encode(fp,
+ myf = io.open(_unicode_encode(fp,
encoding=_encodings['fs'], errors='strict'),
mode='w', encoding=_encodings['repo.content'],
errors='backslashreplace')
for x in self.auxdbkey_order:
- myf.write(values.get(x,"")+"\n")
+ myf.write(_setitem_fmt % (values.get(x, ""),))
myf.close()
self._ensure_access(fp, mtime=values["_mtime_"])
from __future__ import print_function
-import codecs
+import io
import re
import stat
import sys
filename=os.path.basename(path)
try:
- myfile = codecs.open(
+ myfile = io.open(
_unicode_encode(os.path.join(basedir, 'CVS', 'Entries'),
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='strict')
if not os.path.exists(mydir):
return entries
try:
- myfile = codecs.open(_unicode_encode(myfn,
+ myfile = io.open(_unicode_encode(myfn,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='strict')
mylines=myfile.readlines()
import codecs
import errno
+import io
import re
import stat
import subprocess
host, parsed_url.path.lstrip("/"), "Packages")
pkgindex = self._new_pkgindex()
try:
- f = codecs.open(_unicode_encode(pkgindex_file,
+ f = io.open(_unicode_encode(pkgindex_file,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'],
errors='replace')
def _load_pkgindex(self):
pkgindex = self._new_pkgindex()
try:
- f = codecs.open(_unicode_encode(self._pkgindex_file,
+ f = io.open(_unicode_encode(self._pkgindex_file,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'],
errors='replace')
from _emerge.PollScheduler import PollScheduler
import os as _os
-import codecs
-import logging
+import io
import stat
import sys
import traceback
if eapi is None and \
'parse-eapi-ebuild-head' in self.doebuild_settings.features:
- eapi = portage._parse_eapi_ebuild_head(codecs.open(
+ eapi = portage._parse_eapi_ebuild_head(io.open(
_unicode_encode(myebuild,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'],
PORTAGE_PACKAGE_ATOM, PRIVATE_PATH, VDB_PATH
from portage.const import _ENABLE_DYN_LINK_MAP, _ENABLE_PRESERVE_LIBS
from portage.dbapi import dbapi
-from portage.dep import _slot_separator
from portage.exception import CommandNotFound, \
InvalidData, InvalidLocation, InvalidPackageName, \
FileNotFound, PermissionDenied, UnsupportedAPIException
from portage import _unicode_decode
from portage import _unicode_encode
-from _emerge.AsynchronousLock import AsynchronousLock
from _emerge.EbuildBuildDir import EbuildBuildDir
from _emerge.EbuildPhase import EbuildPhase
from _emerge.emergelog import emergelog
from _emerge.PollScheduler import PollScheduler
from _emerge.MiscFunctionsProcess import MiscFunctionsProcess
-import codecs
+import errno
import gc
-import re, shutil, stat, errno, subprocess
+import io
import logging
import os as _os
+import re
+import shutil
import stat
import sys
import tempfile
results.append(st[stat.ST_MTIME])
continue
try:
- myf = codecs.open(
+ myf = io.open(
_unicode_encode(os.path.join(mydir, x),
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'],
new_vdb = False
counter = -1
try:
- cfile = codecs.open(
+ cfile = io.open(
_unicode_encode(self._counter_path,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'],
return self.contentscache
pkgfiles = {}
try:
- myc = codecs.open(_unicode_encode(contents_file,
+ myc = io.open(_unicode_encode(contents_file,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'],
errors='replace')
continue
try:
- val = codecs.open(_unicode_encode(
+ val = io.open(_unicode_encode(
os.path.join(inforoot, var_name),
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'],
# write local package counter for recording
if counter is None:
counter = self.vartree.dbapi.counter_tick(mycpv=self.mycpv)
- codecs.open(_unicode_encode(os.path.join(self.dbtmpdir, 'COUNTER'),
+ io.open(_unicode_encode(os.path.join(self.dbtmpdir, 'COUNTER'),
encoding=_encodings['fs'], errors='strict'),
'w', encoding=_encodings['repo.content'], errors='backslashreplace'
- ).write(str(counter))
+ ).write(_unicode_decode(str(counter)))
self.updateprotect()
cfgfiledict_orig = cfgfiledict.copy()
# open CONTENTS file (possibly overwriting old one) for recording
- outfile = codecs.open(_unicode_encode(
+ # Use atomic_ofstream for automatic coercion of raw bytes to
+ # unicode, in order to prevent TypeError when writing raw bytes
+ # to TextIOWrapper with python2.
+ outfile = atomic_ofstream(_unicode_encode(
os.path.join(self.dbtmpdir, 'CONTENTS'),
encoding=_encodings['fs'], errors='strict'),
mode='w', encoding=_encodings['repo.content'],
"returns contents of a file with whitespace converted to spaces"
if not os.path.exists(self.dbdir+"/"+name):
return ""
- mydata = codecs.open(
+ mydata = io.open(
_unicode_encode(os.path.join(self.dbdir, name),
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'], errors='replace'
def getfile(self,fname):
if not os.path.exists(self.dbdir+"/"+fname):
return ""
- return codecs.open(_unicode_encode(os.path.join(self.dbdir, fname),
+ return io.open(_unicode_encode(os.path.join(self.dbdir, fname),
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'], errors='replace'
).read()
def getelements(self,ename):
if not os.path.exists(self.dbdir+"/"+ename):
return []
- mylines = codecs.open(_unicode_encode(
+ mylines = io.open(_unicode_encode(
os.path.join(self.dbdir, ename),
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'], errors='replace'
return myreturn
def setelements(self,mylist,ename):
- myelement = codecs.open(_unicode_encode(
+ myelement = io.open(_unicode_encode(
os.path.join(self.dbdir, ename),
encoding=_encodings['fs'], errors='strict'),
mode='w', encoding=_encodings['repo.content'],
errors='backslashreplace')
for x in mylist:
- myelement.write(x+"\n")
+ myelement.write(_unicode_decode(x+"\n"))
myelement.close()
def isregular(self):
# elog/messages.py - elog core functions
-# Copyright 2006-2009 Gentoo Foundation
+# Copyright 2006-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
import portage
from portage import _unicode_encode
from portage import _unicode_decode
-import codecs
+import io
import sys
def collect_ebuild_messages(path):
logentries[msgfunction] = []
lastmsgtype = None
msgcontent = []
- for l in codecs.open(_unicode_encode(filename,
+ for l in io.open(_unicode_encode(filename,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'], errors='replace'):
if not l:
_elog_base(level, msg, phase=phase, key=key, color=color, out=out)
return _elog
-import sys
for f in _functions:
setattr(sys.modules[__name__], f, _make_msgfunction(_functions[f][0], _functions[f][1]))
del f, _functions
# elog/mod_save.py - elog dispatch module
-# Copyright 2006-2007 Gentoo Foundation
+# Copyright 2006-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-import codecs
+import io
import time
from portage import os
from portage import _encodings
ensure_dirs(os.path.dirname(elogfilename),
uid=portage_uid, gid=portage_gid, mode=0o2770)
- elogfile = codecs.open(_unicode_encode(elogfilename,
+ elogfile = io.open(_unicode_encode(elogfilename,
encoding=_encodings['fs'], errors='strict'),
mode='w', encoding=_encodings['content'], errors='backslashreplace')
- elogfile.write(fulltext)
+ elogfile.write(_unicode_decode(fulltext))
elogfile.close()
return elogfilename
# elog/mod_save_summary.py - elog dispatch module
-# Copyright 2006-2007 Gentoo Foundation
+# Copyright 2006-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-import codecs
+import io
import time
from portage import os
from portage import _encodings
# TODO: Locking
elogfilename = elogdir+"/summary.log"
- elogfile = codecs.open(_unicode_encode(elogfilename,
+ elogfile = io.open(_unicode_encode(elogfilename,
encoding=_encodings['fs'], errors='strict'),
mode='a', encoding=_encodings['content'], errors='backslashreplace')
apply_permissions(elogfilename, mode=0o60, mask=0)
# Avoid potential UnicodeDecodeError later.
time_str = _unicode_decode(time_str,
encoding=_encodings['content'], errors='replace')
- elogfile.write(_(">>> Messages generated by process %(pid)d on %(time)s for package %(pkg)s:\n\n") %
- {"pid": os.getpid(), "time": time_str, "pkg": key})
- elogfile.write(fulltext)
- elogfile.write("\n")
+ elogfile.write(_unicode_decode(
+ _(">>> Messages generated by process " +
+ "%(pid)d on %(time)s for package %(pkg)s:\n\n") %
+ {"pid": os.getpid(), "time": time_str, "pkg": key}))
+ elogfile.write(_unicode_decode(fulltext))
+ elogfile.write(_unicode_decode("\n"))
elogfile.close()
return elogfilename
# config.py -- Portage Config
-# Copyright 2007 Gentoo Foundation
+# Copyright 2007-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-import codecs
import errno
+import io
import stat
from portage import os
from portage import _encodings
func = self.lineParser
for fn in RecursiveFileLoader(self.fname):
try:
- f = codecs.open(_unicode_encode(fn,
+ f = io.open(_unicode_encode(fn,
encoding=_encodings['fs'], errors='strict'), mode='r',
encoding=_encodings['content'], errors='replace')
except EnvironmentError as e:
-# Copyright 2003-2010 Gentoo Foundation
+# Copyright 2003-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
from __future__ import absolute_import
-import codecs
+import io
import sys
try:
from urllib.request import urlopen as urllib_request_urlopen
@returns: None
"""
if not self.isApplied():
- checkfile = codecs.open(
+ checkfile = io.open(
_unicode_encode(os.path.join(self.config["EROOT"],
CACHE_PATH, "glsa"),
encoding=_encodings['fs'], errors='strict'),
mode='a+', encoding=_encodings['content'], errors='strict')
- checkfile.write(self.nr+"\n")
+ checkfile.write(_unicode_decode(self.nr + "\n"))
checkfile.close()
return None
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-import codecs
import errno
+import io
import portage
portage.proxy.lazyimport.lazyimport(globals(),
"""Parse a manifest. If myhashdict is given then data will be added too it.
Otherwise, a new dict will be created and returned."""
try:
- fd = codecs.open(_unicode_encode(file_path,
+ fd = io.open(_unicode_encode(file_path,
encoding=_encodings['fs'], errors='strict'), mode='r',
encoding=_encodings['repo.content'], errors='replace')
if myhashdict is None:
update_manifest = True
if not force:
try:
- f = codecs.open(_unicode_encode(self.getFullname(),
+ f = io.open(_unicode_encode(self.getFullname(),
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'],
errors='replace')
mfname = self.getFullname()
if not os.path.exists(mfname):
return rVal
- myfile = codecs.open(_unicode_encode(mfname,
+ myfile = io.open(_unicode_encode(mfname,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'], errors='replace')
lines = myfile.readlines()
# portage: news management code
-# Copyright 2006-2010 Gentoo Foundation
+# Copyright 2006-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
__all__ = ["NewsManager", "NewsItem", "DisplayRestriction",
"DisplayProfileRestriction", "DisplayKeywordRestriction",
"DisplayInstalledRestriction"]
-import codecs
+import io
import logging
import os as _os
import re
return self._valid
def parse(self):
- lines = codecs.open(_unicode_encode(self.path,
+ lines = io.open(_unicode_encode(self.path,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='replace'
).readlines()
__docformat__ = "epytext"
-import codecs
try:
from subprocess import getstatusoutput as subprocess_getstatusoutput
except ImportError:
from commands import getstatusoutput as subprocess_getstatusoutput
import errno
+import io
import formatter
import re
import sys
return token
try:
lineno=0
- for line in codecs.open(_unicode_encode(myfile,
+ for line in io.open(_unicode_encode(myfile,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='replace'):
lineno += 1
-# Copyright 2010 Gentoo Foundation
+# Copyright 2010-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
__all__ = (
'LocationsManager',
)
-import codecs
+import io
from portage import os, eapi_is_supported, _encodings, _unicode_encode
from portage.const import CUSTOM_PROFILE_PATH, GLOBAL_CONFIG_PATH, \
PROFILE_PATH, USER_CONFIG_PATH
parentsFile = os.path.join(currentPath, "parent")
eapi_file = os.path.join(currentPath, "eapi")
try:
- eapi = codecs.open(_unicode_encode(eapi_file,
+ eapi = io.open(_unicode_encode(eapi_file,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='replace'
).readline().strip()
-# Copyright 2010 Gentoo Foundation
+# Copyright 2010-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
__all__ = ['deprecated_profile_check']
-import codecs
+import io
from portage import os, _encodings, _unicode_encode
from portage.const import DEPRECATED_PROFILE_FILE
DEPRECATED_PROFILE_FILE)
if not os.access(deprecated_profile_file, os.R_OK):
return False
- dcontent = codecs.open(_unicode_encode(deprecated_profile_file,
+ dcontent = io.open(_unicode_encode(deprecated_profile_file,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='replace').readlines()
writemsg(colorize("BAD", _("\n!!! Your current profile is "
__all__ = ['doebuild', 'doebuild_environment', 'spawn', 'spawnebuild']
-import codecs
import gzip
import errno
+import io
from itertools import chain
import logging
import os as _os
'portage.util.ExtractKernelVersion:ExtractKernelVersion'
)
-from portage import auxdbkeys, bsd_chflags, dep_check, \
+from portage import auxdbkeys, bsd_chflags, \
eapi_is_supported, merge, os, selinux, \
unmerge, _encodings, _parse_eapi_ebuild_head, _os_merge, \
_shell_quote, _unicode_decode, _unicode_encode
from portage.data import portage_gid, portage_uid, secpass, \
uid, userpriv_groups
from portage.dbapi.porttree import _parse_uri_map
-from portage.dbapi.virtual import fakedbapi
from portage.dep import Atom, check_required_use, \
human_readable_required_use, paren_enclose, use_reduce
from portage.eapi import eapi_exports_KV, eapi_exports_merge_type, \
if mydo == 'depend' and 'EAPI' not in mysettings.configdict['pkg']:
if eapi is None and 'parse-eapi-ebuild-head' in mysettings.features:
eapi = _parse_eapi_ebuild_head(
- codecs.open(_unicode_encode(ebuild_path,
+ io.open(_unicode_encode(ebuild_path,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='replace'))
build_info_dir = os.path.join(mysettings['PORTAGE_BUILDDIR'],
'build-info')
- codecs.open(_unicode_encode(os.path.join(build_info_dir,
+ io.open(_unicode_encode(os.path.join(build_info_dir,
'SIZE'), encoding=_encodings['fs'], errors='strict'),
'w', encoding=_encodings['repo.content'],
- errors='strict').write(str(size) + '\n')
+ errors='strict').write(_unicode_decode(str(size) + '\n'))
- codecs.open(_unicode_encode(os.path.join(build_info_dir,
+ io.open(_unicode_encode(os.path.join(build_info_dir,
'BUILD_TIME'), encoding=_encodings['fs'], errors='strict'),
'w', encoding=_encodings['repo.content'],
- errors='strict').write(str(int(time.time())) + '\n')
+ errors='strict').write(_unicode_decode(str(int(time.time())) + '\n'))
use = frozenset(mysettings['PORTAGE_USE'].split())
for k in _vdb_use_conditional_keys:
except OSError:
pass
continue
- codecs.open(_unicode_encode(os.path.join(build_info_dir,
+ io.open(_unicode_encode(os.path.join(build_info_dir,
k), encoding=_encodings['fs'], errors='strict'),
mode='w', encoding=_encodings['repo.content'],
- errors='strict').write(v + '\n')
+ errors='strict').write(_unicode_decode(v + '\n'))
_reapply_bsdflags_to_image(mysettings)
"build-info", "NEEDED.ELF.2")
try:
- lines = codecs.open(_unicode_encode(needed_filename,
+ lines = io.open(_unicode_encode(needed_filename,
encoding=_encodings['fs'], errors='strict'),
'r', encoding=_encodings['repo.content'],
errors='replace').readlines()
__all__ = ['fetch']
-import codecs
import errno
+import io
import logging
import random
import re
GLOBAL_CONFIG_PATH
from portage.data import portage_gid, portage_uid, secpass, userpriv_groups
from portage.exception import FileNotFound, OperationNotPermitted, \
- PermissionDenied, PortageException, TryAgain
+ PortageException, TryAgain
from portage.localization import _
from portage.locks import lockfile, unlockfile
from portage.manifest import Manifest
# Fetch failed... Try the next one... Kill 404 files though.
if (mystat[stat.ST_SIZE]<100000) and (len(myfile)>4) and not ((myfile[-5:]==".html") or (myfile[-4:]==".htm")):
html404=re.compile("<title>.*(not found|404).*</title>",re.I|re.M)
- if html404.search(codecs.open(
+ if html404.search(io.open(
_unicode_encode(myfile_path,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='replace'
# Copyright 2010-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-import codecs
+import io
import logging
import re
except ImportError:
from ConfigParser import SafeConfigParser, ParsingError
from portage import os
-from portage.const import USER_CONFIG_PATH, GLOBAL_CONFIG_PATH, REPO_NAME_LOC
+from portage.const import USER_CONFIG_PATH, REPO_NAME_LOC
from portage.env.loaders import KeyValuePairFileLoader
from portage.util import normalize_path, writemsg, writemsg_level, shlex_split
from portage.localization import _
"""
repo_name_path = os.path.join(repo_path, REPO_NAME_LOC)
try:
- return codecs.open(
+ return io.open(
_unicode_encode(repo_name_path,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'],
-# Copyright 1998-2007 Gentoo Foundation
+# Copyright 1998-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-import codecs
import errno
+import io
import sys
import tempfile
from portage import os
proc.start()
os.close(null_fd)
self.assertEqual(proc.wait(), os.EX_OK)
- f = codecs.open(_unicode_encode(logfile,
+ f = io.open(_unicode_encode(logfile,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='strict')
log_content = f.read()
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-import codecs
import errno
+import io
import re
import stat
import sys
from portage import _unicode_encode
import portage
portage.proxy.lazyimport.lazyimport(globals(),
- 'portage.dep:Atom,dep_getkey,get_operator,isjustname,isvalidatom,' + \
+ 'portage.dep:Atom,dep_getkey,isvalidatom,' + \
'remove_slot',
- 'portage.util:ConfigProtect,grabfile,new_protect_filename,' + \
+ 'portage.util:ConfigProtect,new_protect_filename,' + \
'normalize_path,write_atomic,writemsg',
'portage.util.listdir:_ignorecvs_dirs',
'portage.versions:ververify'
mydata = {}
for myfile in [f for f in os.listdir(dbdir) if f not in ignored_dbentries]:
file_path = os.path.join(dbdir, myfile)
- mydata[myfile] = codecs.open(_unicode_encode(file_path,
+ mydata[myfile] = io.open(_unicode_encode(file_path,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'],
errors='replace').read()
if update_data or \
file_path not in prev_mtimes or \
long(prev_mtimes[file_path]) != mystat[stat.ST_MTIME]:
- content = codecs.open(_unicode_encode(file_path,
+ content = io.open(_unicode_encode(file_path,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['repo.content'], errors='replace'
).read()
myxfiles = recursivefiles
for x in myxfiles:
try:
- file_contents[x] = codecs.open(
+ file_contents[x] = io.open(
_unicode_encode(os.path.join(abs_user_config, x),
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'],
-# Copyright 2010 Gentoo Foundation
+# Copyright 2010-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
__all__ = ['ExtractKernelVersion']
-import codecs
+import io
from portage import os, _encodings, _unicode_encode
from portage.util import getconfig, grabfile
lines = []
pathname = os.path.join(base_dir, 'Makefile')
try:
- f = codecs.open(_unicode_encode(pathname,
+ f = io.open(_unicode_encode(pathname,
encoding=_encodings['fs'], errors='strict'), mode='r',
encoding=_encodings['content'], errors='replace')
except OSError as details:
'stack_dicts', 'stack_lists', 'unique_array', 'unique_everseen', 'varexpand',
'write_atomic', 'writedict', 'writemsg', 'writemsg_level', 'writemsg_stdout']
-import codecs
from copy import deepcopy
import errno
+import io
try:
from itertools import filterfalse
except ImportError:
os.path.join(myfilename, f), recursive, remember_source_file))
else:
try:
- myfile = codecs.open(_unicode_encode(myfilename,
+ myfile = io.open(_unicode_encode(myfilename,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='replace')
if remember_source_file:
if 'b' in mode:
open_func = open
else:
- open_func = codecs.open
+ open_func = io.open
kargs.setdefault('encoding', _encodings['content'])
kargs.setdefault('errors', 'backslashreplace')
def _get_target(self):
return object.__getattribute__(self, '_file')
- def __getattribute__(self, attr):
- if attr in ('close', 'abort', '__del__'):
- return object.__getattribute__(self, attr)
- return getattr(object.__getattribute__(self, '_file'), attr)
+ if sys.hexversion >= 0x3000000:
+
+ def __getattribute__(self, attr):
+ if attr in ('close', 'abort', '__del__'):
+ return object.__getattribute__(self, attr)
+ return getattr(object.__getattribute__(self, '_file'), attr)
+
+ else:
+
+ # For TextIOWrapper, automatically coerce write calls to
+ # unicode, in order to avoid TypeError when writing raw
+ # bytes with python2.
+
+ def __getattribute__(self, attr):
+ if attr in ('close', 'abort', 'write', '__del__'):
+ return object.__getattribute__(self, attr)
+ return getattr(object.__getattribute__(self, '_file'), attr)
+
+ def write(self, s):
+ f = object.__getattribute__(self, '_file')
+ if isinstance(f, io.TextIOWrapper):
+ s = _unicode_decode(s)
+ return f.write(s)
def close(self):
"""Closes the temporary file, copies permissions (if possible),
__all__ = ['env_update']
-import codecs
import errno
+import io
import stat
import sys
import time
ldsoconf_path = os.path.join(target_root, "etc", "ld.so.conf")
try:
- myld = codecs.open(_unicode_encode(ldsoconf_path,
+ myld = io.open(_unicode_encode(ldsoconf_path,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='replace')
myldlines=myld.readlines()
# repoman: Utilities
-# Copyright 2007-2010 Gentoo Foundation
+# Copyright 2007-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
"""This module contains utility functions to help repoman find ebuilds to
"check_metadata"
]
-import codecs
import errno
+import io
import logging
import sys
from portage import os
if not (os.WIFEXITED(retval) and os.WEXITSTATUS(retval) == os.EX_OK):
return None
try:
- mylines = codecs.open(_unicode_encode(filename,
+ mylines = io.open(_unicode_encode(filename,
encoding=_encodings['fs'], errors='strict'),
mode='r', encoding=_encodings['content'], errors='replace'
).readlines()