Skip to content

Commit a2214e0

Browse files
author
Juliya Smith
authored
Fstrs everywhere (#292)
1 parent a7a521f commit a2214e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+260
-364
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ repos:
33
rev: v2.7.1
44
hooks:
55
- id: pyupgrade
6-
args: ["--py3-plus"]
6+
args: ["--py36-plus"]
77
- repo: https://github.com/asottile/reorder_python_imports
88
rev: v2.3.0
99
hooks:

docs/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
author = "Code42 Software"
2424

2525
# The short X.Y version
26-
version = "code42cli v{}".format(meta.__version__)
26+
version = f"code42cli v{meta.__version__}"
2727
# The full version, including alpha/beta/rc tags
28-
release = "code42cli v{}".format(meta.__version__)
28+
release = f"code42cli v{meta.__version__}"
2929

3030

3131
# -- General configuration ---------------------------------------------------

src/code42cli/bulk.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ def write_template_file(path, columns=None, flat_item=None):
2323
new_file.write(",".join(columns))
2424
else:
2525
new_file.write(
26-
"# This template takes a single {} to be processed on each row.".format(
27-
flat_item or "item"
28-
)
26+
f"# This template takes a single {flat_item or 'item'} to be processed on each row."
2927
)
3028

3129

@@ -58,7 +56,7 @@ def generate_template_cmd_factory(group_name, commands_dict, help_message=None):
5856
def generate_template(cmd, path):
5957
columns = commands_dict[cmd]
6058
if not path:
61-
filename = "{}_bulk_{}.csv".format(group_name, cmd.replace("-", "_"))
59+
filename = f"{group_name}_bulk_{cmd.replace('-', '_')}.csv"
6260
path = os.path.join(os.getcwd(), filename)
6361
if isinstance(columns, str):
6462
write_template_file(path, columns=None, flat_item=columns)

src/code42cli/click_ext/groups.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ def _suggest_cmd(usage_err):
102102
)
103103
if not suggested_commands:
104104
raise usage_err
105-
usage_err.message = "No such command '{}'. Did you mean {}?".format(
106-
bad_arg, " or ".join(suggested_commands)
105+
usage_err.message = (
106+
f"No such command '{bad_arg}'. "
107+
f"Did you mean {' or '.join(suggested_commands)}?"
107108
)
108109
raise usage_err
109110

src/code42cli/click_ext/options.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def handle_parse_result(self, ctx, opts, args):
1818
if ctx.obj is not None:
1919
found_incompatible = ", ".join(
2020
[
21-
"--{}".format(opt.replace("_", "-"))
21+
f"--{opt.replace('_', '-')}"
2222
for opt in opts
2323
if opt in incompatible_opts
2424
]
@@ -27,9 +27,7 @@ def handle_parse_result(self, ctx, opts, args):
2727
name = self.name.replace("_", "-")
2828
raise click.BadOptionUsage(
2929
option_name=self.name,
30-
message="--{} can't be used with: {}".format(
31-
name, found_incompatible
32-
),
30+
message=f"--{name} can't be used with: {found_incompatible}",
3331
)
3432
return super().handle_parse_result(ctx, opts, args)
3533

src/code42cli/click_ext/types.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ def _get_dt_from_magic_time_pair(num, period):
115115
elif period == "m":
116116
delta = timedelta(minutes=num)
117117
else:
118-
raise BadParameter(
119-
"Couldn't parse magic time string: {}{}".format(num, period)
120-
)
118+
raise BadParameter(f"Couldn't parse magic time string: {num}{period}")
121119
return datetime.utcnow() - delta
122120

123121
@staticmethod
@@ -127,11 +125,11 @@ def _get_dt_from_date_time_pair(date, time):
127125
time = "{}:{}:{}".format(*time.split(":") + ["00", "00"])
128126
else:
129127
time = "00:00:00"
130-
date_string = "{} {}".format(date, time)
128+
date_string = f"{date} {time}"
131129
try:
132130
dt = datetime.strptime(date_string, date_format)
133131
except ValueError:
134-
raise BadParameter("Unable to parse date string: {}.".format(date_string))
132+
raise BadParameter(f"Unable to parse date string: {date_string}.")
135133
else:
136134
return dt
137135

src/code42cli/cmds/alert_rules.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def remove_user(state, rule_id, username):
7373
_remove_user(state.sdk, rule_id, username)
7474
except Py42BadRequestError:
7575
raise Code42CLIError(
76-
"User {} is not currently assigned to rule-id {}.".format(username, rule_id)
76+
f"User {username} is not currently assigned to rule-id {rule_id}."
7777
)
7878

7979

@@ -118,9 +118,8 @@ def bulk(state):
118118

119119

120120
@bulk.command(
121-
help="Bulk add users to alert rules from a CSV file. CSV file format: {}".format(
122-
",".join(ALERT_RULES_CSV_HEADERS)
123-
)
121+
help=f"Bulk add users to alert rules from a CSV file. "
122+
f"CSV file format: {','.join(ALERT_RULES_CSV_HEADERS)}"
124123
)
125124
@read_csv_arg(headers=ALERT_RULES_CSV_HEADERS)
126125
@sdk_options()
@@ -136,9 +135,8 @@ def handle_row(rule_id, username):
136135

137136

138137
@bulk.command(
139-
help="Bulk remove users from alert rules using a CSV file. CSV file format: {}".format(
140-
",".join(ALERT_RULES_CSV_HEADERS)
141-
)
138+
help="Bulk remove users from alert rules using a CSV file. "
139+
"CSV file format: {','.join(ALERT_RULES_CSV_HEADERS)}"
142140
)
143141
@read_csv_arg(headers=ALERT_RULES_CSV_HEADERS)
144142
@sdk_options()
@@ -182,8 +180,8 @@ def _get_rule_metadata(sdk, rule_id):
182180

183181
def _handle_rules_results(rules, rule_id=None):
184182
if not rules:
185-
id_msg = "with RuleId {} ".format(rule_id) if rule_id else ""
186-
msg = "No alert rules {}found.".format(id_msg)
183+
id_msg = f"with RuleId {rule_id} " if rule_id else ""
184+
msg = f"No alert rules {id_msg}found."
187185
raise Code42CLIError(msg)
188186
return rules
189187

@@ -198,5 +196,5 @@ def _get_rule_type_func(sdk, rule_type):
198196
else:
199197
raise Code42CLIError(
200198
"Received an unknown rule type from server. You might need to update "
201-
"to a newer version of {}".format(PRODUCT_NAME)
199+
f"to a newer version of {PRODUCT_NAME}"
202200
)

src/code42cli/cmds/cases.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def show(state, case_number, format, include_file_events):
193193
events = _get_file_events(state.sdk, case_number)
194194
_display_file_events(events)
195195
except Py42NotFoundError:
196-
raise Code42CLIError("Invalid case-number {}.".format(case_number))
196+
raise Code42CLIError(f"Invalid case-number {case_number}.")
197197

198198

199199
@cases.command()
@@ -207,7 +207,7 @@ def show(state, case_number, format, include_file_events):
207207
def export(state, case_number, path):
208208
"""Download a case detail summary as a PDF file at the given path with name <case_number>_case_summary.pdf."""
209209
response = state.sdk.cases.export_summary(case_number)
210-
file = os.path.join(path, "{}_case_summary.pdf".format(case_number))
210+
file = os.path.join(path, f"{case_number}_case_summary.pdf")
211211
with open(file, "wb") as f:
212212
f.write(response.content)
213213

src/code42cli/cmds/departing_employee.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _get_filter_choices():
2828
DATE_FORMAT = "%Y-%m-%d"
2929
filter_option = click.option(
3030
"--filter",
31-
help="Departing employee filter options. Defaults to {}.".format(ALL_FILTER),
31+
help=f"Departing employee filter options. Defaults to {ALL_FILTER}.",
3232
type=click.Choice(_get_filter_choices()),
3333
default=ALL_FILTER,
3434
callback=lambda ctx, param, arg: handle_filter_choice(arg),
@@ -96,7 +96,7 @@ def bulk(state):
9696
@bulk.command(
9797
name="add",
9898
help="Bulk add users to the Departing Employees detection list using a CSV file with "
99-
"format: {}.".format(",".join(DEPARTING_EMPLOYEE_CSV_HEADERS)),
99+
f"format: {','.join(DEPARTING_EMPLOYEE_CSV_HEADERS)}.",
100100
)
101101
@read_csv_arg(headers=DEPARTING_EMPLOYEE_CSV_HEADERS)
102102
@sdk_options()

src/code42cli/cmds/devices.py

+9-15
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ def _deactivate_device(sdk, device_guid, change_device_name, purge_date):
8383
try:
8484
device = _change_device_activation(sdk, device_guid, "deactivate")
8585
except exceptions.Py42BadRequestError:
86-
raise Code42CLIError(
87-
"The device with GUID '{}' is in legal hold.".format(device_guid)
88-
)
86+
raise Code42CLIError(f"The device with GUID '{device_guid}' is in legal hold.")
8987
if purge_date:
9088
_update_cold_storage_purge_date(sdk, device_guid, purge_date)
9189
if change_device_name and not device.data["name"].startswith("deactivated_"):
@@ -113,12 +111,10 @@ def _change_device_activation(sdk, device_guid, cmd_str):
113111
sdk.devices.deactivate(device_id)
114112
return device
115113
except exceptions.Py42NotFoundError:
116-
raise Code42CLIError(
117-
"The device with GUID '{}' was not found.".format(device_guid)
118-
)
114+
raise Code42CLIError(f"The device with GUID '{device_guid}' was not found.")
119115
except exceptions.Py42ForbiddenError:
120116
raise Code42CLIError(
121-
"Unable to {} the device with GUID '{}'.".format(cmd_str, device_guid)
117+
f"Unable to {cmd_str} the device with GUID '{device_guid}'."
122118
)
123119

124120

@@ -509,14 +505,12 @@ def _add_backup_set_settings_to_dataframe(sdk, devices_dataframe):
509505
def handle_row(guid):
510506
try:
511507
current_device_settings = sdk.devices.get_settings(guid)
512-
except Exception as e:
508+
except Exception as err:
513509
return DataFrame.from_records(
514510
[
515511
{
516512
"guid": guid,
517-
"ERROR": "Unable to retrieve device settings for {}: {}".format(
518-
guid, e
519-
),
513+
"ERROR": f"Unable to retrieve device settings for {guid}: {err}",
520514
}
521515
]
522516
)
@@ -591,8 +585,8 @@ def handle_row(**row):
591585
sdk, row["guid"], row["change_device_name"], row["purge_date"]
592586
)
593587
row["deactivated"] = "True"
594-
except Exception as e:
595-
row["deactivated"] = "False: {}".format(e)
588+
except Exception as err:
589+
row["deactivated"] = f"False: {err}"
596590
return row
597591

598592
result_rows = run_bulk_process(
@@ -615,8 +609,8 @@ def handle_row(**row):
615609
try:
616610
_reactivate_device(sdk, row["guid"])
617611
row["reactivated"] = "True"
618-
except Exception as e:
619-
row["reactivated"] = "False: {}".format(e)
612+
except Exception as err:
613+
row["reactivated"] = f"False: {err}"
620614
return row
621615

622616
result_rows = run_bulk_process(

src/code42cli/cmds/high_risk_employee.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _get_filter_choices():
3030

3131
filter_option = click.option(
3232
"--filter",
33-
help="High risk employee filter options. Defaults to {}.".format(ALL_FILTER),
33+
help=f"High risk employee filter options. Defaults to {ALL_FILTER}.",
3434
type=click.Choice(_get_filter_choices()),
3535
default=ALL_FILTER,
3636
callback=lambda ctx, param, arg: handle_filter_choice(arg),
@@ -126,7 +126,7 @@ def bulk(state):
126126
@bulk.command(
127127
name="add",
128128
help="Bulk add users to the high risk employees detection list using a CSV file with "
129-
"format: {}.".format(",".join(HIGH_RISK_EMPLOYEE_CSV_HEADERS)),
129+
f"format: {','.join(HIGH_RISK_EMPLOYEE_CSV_HEADERS)}.",
130130
)
131131
@read_csv_arg(headers=HIGH_RISK_EMPLOYEE_CSV_HEADERS)
132132
@sdk_options()
@@ -165,9 +165,8 @@ def handle_row(username):
165165

166166
@bulk.command(
167167
name="add-risk-tags",
168-
help="Adds risk tags to users in bulk using a CSV file with format: {}.".format(
169-
",".join(RISK_TAG_CSV_HEADERS)
170-
),
168+
help=f"Adds risk tags to users in bulk using a CSV file with format: "
169+
f"{','.join(RISK_TAG_CSV_HEADERS)}.",
171170
)
172171
@read_csv_arg(headers=RISK_TAG_CSV_HEADERS)
173172
@sdk_options()
@@ -184,9 +183,8 @@ def handle_row(username, tag):
184183

185184
@bulk.command(
186185
name="remove-risk-tags",
187-
help="Removes risk tags from users in bulk using a CSV file with format: {}.".format(
188-
",".join(RISK_TAG_CSV_HEADERS)
189-
),
186+
help=f"Removes risk tags from users in bulk using a CSV file with format: "
187+
f"{','.join(RISK_TAG_CSV_HEADERS)}.",
190188
)
191189
@read_csv_arg(headers=RISK_TAG_CSV_HEADERS)
192190
@sdk_options()

src/code42cli/cmds/legal_hold.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,8 @@ def bulk(state):
190190

191191
@bulk.command(
192192
name="add",
193-
help="Bulk add custodians to legal hold matters using a CSV file. CSV file format: {}".format(
194-
",".join(LEGAL_HOLD_CSV_HEADERS)
195-
),
193+
help=f"Bulk add custodians to legal hold matters using a CSV file. "
194+
f"CSV file format: {','.join(LEGAL_HOLD_CSV_HEADERS)}",
196195
)
197196
@read_csv_arg(headers=LEGAL_HOLD_CSV_HEADERS)
198197
@sdk_options()
@@ -206,9 +205,8 @@ def handle_row(matter_id, username):
206205

207206

208207
@bulk.command(
209-
help="Bulk release custodians from legal hold matters using a CSV file. CSV file format: {}".format(
210-
",".join(LEGAL_HOLD_CSV_HEADERS)
211-
)
208+
help=f"Bulk release custodians from legal hold matters using a CSV file. "
209+
f"CSV file format: {','.join(LEGAL_HOLD_CSV_HEADERS)}"
212210
)
213211
@read_csv_arg(headers=LEGAL_HOLD_CSV_HEADERS)
214212
@sdk_options()
@@ -287,10 +285,10 @@ def _get_all_events(sdk, legal_hold_uid, begin_date, end_date):
287285

288286
def _print_matter_members(username_list, member_type="active"):
289287
if username_list:
290-
echo("\n{} matter members:\n".format(member_type.capitalize()))
288+
echo(f"\n{member_type.capitalize()} matter members:\n")
291289
format_string_list_to_columns(username_list)
292290
else:
293-
echo("No {} matter members.\n".format(member_type))
291+
echo(f"No {member_type} matter members.\n")
294292

295293

296294
@lru_cache(maxsize=None)

0 commit comments

Comments
 (0)