diff options
-rw-r--r-- | pym/_emerge/Scheduler.py | 4 | ||||
-rw-r--r-- | pym/_emerge/emergelog.py | 7 | ||||
-rw-r--r-- | pym/portage/elog/messages.py | 18 |
3 files changed, 24 insertions, 5 deletions
diff --git a/pym/_emerge/Scheduler.py b/pym/_emerge/Scheduler.py index 0ad91675f..ec6135d32 100644 --- a/pym/_emerge/Scheduler.py +++ b/pym/_emerge/Scheduler.py @@ -477,6 +477,10 @@ class Scheduler(PollScheduler): return self._pkg(cpv, type_name, root_config, installed=installed) def _append_to_log_path(self, log_path, msg): + + if not isinstance(msg, unicode): + msg = unicode(msg, encoding='utf_8', errors='replace') + f = codecs.open(log_path, mode='a', encoding='utf_8', errors='replace') try: diff --git a/pym/_emerge/emergelog.py b/pym/_emerge/emergelog.py index 1469f5265..1a26cc9fa 100644 --- a/pym/_emerge/emergelog.py +++ b/pym/_emerge/emergelog.py @@ -19,6 +19,13 @@ from portage.output import xtermTitle _emerge_log_dir = '/var/log' def emergelog(xterm_titles, mystr, short_msg=None): + + if not isinstance(mystr, unicode): + mystr = unicode(mystr, encoding='utf_8', errors='replace') + + if short_msg is not None and not isinstance(short_msg, unicode): + short_msg = unicode(short_msg, encoding='utf_8', errors='replace') + if xterm_titles and short_msg: if "HOSTNAME" in os.environ: short_msg = os.environ["HOSTNAME"]+": "+short_msg diff --git a/pym/portage/elog/messages.py b/pym/portage/elog/messages.py index 9832f2660..3b44e0fe8 100644 --- a/pym/portage/elog/messages.py +++ b/pym/portage/elog/messages.py @@ -79,15 +79,23 @@ def _elog_base(level, msg, phase="other", key=None, color=None, out=None): global _msgbuffer - if color == None: + if out is None: + out = sys.stdout + + if color is None: color = "GOOD" + if not isinstance(msg, unicode): + msg = unicode(msg, encoding='utf_8', errors='replace') + formatted_msg = colorize(color, " * ") + msg + "\n" - if out is None: - sys.stdout.write(formatted_msg) - else: - out.write(formatted_msg) + if sys.hexversion < 0x3000000 and \ + out in (sys.stdout, sys.stderr) and isinstance(formatted_msg, unicode): + # avoid potential UnicodeEncodeError + formatted_msg = formatted_msg.encode('utf_8', 'replace') + + out.write(formatted_msg) if key not in _msgbuffer: _msgbuffer[key] = {} |