From af9eb15b72eadb8fc5e271fe2b518103b47567c9 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 16 Sep 2010 04:32:31 -0700 Subject: [PATCH] Make Package __str__ and __unicode__ methods more like DependencyArg. --- pym/_emerge/Package.py | 10 +++++++++- pym/_emerge/Scheduler.py | 6 ++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pym/_emerge/Package.py b/pym/_emerge/Package.py index 0db16fb2f..66ac7ff67 100644 --- a/pym/_emerge/Package.py +++ b/pym/_emerge/Package.py @@ -4,7 +4,7 @@ import sys from itertools import chain import portage -from portage import _unicode_decode +from portage import _encodings, _unicode_decode, _unicode_encode from portage.cache.mappings import slot_dict_class from portage.const import EBUILD_PHASES from portage.dep import Atom, check_required_use, use_reduce, \ @@ -298,6 +298,14 @@ class Package(Task): s += ")" return s + if sys.hexversion < 0x3000000: + + __unicode__ = __str__ + + def __str__(self): + return _unicode_encode(self.__unicode__(), + encoding=_encodings['content']) + class _use_class(object): __slots__ = ("__weakref__", "enabled") diff --git a/pym/_emerge/Scheduler.py b/pym/_emerge/Scheduler.py index d45f26d9f..4b6b80f76 100644 --- a/pym/_emerge/Scheduler.py +++ b/pym/_emerge/Scheduler.py @@ -19,7 +19,7 @@ import portage from portage import StringIO from portage import os from portage import _encodings -from portage import _unicode_encode +from portage import _unicode_decode, _unicode_encode from portage.cache.mappings import slot_dict_class from portage.const import LIBC_PACKAGE_ATOM from portage.elog.messages import eerror @@ -1203,7 +1203,9 @@ class Scheduler(PollScheduler): printer.eerror(line) printer.eerror("") for failed_pkg in self._failed_pkgs_all: - msg = " %s" % (colorize('INFORM', failed_pkg.pkg.__str__()),) + # Use _unicode_decode() to force unicode format string so + # that Package.__unicode__() is called in python2. + msg = _unicode_decode(" %s") % (failed_pkg.pkg,) log_path = self._locate_failure_log(failed_pkg) if log_path is not None: msg += ", Log file:" -- 2.26.2