else:
return True
- confs = filter (f, confs)
+ confs = [x for x in confs if f(x)]
#
# Interactively process remaining
self._check_world(onProgress)
errors = []
if self.found:
- errors += map(lambda x: "'%s' is not a valid atom" % x, self.invalid)
- errors += map(lambda x: "'%s' is not installed" % x, self.not_installed)
- errors += map(lambda x: "'%s' has a category that is not listed in /etc/portage/categories" % x, self.invalid_category)
+ errors += ["'%s' is not a valid atom" % x for x in self.invalid]
+ errors += ["'%s' is not installed" % x for x in self.not_installed]
+ errors += ["'%s' has a category that is not listed in /etc/portage/categories" % x for x in self.invalid_category]
else:
errors.append(self.world_file + " could not be opened for reading")
return errors
sys.exit(0)
worldlist = portage.grabfile(os.path.join(portage.const.EPREFIX, portage.WORLD_FILE))
-syslist = portage.settings.packages
-syslist = filter(issyspkg, syslist)
+syslist = [x for x in portage.settings.packages if issyspkg(x)]
logfile = portage.grabfile(portage.const.EPREFIX+"/var/log/emerge.log")
-biglist = filter(iscandidate, logfile)
-biglist = map(getpkginfo, biglist)
+biglist = [getpkginfo(x) for x in logfile if iscandidate(x)]
tmplist = []
for l in biglist:
tmplist += l.split()
-biglist = filter(isunwanted, tmplist)
+biglist = [x for x in tmplist if isunwanted(x)]
#for p in biglist:
-# print p
+# print(p)
#sys.exit(0)
# resolving virtuals
for mykey in syslist:
# drop the asterix
mykey = mykey[1:]
- #print "candidate:",mykey
+ #print("candidate:",mykey)
mylist=portage.db["/"]["vartree"].dbapi.match(mykey)
if mylist:
mykey=portage.cpv_getkey(mylist[0])
realsyslist.append(mykey)
for mykey in biglist:
- #print "checking:",mykey
+ #print("checking:",mykey)
try:
mylist=portage.db["/"]["vartree"].dbapi.match(mykey)
except (portage.exception.InvalidAtom, KeyError):
keys = __iter__
items = iteritems
+def _test_pty_eof():
+ """
+ Returns True if this issues is fixed for the currently
+ running version of python: http://bugs.python.org/issue5380
+ Raises an EnvironmentError from openpty() if it fails.
+ """
+
+ import array, pty, termios
+ test_string = 2 * "blah blah blah\n"
+ test_string = _unicode_decode(test_string,
+ encoding='utf_8', errors='strict')
+
+ # may raise EnvironmentError
+ master_fd, slave_fd = pty.openpty()
+
+ master_file = os.fdopen(master_fd, 'rb')
+ slave_file = os.fdopen(slave_fd, 'wb')
+
+ # Disable post-processing of output since otherwise weird
+ # things like \n -> \r\n transformations may occur.
+ mode = termios.tcgetattr(slave_fd)
+ mode[1] &= ~termios.OPOST
+ termios.tcsetattr(slave_fd, termios.TCSANOW, mode)
+
+ # Simulate a subprocess writing some data to the
+ # slave end of the pipe, and then exiting.
+ slave_file.write(_unicode_encode(test_string,
+ encoding='utf_8', errors='strict'))
+ slave_file.close()
+
+ eof = False
+ data = []
+
+ while not eof:
+
+ buf = array.array('B')
+ try:
+ buf.fromfile(master_file, 1024)
+ except EOFError:
+ eof = True
+ except IOError:
+ # This is where data loss occurs.
+ eof = True
+
+ if not buf:
+ eof = True
+ else:
+ data.append(_unicode_decode(buf.tostring(),
+ encoding='utf_8', errors='strict'))
+
+ master_file.close()
+
+ return test_string == ''.join(data)
+
# In some cases, openpty can be slow when it fails. Therefore,
# stop trying to use it after the first failure.
if platform.system() in ["SunOS"]:
_disable_openpty = True
else:
_disable_openpty = False
-
-if sys.hexversion >= 0x3000000:
- # This is a temporary workaround for http://bugs.python.org/issue5380.
- _disable_openpty = True
+_tested_pty = False
def _create_pty_or_pipe(copy_term_size=None):
"""
got_pty = False
- global _disable_openpty
+ global _disable_openpty, _tested_pty
+ if not (_tested_pty or _disable_openpty):
+ try:
+ if not _test_pty_eof():
+ _disable_openpty = True
+ except EnvironmentError as e:
+ _disable_openpty = True
+ writemsg("openpty failed: '%s'\n" % str(e),
+ noiselevel=-1)
+ del e
+ _tested_pty = True
+
if _disable_openpty:
master_fd, slave_fd = os.pipe()
else:
return 0
continue
for d in dirs:
+ d_bytes = d
try:
d = _unicode_decode(d,
encoding=_encodings['fs'], errors='strict')
noiselevel=-1)
if strict:
return 0
- dirs.remove(d)
+ dirs.remove(d_bytes)
continue
if d.startswith(".") or d == "CVS":
- dirs.remove(d)
+ dirs.remove(d_bytes)
for f in files:
try:
f = _unicode_decode(f,
mode='r', encoding=_encodings['repo.content'],
errors='replace')
try:
- d = self._parse_data(myf.read().split("\n"), cpv)
+ lines = myf.read().split("\n")
+ if not lines[-1]:
+ lines.pop()
+ d = self._parse_data(lines, cpv)
if '_mtime_' not in d:
# Backward compatibility with old cache
# that uses mtime mangling.
# XXX: REMOVE THIS ONCE UNUSED_0 IS YANKED FROM auxdbkeys
# ~harring
- filtered_auxdbkeys = list(filter(lambda x: not x.startswith("UNUSED_0"), auxdbkeys))
+ filtered_auxdbkeys = [x for x in auxdbkeys if not x.startswith("UNUSED_0")]
filtered_auxdbkeys.sort()
from portage.cache import metadata_overlay, volatile
if not depcachedir_w_ok:
for x in filter(None, fields[3].replace(
"${ORIGIN}", os.path.dirname(obj)).replace(
"$ORIGIN", os.path.dirname(obj)).split(":"))])
- needed = filter(None, fields[4].split(","))
+ needed = [x for x in fields[4].split(",") if x]
obj_key = self._obj_key(obj)
indexed = True
# <revised count="2">2007-12-30</revised>
revisedEl = myroot.getElementsByTagName("revised")[0]
self.revised = getText(revisedEl, format="strip")
- if (revisedEl.attributes.has_key("count")):
+ if ((sys.hexversion >= 0x3000000 and "count" in revisedEl.attributes) or
+ (sys.hexversion < 0x3000000 and revisedEl.attributes.has_key("count"))):
count = revisedEl.getAttribute("count")
elif (self.revised.find(":") >= 0):
(self.revised, count) = self.revised.split(":")
self.stream.writeln()
if not result.wasSuccessful():
self.stream.write("FAILED (")
- failed, errored = map(len, (result.failures, result.errors))
+ failed = len(result.failures)
+ errored = len(result.errors)
if failed:
self.stream.write("failures=%d" % failed)
if errored:
--- /dev/null
+# Copyright 1998-2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+import pty
+
+import portage
+from portage import os
+from portage.tests import TestCase
+
+class PtyEofTestCase(TestCase):
+
+ def testPtyEof(self):
+ # This tests if the following python issue is fixed yet:
+ # http://bugs.python.org/issue5380
+ # Since it might not be fixed, mark as todo.
+ self.todo = True
+ # The result is only valid if openpty does not raise EnvironmentError.
+ try:
+ self.assertEqual(portage._test_pty_eof(), True)
+ except EnvironmentError:
+ pass
mode='r', encoding=_encodings['content'],
errors='replace').readlines()
except IOError:
- if file_contents.has_key(x):
- del file_contents[x]
continue
# update /etc/portage/packages.*
new_dl = {}
for key in myDict:
new_dl[key] = []
- new_dl[key] = map(func,myDict[key])
+ new_dl[key] = [func(x) for x in myDict[key]]
return new_dl
def stack_dictlist(original_dicts, incremental=0, incrementals=[], ignore_none=0):
Args:
settings - portage.config instance, preferably repoman_settings
Returns:
- tuple(portdir, portdir_overlay, location)
+ list(portdir, portdir_overlay, location)
"""
portdir = None
if not portdir.endswith('/'):
portdir += '/'
- return map(normalize_path, (portdir, portdir_overlay, location))
+ return [normalize_path(x) for x in (portdir, portdir_overlay, location)]