Skip to content

Commit 6463ad6

Browse files
committed
Improve formatting in display_debug_info function
1 parent 60255b3 commit 6463ad6

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/borg/helpers/passphrase.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def verification(cls, passphrase):
111111
env_var_override="BORG_DISPLAY_PASSPHRASE",
112112
):
113113
pw_msg = textwrap.dedent(
114-
f"""
114+
f"""\
115115
Your passphrase (between double-quotes): "{passphrase}"
116116
Make sure the passphrase displayed above is exactly what you wanted.
117117
Your passphrase (UTF-8 encoding in hex): {bin_to_hex(passphrase.encode("utf-8"))}
@@ -123,20 +123,24 @@ def verification(cls, passphrase):
123123

124124
@staticmethod
125125
def display_debug_info(passphrase):
126+
def fmt_var(env_var):
127+
env_var_value = os.environ.get(env_var)
128+
if env_var_value is not None:
129+
return f'{env_var} = "{env_var_value}"'
130+
else:
131+
return f"# {env_var} is not set"
132+
126133
if os.environ.get("BORG_DEBUG_PASSPHRASE") == "YES":
127-
env_vars_str = ""
128-
for env_var in ["BORG_PASSPHRASE", "BORG_PASSCOMMAND", "BORG_PASSPHRASE_FD"]:
129-
env_var_value = os.environ.get(env_var)
130-
if env_var_value is not None:
131-
env_vars_str += f'{env_var} = "{env_var_value}"\n'
132-
else:
133-
env_vars_str += f"# {env_var} is not set\n"
134-
passphrase_info = (
135-
f"Incorrect passphrase!\n"
136-
f'Passphrase used (between double-quotes): "{passphrase}"\n'
137-
f"Same, UTF-8 encoded, in hex: {bin_to_hex(passphrase.encode('utf-8'))}\n"
138-
f"Relevant Environment Variables:\n"
139-
f"{env_vars_str}"
134+
passphrase_info = textwrap.dedent(
135+
f"""\
136+
Incorrect passphrase!
137+
Passphrase used (between double-quotes): "{passphrase}"
138+
Same, UTF-8 encoded, in hex: {bin_to_hex(passphrase.encode('utf-8'))}
139+
Relevant Environment Variables:
140+
{fmt_var("BORG_PASSPHRASE")}
141+
{fmt_var("BORG_PASSCOMMAND")}
142+
{fmt_var("BORG_PASSPHRASE_FD")}
143+
"""
140144
)
141145
print(passphrase_info, file=sys.stderr)
142146

0 commit comments

Comments
 (0)