diff options
author | 2015-11-24 13:07:33 -0600 | |
---|---|---|
committer | 2015-11-24 13:07:33 -0600 | |
commit | c9a117bebeb04efcb731e47a12e79c4c8d065896 (patch) | |
tree | 6db392af53510002fce752a07b5c9d79daafddea /pym/gentoolkit/revdep_rebuild/cache.py | |
parent | Fix spelling error (diff) | |
download | gentoolkit-c9a117bebeb04efcb731e47a12e79c4c8d065896.tar.gz gentoolkit-c9a117bebeb04efcb731e47a12e79c4c8d065896.tar.bz2 gentoolkit-c9a117bebeb04efcb731e47a12e79c4c8d065896.zip |
Change all open() calls to use Unicode.
We are using the following import from portage:
from portage import _encodings, _unicode_decode, _unicode_encode
A generalized call using the definitions from portage looks like:
with open(_unicode_encode(path), encoding=_encodings['fs']) as open_file
The portage code has been in place since 2013 and using the definitions
from portage ensures we maintain compatibility if portage changes.
All portage versions in the tree contain the above code.
Diffstat (limited to 'pym/gentoolkit/revdep_rebuild/cache.py')
-rw-r--r-- | pym/gentoolkit/revdep_rebuild/cache.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/pym/gentoolkit/revdep_rebuild/cache.py b/pym/gentoolkit/revdep_rebuild/cache.py index 3d925d8..31ee2c9 100644 --- a/pym/gentoolkit/revdep_rebuild/cache.py +++ b/pym/gentoolkit/revdep_rebuild/cache.py @@ -8,6 +8,7 @@ from __future__ import print_function import os import time +from portage import _encodings, _unicode_decode, _unicode_encode from portage.output import red from .settings import DEFAULTS @@ -29,7 +30,8 @@ def read_cache(temp_path=DEFAULTS['DEFAULT_TMP_DIR']): } try: for key,val in ret.items(): - _file = open(os.path.join(temp_path, key)) + _file = open(_unicode_encode(os.path.join(temp_path, key)), + encoding=_encodings['fs']) for line in _file.readlines(): val.add(line.strip()) #libraries.remove('\n') @@ -52,12 +54,14 @@ def save_cache(logger, to_save={}, temp_path=DEFAULTS['DEFAULT_TMP_DIR']): os.makedirs(temp_path) try: - _file = open(os.path.join(temp_path, 'timestamp'), 'w') + _file = open(_unicode_encode(os.path.join(temp_path, 'timestamp')), + encoding=_encodings['fs'], mode='w') _file.write(str(int(time.time()))) _file.close() for key,val in to_save.items(): - _file = open(os.path.join(temp_path, key), 'w') + _file = open(_unicode_encode(os.path.join(temp_path, key)), + encoding=_encodings['fs'], mode='w') for line in val: _file.write(line + '\n') _file.close() @@ -85,7 +89,7 @@ def check_temp_files(temp_path=DEFAULTS['DEFAULT_TMP_DIR'], max_delay=3600, return False try: - _file = open(timestamp_path) + _file = open(_unicode_encode(timestamp_path), encoding=_encodings['fs']) timestamp = int(_file.readline()) _file .close() except Exception as ex: |