diff options
author | Zac Medico <zmedico@gentoo.org> | 2009-08-06 09:18:49 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2009-08-06 09:18:49 +0000 |
commit | 11077ac16f68d49d4fd08817255385f428338d7c (patch) | |
tree | 70b8c7a9460d294cf19f2b125cf6040869580fed | |
parent | 791b1bc23bf51f5706de80d2b4ce2236e0054cf3 (diff) | |
download | portage-11077ac16f68d49d4fd08817255385f428338d7c.tar.gz portage-11077ac16f68d49d4fd08817255385f428338d7c.tar.bz2 portage-11077ac16f68d49d4fd08817255385f428338d7c.zip |
Add unicode conversions in various logging code.
svn path=/main/trunk/; revision=13931
-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] = {} |