diff options
author | Zac Medico <zmedico@gentoo.org> | 2010-08-28 15:51:37 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2010-08-28 15:51:37 -0700 |
commit | 87b1b094b789f414da007214bbd3f651671f084f (patch) | |
tree | ee475d2e07d13de6ba6f4be2c1bba8a5e381a0e6 | |
parent | 678f3895b1a3d8c33977c2946aa520440c8d2461 (diff) | |
download | portage-87b1b094b789f414da007214bbd3f651671f084f.tar.gz portage-87b1b094b789f414da007214bbd3f651671f084f.tar.bz2 portage-87b1b094b789f414da007214bbd3f651671f084f.zip |
Make egencache --update-use-local-desc use codecs.open() to write to
use.local.desc (fixes possible unicode issues with python3).
-rwxr-xr-x | bin/egencache | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/bin/egencache b/bin/egencache index 7a3a9f218..a16ac4f93 100755 --- a/bin/egencache +++ b/bin/egencache @@ -20,6 +20,7 @@ try: except KeyboardInterrupt: sys.exit(1) +import codecs import logging import optparse @@ -30,7 +31,7 @@ except ImportError: sys.path.insert(0, osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "pym")) import portage -from portage import os +from portage import os, _encodings, _unicode_encode from _emerge.MetadataRegen import MetadataRegen from portage.cache.cache_errors import CacheError, StatCollision from portage.util import cmp_sort_key, writemsg_level @@ -341,15 +342,17 @@ class GenUseLocalDesc(object): else: desc_path = self._output - if self._preserve_comments: - # Probe in binary mode, in order to avoid - # potential character encoding issues. - output_mode = 'rb' - else: - output_mode = 'w' - try: - output = open(desc_path, output_mode) + if self._preserve_comments: + # Probe in binary mode, in order to avoid + # potential character encoding issues. + output = open(_unicode_encode(desc_path, + encoding=_encodings['fs'], errors='strict'), 'r+b') + else: + output = codecs.open(_unicode_encode(desc_path, + encoding=_encodings['fs'], errors='strict'), + mode='w', encoding=_encodings['repo.content'], + errors='replace') except IOError as e: writemsg_level( "ERROR: failed to open output file %s: %s\n" % (output_mode,e,), @@ -364,14 +367,18 @@ class GenUseLocalDesc(object): pos = output.tell() if not output.readline().startswith(b'#'): break + output.seek(pos) + output.truncate() output.close() - # Finished probing comments, now open for write. - output = open(desc_path, 'r+') - output.seek(pos) + # Finished probing comments in binary mode, now append + # in text mode. + output = codecs.open(_unicode_encode(desc_path, + encoding=_encodings['fs'], errors='strict'), + mode='a', encoding=_encodings['repo.content'], + errors='replace') output.write('\n') - output.truncate() - else: + else: output.write(''' # This file is deprecated as per GLEP 56 in favor of metadata.xml. Please add # your descriptions to your package's metadata.xml ONLY. |