diff options
author | Paul Varner <fuzzyray@gentoo.org> | 2015-11-24 13:07:33 -0600 |
---|---|---|
committer | Paul Varner <fuzzyray@gentoo.org> | 2015-11-24 13:07:33 -0600 |
commit | c9a117bebeb04efcb731e47a12e79c4c8d065896 (patch) | |
tree | 6db392af53510002fce752a07b5c9d79daafddea /pym/gentoolkit | |
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')
-rw-r--r-- | pym/gentoolkit/deprecated/helpers.py | 4 | ||||
-rw-r--r-- | pym/gentoolkit/eclean/exclude.py | 4 | ||||
-rw-r--r-- | pym/gentoolkit/enalyze/rebuild.py | 4 | ||||
-rw-r--r-- | pym/gentoolkit/equery/uses.py | 5 | ||||
-rw-r--r-- | pym/gentoolkit/equery/which.py | 4 | ||||
-rw-r--r-- | pym/gentoolkit/eshowkw/keywords_header.py | 5 | ||||
-rw-r--r-- | pym/gentoolkit/glsa/__init__.py | 5 | ||||
-rw-r--r-- | pym/gentoolkit/helpers.py | 8 | ||||
-rw-r--r-- | pym/gentoolkit/revdep_rebuild/analyse.py | 3 | ||||
-rw-r--r-- | pym/gentoolkit/revdep_rebuild/cache.py | 12 | ||||
-rw-r--r-- | pym/gentoolkit/revdep_rebuild/collect.py | 8 | ||||
-rw-r--r-- | pym/gentoolkit/revdep_rebuild/settings.py | 4 |
12 files changed, 43 insertions, 23 deletions
diff --git a/pym/gentoolkit/deprecated/helpers.py b/pym/gentoolkit/deprecated/helpers.py index 59d6a2c..c3a72dc 100644 --- a/pym/gentoolkit/deprecated/helpers.py +++ b/pym/gentoolkit/deprecated/helpers.py @@ -12,6 +12,7 @@ from __future__ import print_function import warnings import portage +from portage import _encodings, _unicode_decode, _unicode_encode from gentoolkit import * from package import * from pprinter import warn @@ -99,7 +100,8 @@ def find_system_packages(prefilter=None): def find_world_packages(prefilter=None): """Returns a tuple of lists, first list is resolved world packages, seond is unresolved package names.""" - f = open(portage.root+portage.WORLD_FILE) + f = open(_unicode_encode(portage.root+portage.WORLD_FILE), + encoding=_encodings['fs']) pkglist = f.readlines() resolved = [] unresolved = [] diff --git a/pym/gentoolkit/eclean/exclude.py b/pym/gentoolkit/eclean/exclude.py index a6422d0..5a13186 100644 --- a/pym/gentoolkit/eclean/exclude.py +++ b/pym/gentoolkit/eclean/exclude.py @@ -11,6 +11,7 @@ import os import sys import re import portage +from portage import _encodings, _unicode_decode, _unicode_encode from gentoolkit.pprinter import warn @@ -81,7 +82,8 @@ def parseExcludeFile(filepath, output): } output("Parsing Exclude file: " + filepath) try: - file_ = open(filepath,"r") + file_ = open(_unicode_encode(filepath), + encoding=_encodings['fs'], mode="r") except IOError: raise ParseExcludeFileException("Could not open exclusion file: " + filepath) diff --git a/pym/gentoolkit/enalyze/rebuild.py b/pym/gentoolkit/enalyze/rebuild.py index 778fed4..3f9527a 100644 --- a/pym/gentoolkit/enalyze/rebuild.py +++ b/pym/gentoolkit/enalyze/rebuild.py @@ -27,7 +27,7 @@ from gentoolkit.atom import Atom import portage - +from portage import _encodings, _unicode_decode, _unicode_encode def cpv_all_diff_use( cpvs=None, @@ -352,7 +352,7 @@ class Rebuild(ModuleBase): """ if not self.options["quiet"]: print(' - Saving file: %s' %filepath) - with open(filepath, "w") as output: + with open(_unicode_encode(filepath), encoding=_encodings['fs'], mode="w") as output: output.write('\n'.join(data)) print(" - Done") diff --git a/pym/gentoolkit/equery/uses.py b/pym/gentoolkit/equery/uses.py index cedac96..7717710 100644 --- a/pym/gentoolkit/equery/uses.py +++ b/pym/gentoolkit/equery/uses.py @@ -21,6 +21,7 @@ from getopt import gnu_getopt, GetoptError from glob import glob from portage import settings +from portage import _encodings, _unicode_decode, _unicode_encode import gentoolkit.pprinter as pp from gentoolkit import errors @@ -135,7 +136,7 @@ def get_global_useflags(): # Get global USE flag descriptions try: path = os.path.join(settings["PORTDIR"], 'profiles', 'use.desc') - with open(path) as open_file: + with open(_unicode_encode(path), encoding=_encodings['fs']) as open_file: for line in open_file: if line.startswith('#'): continue @@ -155,7 +156,7 @@ def get_global_useflags(): for path in glob(os.path.join(settings["PORTDIR"], 'profiles', 'desc', '*.desc')): try: - with open(path) as open_file: + with open(_unicode_encode(path), encoding=_encodings['fs']) as open_file: for line in open_file: if line.startswith('#'): continue diff --git a/pym/gentoolkit/equery/which.py b/pym/gentoolkit/equery/which.py index da60a1b..ea03b90 100644 --- a/pym/gentoolkit/equery/which.py +++ b/pym/gentoolkit/equery/which.py @@ -26,6 +26,8 @@ from gentoolkit import errors from gentoolkit.equery import format_options, mod_usage from gentoolkit.query import Query +from portage import _encodings, _unicode_decode, _unicode_encode + # ======= # Globals # ======= @@ -60,7 +62,7 @@ def print_help(with_description=True): def print_ebuild(ebuild_path): """Output the ebuild to std_out""" - with open(ebuild_path) as f: + with open(_unicode_encode(ebuild_path), encoding=_encodings['fs']) as f: lines = f.readlines() print("\n\n") print("".join(lines)) diff --git a/pym/gentoolkit/eshowkw/keywords_header.py b/pym/gentoolkit/eshowkw/keywords_header.py index aaf1e8c..9ca0364 100644 --- a/pym/gentoolkit/eshowkw/keywords_header.py +++ b/pym/gentoolkit/eshowkw/keywords_header.py @@ -6,6 +6,7 @@ __all__ = ['keywords_header'] import portage import os +from portage import _encodings, _unicode_decode, _unicode_encode from portage import settings as ports from portage.output import colorize from gentoolkit.eshowkw.display_pretty import colorize_string @@ -30,7 +31,7 @@ def load_profile_data(portdir=None, repo='gentoo'): try: arch_list = os.path.join(portdir, 'profiles', 'arch.list') - with open(arch_list) as f: + with open(_unicode_encode(arch_list), encoding=_encodings['fs']) as f: for line in f: line = line.split('#', 1)[0].strip() if line: @@ -46,7 +47,7 @@ def load_profile_data(portdir=None, repo='gentoo'): None: 3, } profiles_list = os.path.join(portdir, 'profiles', 'profiles.desc') - with open(profiles_list) as f: + with open(_unicode_encode(profiles_list), encoding=_encodings['fs']) as f: for line in f: line = line.split('#', 1)[0].split() if line: diff --git a/pym/gentoolkit/glsa/__init__.py b/pym/gentoolkit/glsa/__init__.py index a9eb30b..0d670b7 100644 --- a/pym/gentoolkit/glsa/__init__.py +++ b/pym/gentoolkit/glsa/__init__.py @@ -35,9 +35,11 @@ if sys.version_info[0:2] < (2,3): try: import portage + from portage import _encodings, _unicode_decode, _unicode_encode except ImportError: sys.path.insert(0, "/usr/lib/portage/pym") import portage + from portage import _encodings, _unicode_decode, _unicode_encode # Note: the space for rgt and rlt is important !! @@ -702,7 +704,8 @@ class Glsa: @returns: None """ if not self.isInjected(): - checkfile = open(self.config["CHECKFILE"], "a+") + checkfile = open(_unicode_encode(self.config["CHECKFILE"]), + encoding=_encodings['fs'], mode="a+") checkfile.write(self.nr+"\n") checkfile.close() return None diff --git a/pym/gentoolkit/helpers.py b/pym/gentoolkit/helpers.py index 55fecdb..f9da6cd 100644 --- a/pym/gentoolkit/helpers.py +++ b/pym/gentoolkit/helpers.py @@ -27,11 +27,11 @@ __docformat__ = 'epytext' import os import re -import codecs from functools import partial from itertools import chain import portage +from portage import _encodings, _unicode_decode, _unicode_encode from gentoolkit import pprinter as pp from gentoolkit import errors @@ -194,8 +194,8 @@ class ChangeLog(object): result = [] partial_entries = [] - with codecs.open(self.changelog_path, encoding="utf-8", - errors="replace") as log: + with open(_unicode_encode(self.changelog_path), + encoding=_encodings['fs'], errors="replace") as log: for line in log: if line.startswith('#'): continue @@ -464,7 +464,7 @@ def get_bintree_cpvs(predicate=None): def print_file(path): """Display the contents of a file.""" - with open(path, "rb") as open_file: + with open(_unicode_encode(path), encoding=_encodings['fs'], mode="rb") as open_file: lines = open_file.read() pp.uprint(lines.strip()) diff --git a/pym/gentoolkit/revdep_rebuild/analyse.py b/pym/gentoolkit/revdep_rebuild/analyse.py index c0e7231..0f89b03 100644 --- a/pym/gentoolkit/revdep_rebuild/analyse.py +++ b/pym/gentoolkit/revdep_rebuild/analyse.py @@ -8,6 +8,7 @@ import os import re import time +from portage import _encodings, _unicode_decode, _unicode_encode from portage.output import bold, blue, yellow, green from .stuff import scan @@ -82,7 +83,7 @@ def extract_dependencies_from_la(la, libraries, to_check, logger): if not os.path.exists(_file): continue - for line in open(_file, 'r').readlines(): + for line in open(_unicode_encode(_file), encoding=_encodings['fs'], mode='r').readlines(): line = line.strip() if line.startswith('dependency_libs='): match = re.match("dependency_libs='([^']+)'", line) 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: diff --git a/pym/gentoolkit/revdep_rebuild/collect.py b/pym/gentoolkit/revdep_rebuild/collect.py index 2a431cb..758bcf7 100644 --- a/pym/gentoolkit/revdep_rebuild/collect.py +++ b/pym/gentoolkit/revdep_rebuild/collect.py @@ -11,6 +11,7 @@ import stat import sys import portage +from portage import _encodings, _unicode_decode, _unicode_encode from portage.output import blue, yellow from .settings import parse_revdep_config @@ -34,7 +35,7 @@ def parse_conf(conf_file, visited=None, logger=None): for conf in conf_file: try: - with open(conf) as _file: + with open(_unicode_encode(conf), encoding=_encodings['fs']) as _file: for line in _file.readlines(): line = line.strip() if line.startswith('#'): @@ -74,8 +75,9 @@ def prepare_search_dirs(logger, settings): lib_dirs = set(['/lib', '/usr/lib', ]) #try: - with open(os.path.join( - portage.root, settings['DEFAULT_ENV_FILE']), 'r') as _file: + with open(_unicode_encode(os.path.join( + portage.root, settings['DEFAULT_ENV_FILE'])), + encoding=_encodings['fs'], mode='r') as _file: for line in _file.readlines(): line = line.strip() match = re.match("^export (ROOT)?PATH='([^']+)'", line) diff --git a/pym/gentoolkit/revdep_rebuild/settings.py b/pym/gentoolkit/revdep_rebuild/settings.py index 08220f8..257bd3a 100644 --- a/pym/gentoolkit/revdep_rebuild/settings.py +++ b/pym/gentoolkit/revdep_rebuild/settings.py @@ -11,6 +11,7 @@ import re import glob import portage +from portage import _encodings, _unicode_decode, _unicode_encode DEFAULTS = { 'DEFAULT_LD_FILE': os.path.join(portage.root, 'etc/ld.so.conf'), @@ -136,7 +137,8 @@ def parse_revdep_config(revdep_confdir): masked_files = os.environ.get('LD_LIBRARY_MASK', '') for _file in os.listdir(revdep_confdir): - for line in open(os.path.join(revdep_confdir, _file)): + for line in open(_unicode_encode(os.path.join(revdep_confdir, _file)), + encoding=_encodings['fs']): line = line.strip() #first check for comment, we do not want to regex all lines if not line.startswith('#'): |