Unify string formatting

Use one way of string formatting: replace old `%` style with new `str.format`.

Resolve #855.
This commit is contained in:
Darko Poljak 2021-03-30 07:56:38 +02:00
commit 4c2d273f07
17 changed files with 67 additions and 65 deletions

View file

@ -152,7 +152,7 @@ class Local:
def _setup_object_marker_file(self):
with open(self.object_marker_file, 'w') as fd:
fd.write("%s\n" % self.object_marker_name)
fd.write("{}\n".format(self.object_marker_name))
self.log.trace("Object marker %s saved in %s",
self.object_marker_name, self.object_marker_file)
@ -184,7 +184,7 @@ class Local:
"""
assert isinstance(command, (list, tuple)), (
"list or tuple argument expected, got: %s" % command)
"list or tuple argument expected, got: {}".format(command))
quiet = self.quiet_mode or quiet_mode
do_save_output = save_output and not quiet and self.save_output_streams
@ -352,8 +352,9 @@ class Local:
try:
os.symlink(src, dst)
except OSError as e:
raise cdist.Error("Linking %s %s to %s failed: %s" % (
sub_dir, src, dst, e.__str__()))
raise cdist.Error(
"Linking {} {} to {} failed: {}".format(
sub_dir, src, dst, e.__str__()))
def _link_types_for_emulator(self):
"""Link emulator to types"""
@ -366,5 +367,5 @@ class Local:
os.symlink(src, dst)
except OSError as e:
raise cdist.Error(
"Linking emulator from %s to %s failed: %s" % (
"Linking emulator from {} to {} failed: {}".format(
src, dst, e.__str__()))

View file

@ -24,12 +24,10 @@ import os
import glob
import subprocess
import logging
import multiprocessing
import cdist
import cdist.exec.util as util
import cdist.util.ipaddr as ipaddr
from cdist.mputil import mp_pool_run
def _wrap_addr(addr):
@ -262,9 +260,10 @@ class Remote:
# remotely in e.g. csh and setting up CDIST_REMOTE_SHELL to e.g.
# /bin/csh will execute this script in the right way.
if env:
remote_env = [" export %s=%s;" % item for item in env.items()]
string_cmd = ("/bin/sh -c '" + " ".join(remote_env) +
" ".join(command) + "'")
remote_env = [" export {env[0]}={env[1]};".format(env=item)
for item in env.items()]
string_cmd = ("/bin/sh -c '{}{}'").format(" ".join(remote_env),
" ".join(command))
cmd.append(string_cmd)
else:
cmd.extend(command)
@ -278,7 +277,7 @@ class Remote:
"""
assert isinstance(command, (list, tuple)), (
"list or tuple argument expected, got: %s" % command)
"list or tuple argument expected, got: {}".format(command))
close_stdout = False
close_stderr = False