Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use safer log parameters instead of interpolation #2248

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions fabric/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,11 @@ def _load_ssh_file(self, path):
with open(path) as fd:
self.base_ssh_config.parse(fd)
new_rules = len(self.base_ssh_config._config)
msg = "Loaded {} new ssh_config rules from {!r}"
debug(msg.format(new_rules - old_rules, path))
debug(
"Loaded %s new ssh_config rules from %r",
new_rules - old_rules,
path,
)
else:
debug("File not found, skipping")

Expand Down
4 changes: 2 additions & 2 deletions fabric/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def parameterize(self, call, connection_init_kwargs):
:returns:
`.ConnectionCall`.
"""
msg = "Parameterizing {!r} with Connection kwargs {!r}"
debug(msg.format(call, connection_init_kwargs))
msg = "Parameterizing %r with Connection kwargs %r"
debug(msg, call, connection_init_kwargs)
# Generate a custom ConnectionCall that has init_kwargs (used for
# creating the Connection at runtime) set to the requested params.
new_call_kwargs = dict(init_kwargs=connection_init_kwargs)
Expand Down
20 changes: 10 additions & 10 deletions fabric/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def put(self, local, remote=None, preserve_mode=True):
)
else:
remote = local_base
debug("Massaged empty remote path into {!r}".format(remote))
debug("Massaged empty remote path into %r", remote)
elif self.is_remote_dir(remote):
# non-empty local_base implies a) text file path or b) FLO which
# had a non-empty .name attribute. huzzah!
Expand All @@ -273,19 +273,19 @@ def put(self, local, remote=None, preserve_mode=True):
self.sftp.getcwd() or self.sftp.normalize("."), remote
)
if remote != prejoined_remote:
msg = "Massaged relative remote path {!r} into {!r}"
debug(msg.format(prejoined_remote, remote))
msg = "Massaged relative remote path %r into %r"
debug(msg, prejoined_remote, remote)

# Massage local path
orig_local = local
if not is_file_like:
local = os.path.abspath(local)
if local != orig_local:
debug(
"Massaged relative local path {!r} into {!r}".format(
orig_local, local
)
) # noqa
"Massaged relative local path %r into %r",
orig_local,
local,
)

# Run Paramiko-level .put() (side-effects only. womp.)
# TODO: push some of the path handling into Paramiko; it should be
Expand All @@ -295,16 +295,16 @@ def put(self, local, remote=None, preserve_mode=True):
#
# If local appears to be a file-like object, use sftp.putfo, not put
if is_file_like:
msg = "Uploading file-like object {!r} to {!r}"
debug(msg.format(local, remote))
msg = "Uploading file-like object %r to %r"
debug(msg, local, remote)
pointer = local.tell()
try:
local.seek(0)
self.sftp.putfo(fl=local, remotepath=remote)
finally:
local.seek(pointer)
else:
debug("Uploading {!r} to {!r}".format(local, remote))
debug("Uploading %r to %r", local, remote)
self.sftp.put(localpath=local, remotepath=remote)
# Set mode to same as local end
# TODO: Push this down into SFTPClient sometime (requires backwards
Expand Down
5 changes: 1 addition & 4 deletions fabric/util.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import logging
import sys


# Ape the half-assed logging junk from Invoke, but ensuring the logger reflects
# our name, not theirs. (Assume most contexts will rely on Invoke itself to
# literally enable/disable logging, for now.)
log = logging.getLogger("fabric")
for x in ("debug",):
globals()[x] = getattr(log, x)

debug = log.debug

win32 = sys.platform == "win32"

Expand Down