Skip to content

Commit

Permalink
Convert %-formats to fstrings
Browse files Browse the repository at this point in the history
Files under lib/_emerge

Signed-off-by: Oskari Pirhonen <[email protected]>
Closes: #1013
Signed-off-by: Sam James <[email protected]>
  • Loading branch information
xxc3nsoredxx authored and thesamesam committed Apr 30, 2023
1 parent 2202207 commit 0b21a5a
Show file tree
Hide file tree
Showing 24 changed files with 271 additions and 425 deletions.
64 changes: 28 additions & 36 deletions lib/_emerge/AbstractEbuildProcess.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from _emerge.EbuildIpcDaemon import EbuildIpcDaemon
import portage
from portage.elog import messages as elog_messages
from portage.localization import _
from portage.package.ebuild._ipc.ExitCommand import ExitCommand
from portage.package.ebuild._ipc.QueryCommand import QueryCommand
from portage import os
Expand Down Expand Up @@ -72,10 +71,10 @@ def _start(self):
# die_hooks for some reason, and PORTAGE_BUILDDIR
# doesn't exist yet.
if need_builddir and not os.path.isdir(self.settings["PORTAGE_BUILDDIR"]):
msg = _(
"The ebuild phase '%s' has been aborted "
"since PORTAGE_BUILDDIR does not exist: '%s'"
) % (self.phase, self.settings["PORTAGE_BUILDDIR"])
msg = (
f"The ebuild phase '{self.phase}' has been aborted since "
f"PORTAGE_BUILDDIR does not exist: '{self.settings['PORTAGE_BUILDDIR']}'"
)
self._eerror(textwrap.wrap(msg, 72))
self.returncode = 1
self._async_wait()
Expand Down Expand Up @@ -326,11 +325,10 @@ def _cancel_timeout_cb(self):
def _orphan_process_warn(self):
phase = self.phase

msg = _(
"The ebuild phase '%s' with pid %s appears "
"to have left an orphan process running in the "
"background."
) % (phase, self.pid)
msg = (
f"The ebuild phase '{phase}' with pid {self.pid} appears "
"to have left an orphan process running in the background."
)

self._eerror(textwrap.wrap(msg, 72))

Expand All @@ -346,38 +344,32 @@ def _can_log(self, slave_fd):
) or os.isatty(slave_fd)

def _killed_by_signal(self, signum):
msg = _("The ebuild phase '%s' has been " "killed by signal %s.") % (
self.phase,
signum,
)
msg = f"The ebuild phase '{self.phase}' has been killed by signal {signum}."
self._eerror(textwrap.wrap(msg, 72))

def _unexpected_exit(self):
phase = self.phase

msg = (
_(
"The ebuild phase '%s' has exited "
"unexpectedly. This type of behavior "
"is known to be triggered "
"by things such as failed variable "
"assignments (bug #190128) or bad substitution "
"errors (bug #200313). Normally, before exiting, bash should "
"have displayed an error message above. If bash did not "
"produce an error message above, it's possible "
"that the ebuild has called `exit` when it "
"should have called `die` instead. This behavior may also "
"be triggered by a corrupt bash binary or a hardware "
"problem such as memory or cpu malfunction. If the problem is not "
"reproducible or it appears to occur randomly, then it is likely "
"to be triggered by a hardware problem. "
"If you suspect a hardware problem then you should "
"try some basic hardware diagnostics such as memtest. "
"Please do not report this as a bug unless it is consistently "
"reproducible and you are sure that your bash binary and hardware "
"are functioning properly."
)
% phase
f"The ebuild phase '{phase}' has exited "
"unexpectedly. This type of behavior "
"is known to be triggered "
"by things such as failed variable "
"assignments (bug #190128) or bad substitution "
"errors (bug #200313). Normally, before exiting, bash should "
"have displayed an error message above. If bash did not "
"produce an error message above, it's possible "
"that the ebuild has called `exit` when it "
"should have called `die` instead. This behavior may also "
"be triggered by a corrupt bash binary or a hardware "
"problem such as memory or cpu malfunction. If the problem is not "
"reproducible or it appears to occur randomly, then it is likely "
"to be triggered by a hardware problem. "
"If you suspect a hardware problem then you should "
"try some basic hardware diagnostics such as memtest. "
"Please do not report this as a bug unless it is consistently "
"reproducible and you are sure that your bash binary and hardware "
"are functioning properly."
)

self._eerror(textwrap.wrap(msg, 72))
Expand Down
5 changes: 1 addition & 4 deletions lib/_emerge/AsynchronousLock.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import portage
from portage import os
from portage.exception import TryAgain
from portage.localization import _
from portage.locks import lockfile, unlockfile
from portage.util import writemsg_level
from _emerge.AbstractPollTask import AbstractPollTask
Expand Down Expand Up @@ -244,9 +243,7 @@ def _proc_exit(self, proc):
# this failure appropriately.
if not (self.cancelled or self._kill_test):
writemsg_level(
"_LockProcess: %s\n"
% _("failed to acquire lock on '%s'")
% (self.path,),
"_LockProcess: failed to acquire lock on '{self.path}'\n",
level=logging.ERROR,
noiselevel=-1,
)
Expand Down
5 changes: 1 addition & 4 deletions lib/_emerge/BinpkgEnvExtractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ def _get_dest_env_path(self):
def _start(self):
saved_env_path = self._get_saved_env_path()
dest_env_path = self._get_dest_env_path()
shell_cmd = (
"${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} -c -- %s > %s"
% (_shell_quote(saved_env_path), _shell_quote(dest_env_path))
)
shell_cmd = f"${{PORTAGE_BUNZIP2_COMMAND:-${{PORTAGE_BZIP2_COMMAND}} -d}} -c -- {_shell_quote(saved_env_path)} > {_shell_quote(dest_env_path)}"

logfile = None
if self.settings.get("PORTAGE_BACKGROUND") != "subprocess":
Expand Down
60 changes: 28 additions & 32 deletions lib/_emerge/BinpkgExtractorAsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from _emerge.SpawnProcess import SpawnProcess
import portage
from portage.localization import _
from portage.util.compression_probe import (
compression_probe,
_compressors,
Expand All @@ -21,6 +20,7 @@
import signal
import subprocess
import tarfile
import textwrap


class BinpkgExtractorAsync(SpawnProcess):
Expand Down Expand Up @@ -72,9 +72,7 @@ def _xpak_start(self):
decomp_cmd = None
if decomp_cmd is None:
self.scheduler.output(
"!!! %s\n"
% _("File compression header unrecognized: %s")
% self.pkg_path,
f"!!! File compression header unrecognized: {self.pkg_path}\n",
log_path=self.logfile,
background=self.background,
level=logging.ERROR,
Expand Down Expand Up @@ -104,15 +102,9 @@ def _xpak_start(self):
if find_binary(decompression_binary) is None:
missing_package = decomp.get("package")
self.scheduler.output(
"!!! %s\n"
% _(
"File compression unsupported %s.\n Command was: %s.\n Maybe missing package: %s"
)
% (
self.pkg_path,
varexpand(decomp_cmd, mydict=self.env),
missing_package,
),
f"!!! File compression unsupported {self.pkg_path}.\n"
f" Command was: {varexpand(decomp_cmd, mydict=self.env)}.\n"
f" Missing package: {missing_package}\n",
log_path=self.logfile,
background=self.background,
level=logging.ERROR,
Expand All @@ -129,26 +121,30 @@ def _xpak_start(self):
self.args = [
self._shell_binary,
"-c",
(
"cmd0=(head -c %d -- %s) cmd1=(%s) cmd2=(tar -xp %s -C %s -f -); "
+ '"${cmd0[@]}" | "${cmd1[@]}" | "${cmd2[@]}"; '
+ "p=(${PIPESTATUS[@]}) ; for i in {0..2}; do "
+ "if [[ ${p[$i]} != 0 && ${p[$i]} != %d ]] ; then "
+ 'echo command $(eval "echo \\"\'\\${cmd$i[*]}\'\\"") '
+ "failed with status ${p[$i]} ; exit ${p[$i]} ; fi ; done; "
+ "if [ ${p[$i]} != 0 ] ; then "
+ 'echo command $(eval "echo \\"\'\\${cmd$i[*]}\'\\"") '
+ "failed with status ${p[$i]} ; exit ${p[$i]} ; fi ; "
+ "exit 0 ;"
textwrap.dedent(
f"""
cmd0=(head -c {pkg_xpak.filestat.st_size - pkg_xpak.xpaksize} -- {portage._shell_quote(self.pkg_path)})
cmd1=({decomp_cmd})
cmd2=(tar -xp {tar_options} -C {portage._shell_quote(self.image_dir)} -f -);
"""
"""
"${cmd0[@]}" | "${cmd1[@]}" | "${cmd2[@]}";
p=(${PIPESTATUS[@]}) ; for i in {0..2}; do
"""
f"""
if [[ ${{p[$i]}} != 0 && ${{p[$i]}} != {128 + signal.SIGPIPE} ]] ; then
"""
"""
echo command $(eval "echo \\"'\\${cmd$i[*]}'\\"") failed with status ${p[$i]} ;
exit ${p[$i]} ; fi ; done;
if [ ${p[$i]} != 0 ] ; then
echo command $(eval "echo \\"'\\${cmd$i[*]}'\\"") failed with status ${p[$i]} ;
exit ${p[$i]} ; fi ;
exit 0 ;
"""
)
% (
pkg_xpak.filestat.st_size - pkg_xpak.xpaksize,
portage._shell_quote(self.pkg_path),
decomp_cmd,
tar_options,
portage._shell_quote(self.image_dir),
128 + signal.SIGPIPE,
),
.replace("\n", " ")
.strip(),
]

SpawnProcess._start(self)
3 changes: 1 addition & 2 deletions lib/_emerge/BinpkgFetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,7 @@ def acquired_lock(async_lock):
else:
result.set_exception(
AssertionError(
"AsynchronousLock failed with returncode %s"
% (async_lock.returncode,)
f"AsynchronousLock failed with returncode {async_lock.returncode}"
)
)

Expand Down
17 changes: 7 additions & 10 deletions lib/_emerge/BinpkgVerifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _start(self):
if e.errno not in (errno.ENOENT, errno.ESTALE):
raise
self.scheduler.output(
("!!! Fetching Binary failed " "for '%s'\n") % self.pkg.cpv,
f"!!! Fetching Binary failed for '{self.pkg.cpv}'\n",
log_path=self.logfile,
background=self.background,
)
Expand Down Expand Up @@ -123,15 +123,12 @@ def _digest_exception(self, name, value, expected):
)

self.scheduler.output(
(
"\n!!! Digest verification failed:\n"
"!!! %s\n"
"!!! Reason: Failed on %s verification\n"
"!!! Got: %s\n"
"!!! Expected: %s\n"
"File renamed to '%s'\n"
)
% (self._pkg_path, name, value, expected, temp_filename),
"\n!!! Digest verification failed:\n"
f"!!! {self._pkg_path}\n"
f"!!! Reason: Failed on {name} verification\n"
f"!!! Got: {value}\n"
f"!!! Expected: {expected}\n"
f"File renamed to '{temp_filename}'\n",
log_path=self.logfile,
background=self.background,
)
8 changes: 4 additions & 4 deletions lib/_emerge/EbuildMerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ def _merge_exit(self, merge_task):
pkg.cpv,
)
logger.log(
(" === (%s of %s) " + "Post-Build Cleaning (%s::%s)")
% (pkg_count.curval, pkg_count.maxval, pkg.cpv, pkg_path),
f" === ({pkg_count.curval} of {pkg_count.maxval}) "
f"Post-Build Cleaning ({pkg.cpv}::{pkg_path})",
short_msg=short_msg,
)
logger.log(
" ::: completed emerge (%s of %s) %s to %s"
% (pkg_count.curval, pkg_count.maxval, pkg.cpv, pkg.root)
f" ::: completed emerge ({pkg_count.curval} of {pkg_count.maxval}) "
f"{pkg.cpv} to {pkg.root}"
)

self._start_exit_hook(self.returncode)
Expand Down
8 changes: 3 additions & 5 deletions lib/_emerge/JobStatusDisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,11 @@ def _load_avg_str(self):
max_avg = max(avg)

if max_avg < 10:
digits = 2
return ", ".join(f"{x:.2f}" for x in avg)
elif max_avg < 100:
digits = 1
return ", ".join(f"{x:.1f}" for x in avg)
else:
digits = 0

return ", ".join(("%%.%df" % digits) % x for x in avg)
return ", ".join(f"{x:.0f}" for x in avg)

def display(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions lib/_emerge/MergeListItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def _start(self):
if not build_opts.pretend:
self.statusMessage(msg)
logger.log(
" >>> emerge (%s of %s) %s to %s"
% (pkg_count.curval, pkg_count.maxval, pkg.cpv, pkg.root)
f" >>> emerge ({pkg_count.curval} of {pkg_count.maxval}) "
f"{pkg.cpv} to {pkg.root}"
)

if pkg.type_name == "ebuild":
Expand Down
8 changes: 2 additions & 6 deletions lib/_emerge/Package.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from portage.versions import _pkg_str, _unknown_repo
from portage.eapi import _get_eapi_attrs
from portage.exception import InvalidData, InvalidDependString
from portage.localization import _
from _emerge.Task import Task


Expand Down Expand Up @@ -344,11 +343,8 @@ def _validate_deps(self):
continue
if atom.slot_operator_built:
e = InvalidDependString(
_(
"Improper context for slot-operator "
'"built" atom syntax: %s'
)
% (atom.unevaluated_atom,)
'Improper context for slot-operator "built" '
f"atom syntax: {atom.unevaluated_atom}"
)
self._metadata_exception(k, e)

Expand Down
6 changes: 3 additions & 3 deletions lib/_emerge/Scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2218,11 +2218,11 @@ def _world_atom(self, pkg):
if atom is not None:
if hasattr(world_set, "add"):
self._status_msg(
('Recording %s in "world" ' + "favorites file...") % atom
f'Recording {atom} in "world" favorites file...'
)
logger.log(
" === (%s of %s) Updating world file (%s)"
% (pkg_count.curval, pkg_count.maxval, pkg.cpv)
f" === ({pkg_count.curval} of {pkg_count.maxval}) "
f"Updating world file ({pkg.cpv})"
)
world_set.add(atom)
else:
Expand Down
11 changes: 4 additions & 7 deletions lib/_emerge/SpawnProcess.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import portage
from portage import os
from portage.const import BASH_BINARY
from portage.localization import _
from portage.output import EOutput
from portage.util import writemsg_level
from portage.util._async.BuildLogger import BuildLogger
Expand Down Expand Up @@ -271,7 +270,7 @@ def kill_all(pids, sig):
if e.errno == errno.EPERM:
# Reported with hardened kernel (bug #358211).
writemsg_level(
"!!! kill: (%i) - Operation not permitted\n" % (p,),
f"!!! kill: ({p}) - Operation not permitted\n",
level=logging.ERROR,
noiselevel=-1,
)
Expand All @@ -291,11 +290,9 @@ def kill_all(pids, sig):
if pids:
msg = []
msg.append(
_("Failed to kill pid(s) in '%(cgroup)s': %(pids)s")
% dict(
cgroup=os.path.join(self.cgroup, "cgroup.procs"),
pids=" ".join(str(pid) for pid in pids),
)
"Failed to kill pid(s) in "
f"'{os.path.join(self.cgroup, 'cgroup.procs')}': "
f"{' '.join(str(pid) for pid in pids)}"
)

self._elog("eerror", msg)
Expand Down
2 changes: 1 addition & 1 deletion lib/_emerge/SubProcess.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _cancel(self):
if e.errno == errno.EPERM:
# Reported with hardened kernel (bug #358211).
writemsg_level(
"!!! kill: (%i) - Operation not permitted\n" % (self.pid,),
f"!!! kill: ({self.pid}) - Operation not permitted\n",
level=logging.ERROR,
noiselevel=-1,
)
Expand Down
Loading

0 comments on commit 0b21a5a

Please sign in to comment.