Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pym/gentoolkit/eclean/exclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import os
import re
import portage
from portage import _encodings, _unicode_encode

# Misc. shortcuts to some portage stuff:
listdir = portage.listdir
Expand Down Expand Up @@ -78,8 +77,8 @@ def parseExcludeFile(filepath, output):
output("Parsing Exclude file: " + filepath)
try:
file_ = open(
_unicode_encode(filepath, encoding=_encodings["fs"]),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, see https://bugs.gentoo.org/914722 and 4f5f6f571e52af6d2703db760bad4e0ad7439d5a in Portage.

Sadly, we still have a lot of baggage to remove: gentoo/portage#700

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I started cleaning things up in this area with gentoo/portage#1601

I'll review the one you linked to see if there is something valuable there.

encoding=_encodings["content"],
filepath,
encoding="utf-8",
)
except OSError:
raise ParseExcludeFileException("Could not open exclusion file: " + filepath)
Expand Down
5 changes: 2 additions & 3 deletions pym/gentoolkit/enalyze/rebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@


import portage
from portage import _encodings, _unicode_encode


def cpv_all_diff_use(
Expand Down Expand Up @@ -391,9 +390,9 @@ def save_file(self, filepath, data):
if not self.options["quiet"]:
print(" - Saving file: %s" % filepath)
with open(
_unicode_encode(filepath, encoding=_encodings["fs"]),
filepath,
mode="w",
encoding=_encodings["content"],
encoding="utf-8",
) as output:
output.write("\n".join(data))
output.write("\n")
Expand Down
9 changes: 4 additions & 5 deletions pym/gentoolkit/equery/uses.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from glob import glob

from portage import settings
from portage import _encodings, _unicode_encode

import gentoolkit.pprinter as pp
from gentoolkit import errors
Expand Down Expand Up @@ -151,8 +150,8 @@ def get_global_useflags():
try:
path = os.path.join(settings["PORTDIR"], "profiles", "use.desc")
with open(
_unicode_encode(path, encoding=_encodings["fs"]),
encoding=_encodings["content"],
path,
encoding="utf-8",
) as open_file:
for line in open_file:
if line.startswith("#"):
Expand All @@ -171,8 +170,8 @@ def get_global_useflags():
for path in glob(os.path.join(settings["PORTDIR"], "profiles", "desc", "*.desc")):
try:
with open(
_unicode_encode(path, encoding=_encodings["fs"]),
encoding=_encodings["content"],
path,
encoding="utf-8",
) as open_file:
for line in open_file:
if line.startswith("#"):
Expand Down
6 changes: 2 additions & 4 deletions pym/gentoolkit/equery/which.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
from gentoolkit.equery import format_options, mod_usage
from gentoolkit.query import Query

from portage import _encodings, _unicode_encode

# =======
# Globals
# =======
Expand Down Expand Up @@ -62,8 +60,8 @@ def print_help(with_description=True):
def print_ebuild(ebuild_path):
"""Output the ebuild to std_out"""
with open(
_unicode_encode(ebuild_path, encoding=_encodings["fs"]),
encoding=_encodings["content"],
ebuild_path,
encoding="utf-8",
) as f:
lines = f.readlines()
print("\n\n")
Expand Down
4 changes: 3 additions & 1 deletion pym/gentoolkit/eshowkw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ def main(argv, indirect=False):
for repo in ports.repositories:
repos[repo.name] = repo.location

with open(os.path.join(ourtree, "profiles", "repo_name")) as f:
with open(
os.path.join(ourtree, "profiles", "repo_name"), encoding="utf-8"
) as f:
repo_name = f.readline().strip()

repos[repo_name] = ourtree
Expand Down
3 changes: 1 addition & 2 deletions pym/gentoolkit/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from itertools import chain

import portage
from portage import _encodings, _unicode_encode

from gentoolkit import pprinter as pp
from gentoolkit import errors
Expand Down Expand Up @@ -300,7 +299,7 @@ def get_bintree_cpvs(predicate=None):
def print_file(path):
"""Display the contents of a file."""

with open(_unicode_encode(path, encoding=_encodings["fs"]), mode="rb") as open_file:
with open(path, mode="rb") as open_file:
lines = open_file.read()
pp.uprint(lines.strip())

Expand Down
2 changes: 1 addition & 1 deletion pym/gentoolkit/imlate/imlate.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def show_result(conf, pkgs):
elif conf["FILE"] == "stderr":
out = stderr
else:
out = open(conf["FILE"], "w")
out = open(conf["FILE"], "w", encoding="utf-8")

if conf["STABLE"] and conf["KEYWORD"]:
_cand = "%i Stable and %i Keyword(~)" % (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def keyword_line_changes(old: str, new: str) -> KeywordChanges:


def keyword_changes(ebuild1: str, ebuild2: str) -> Optional[KeywordChanges]:
with open(ebuild1) as e1, open(ebuild2) as e2:
with open(ebuild1, encoding="utf-8") as e1, open(ebuild2, encoding="utf-8") as e2:
lines1 = e1.readlines()
lines2 = e2.readlines()

Expand Down
3 changes: 1 addition & 2 deletions pym/gentoolkit/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@

import portage
from portage.util import LazyItemsDict
from portage import _encodings, _unicode_encode

import gentoolkit.pprinter as pp
from gentoolkit import errors
Expand Down Expand Up @@ -397,7 +396,7 @@ def size(self):
size = n_files = n_uncounted = 0
for path in self.parsed_contents(prefix_root=True):
try:
st = os.lstat(_unicode_encode(path, encoding=_encodings["fs"]))
st = os.lstat(path)
except OSError:
continue

Expand Down
8 changes: 1 addition & 7 deletions pym/gentoolkit/pprinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,6 @@ def warn(string):
return "!!! " + string + "\n"


try:
unicode
except NameError:
unicode = str


def uprint(*args, **kw):
"""Replacement for the builtin print function.

Expand Down Expand Up @@ -199,7 +193,7 @@ def encoded_args():
if isinstance(arg, bytes):
yield arg
else:
yield unicode(arg).encode(encoding, "replace")
yield str(arg).encode(encoding, "replace")

sep = sep.encode(encoding, "replace")
end = end.encode(encoding, "replace")
Expand Down
14 changes: 6 additions & 8 deletions pym/gentoolkit/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import portage
import sys

from portage import _encodings, _unicode_encode


def warning(msg):
"""Write |msg| as a warning to stderr"""
Expand Down Expand Up @@ -47,8 +45,8 @@ def load_profile_data(portdir=None, repo=""):
try:
arch_list = os.path.join(portdir, "profiles", "arch.list")
with open(
_unicode_encode(arch_list, encoding=_encodings["fs"]),
encoding=_encodings["content"],
arch_list,
encoding="utf-8",
) as f:
for line in f:
line = line.split("#", 1)[0].strip()
Expand All @@ -66,8 +64,8 @@ def load_profile_data(portdir=None, repo=""):
}
profiles_list = os.path.join(portdir, "profiles", "profiles.desc")
with open(
_unicode_encode(profiles_list, encoding=_encodings["fs"]),
encoding=_encodings["content"],
profiles_list,
encoding="utf-8",
) as f:
for line in f:
line = line.split("#", 1)[0].split()
Expand All @@ -91,8 +89,8 @@ def load_profile_data(portdir=None, repo=""):
try:
arches_list = os.path.join(portdir, "profiles", "arches.desc")
with open(
_unicode_encode(arches_list, encoding=_encodings["fs"]),
encoding=_encodings["content"],
arches_list,
encoding="utf-8",
) as f:
for line in f:
line = line.split("#", 1)[0].split()
Expand Down
5 changes: 2 additions & 3 deletions pym/gentoolkit/revdep_rebuild/analyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import re
import time

from portage import _encodings, _unicode_encode
from portage.output import bold, blue, yellow, green

from .stuff import scan
Expand Down Expand Up @@ -91,8 +90,8 @@ def extract_dependencies_from_la(la, libraries, to_check, logger):
continue

for line in open(
_unicode_encode(_file, encoding=_encodings["fs"]),
encoding=_encodings["content"],
_file,
encoding="utf-8",
).readlines():
line = line.strip()
if line.startswith("dependency_libs="):
Expand Down
25 changes: 9 additions & 16 deletions pym/gentoolkit/revdep_rebuild/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
Functions for reading, saving and verifying the data caches
"""

from portage import os
import os
import time

from portage import _encodings, _unicode_encode
from portage.output import red
from .settings import DEFAULTS

Expand All @@ -28,10 +27,8 @@ def read_cache(temp_path=DEFAULTS["DEFAULT_TMP_DIR"]):
try:
for key, val in ret.items():
_file = open(
_unicode_encode(
os.path.join(temp_path, key), encoding=_encodings["fs"]
),
encoding=_encodings["content"],
os.path.join(temp_path, key),
encoding="utf-8",
)
for line in _file.readlines():
val.add(line.strip())
Expand Down Expand Up @@ -60,22 +57,18 @@ def save_cache(logger, to_save={}, temp_path=DEFAULTS["DEFAULT_TMP_DIR"]):

try:
_file = open(
_unicode_encode(
os.path.join(temp_path, "timestamp"), encoding=_encodings["fs"]
),
os.path.join(temp_path, "timestamp"),
mode="w",
encoding=_encodings["content"],
encoding="utf-8",
)
_file.write(str(int(time.time())))
_file.close()

for key, val in to_save.items():
_file = open(
_unicode_encode(
os.path.join(temp_path, key), encoding=_encodings["fs"]
),
os.path.join(temp_path, key),
mode="w",
encoding=_encodings["content"],
encoding="utf-8",
)
for line in val:
_file.write(line + "\n")
Expand Down Expand Up @@ -105,8 +98,8 @@ def check_temp_files(

try:
_file = open(
_unicode_encode(timestamp_path, encoding=_encodings["fs"]),
encoding=_encodings["content"],
timestamp_path,
encoding="utf-8",
)
timestamp = int(_file.readline())
_file.close()
Expand Down
14 changes: 5 additions & 9 deletions pym/gentoolkit/revdep_rebuild/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
"""Data collection module"""

import re
from portage import os
import os
import glob
import stat

import portage
from portage import _encodings, _unicode_encode
from portage.output import blue, yellow
from .settings import parse_revdep_config

Expand All @@ -27,8 +26,8 @@ def parse_conf(conf_file, visited=None, logger=None):
for conf in conf_file:
try:
with open(
_unicode_encode(conf, encoding=_encodings["fs"]),
encoding=_encodings["content"],
conf,
encoding="utf-8",
) as _file:
for line in _file.readlines():
line = line.strip()
Expand Down Expand Up @@ -75,11 +74,8 @@ def prepare_search_dirs(logger, settings):

# try:
with open(
_unicode_encode(
os.path.join(portage.root, settings["DEFAULT_ENV_FILE"]),
encoding=_encodings["fs"],
),
encoding=_encodings["content"],
os.path.join(portage.root, settings["DEFAULT_ENV_FILE"]),
encoding="utf-8",
) as _file:
for line in _file.readlines():
line = line.strip()
Expand Down
7 changes: 2 additions & 5 deletions pym/gentoolkit/revdep_rebuild/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import glob

import portage
from portage import _encodings, _unicode_encode

portage_root = str(portage.root)

Expand Down Expand Up @@ -158,10 +157,8 @@ def parse_revdep_config(revdep_confdir):

for _file in os.listdir(revdep_confdir):
for line in open(
_unicode_encode(
os.path.join(revdep_confdir, _file), encoding=_encodings["fs"]
),
encoding=_encodings["content"],
os.path.join(revdep_confdir, _file),
encoding="utf-8",
):
line = line.strip()
# first check for comment, we do not want to regex all lines
Expand Down
5 changes: 2 additions & 3 deletions pym/gentoolkit/test/eclean/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import random

import gentoolkit.pprinter as pp
from portage import _encodings, _unicode_encode

__version__ = "0.0.1"
__author__ = "Brian Dolbec"
Expand Down Expand Up @@ -51,10 +50,10 @@ def make_dist(path, files, clean_dict=None):
data = "0" * size
filepath = os.path.join(path, file_)
with open(
_unicode_encode(filepath, encoding=_encodings["fs"]),
filepath,
"w",
file_mode,
encoding=_encodings["content"],
encoding="utf-8",
) as new_file:
new_file.write(data)
if file_ not in clean_dict:
Expand Down
Loading