Skip to content

Commit d399583

Browse files
matmaciejemkopec
authored andcommitted
osfv_cli: string literals breaking fixed, source limited to 80 cols
Literals breaking with backslash fixed, string literals and comments limited to 80 columns, remaining black autoformatter hints applied. Signed-off-by: Mateusz Maciejewski <[email protected]>
1 parent 3ed3dd3 commit d399583

File tree

8 files changed

+117
-61
lines changed

8 files changed

+117
-61
lines changed

osfv_cli/src/osfv/cli/cli.py

+45-25
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def check_out_asset(snipeit_api, asset_id):
2929
print(f"Error checking out asset {asset_id}")
3030
print(f"Response data: {data}")
3131
exit(
32-
f"Exiting to avoid conflict. Check who is working on this device and contact them first."
32+
f"Exiting to avoid conflict. Check who is working on this device"
33+
f" and contact them first."
3334
)
3435

3536
return already_checked_out
@@ -93,7 +94,8 @@ def list_my_assets(snipeit_api, args):
9394
9495
Args:
9596
snipeit_api: The API client used to interact with the Snipe-IT API.
96-
args: Command-line arguments object which contains the following attributes:
97+
args: Command-line arguments object which contains the following
98+
attributes:
9799
- json: A boolean indicating to output the list as json.
98100
Returns:
99101
Boolean: False if no assets were assigned to the user, True otherwise
@@ -119,7 +121,8 @@ def check_in_my(snipeit_api, args):
119121
120122
Args:
121123
snipeit_api: The API client used to interact with the Snipe-IT API.
122-
args: Command-line arguments object which contains the following attributes:
124+
args: Command-line arguments object which contains the following
125+
attributes:
123126
- yes: A boolean indicating to skip the confirmation prompt.
124127
Returns:
125128
None
@@ -200,7 +203,8 @@ def list_for_zabbix(snipeit_api, args):
200203
# Print asset details including custom fields
201204
def print_asset_details(asset):
202205
print(
203-
f'Asset Tag: {asset["asset_tag"]}, Asset ID: {asset["id"]}, Name: {asset["name"]}, Serial: {asset["serial"]}'
206+
f'Asset Tag: {asset["asset_tag"]}, Asset ID: {asset["id"]},'
207+
f'Name: {asset["name"]}, Serial: {asset["serial"]}'
204208
)
205209

206210
if asset["assigned_to"]:
@@ -265,7 +269,8 @@ def power_on(rte, args):
265269
if state != rte.PSU_STATE_ON:
266270
print(f"Power supply state: {state} !")
267271
print(
268-
'If you wanted to power on the DUT, you need to enable power supply first ("pwr psu on"), pushing the power button is not enough!'
272+
"If you wanted to power on the DUT, you need to enable power suppl"
273+
'y first ("pwr psu on"), pushing the power button is not enough!'
269274
)
270275
print(f"Powering on...")
271276
rte.power_on(args.time)
@@ -507,12 +512,14 @@ def update_zabbix_assets(snipeit_api):
507512
== snipeit_assets[snipeit_assets_keys[j]]
508513
):
509514
print(
510-
f"{snipeit_assets_keys[i]} has the same IP as {snipeit_assets_keys[j]}!"
515+
f"{snipeit_assets_keys[i]} has the same IP as "
516+
f"{snipeit_assets_keys[j]}!"
511517
)
512518
snipeit_configuration_error = True
513519
if snipeit_assets_keys[i] == snipeit_assets_keys[j]:
514520
print(
515-
f"There are at least 2 assets with name {snipeit_assets_keys[i]} present!"
521+
f"There are at least 2 assets with name "
522+
f"{snipeit_assets_keys[i]} present!"
516523
)
517524
snipeit_configuration_error = True
518525

@@ -521,7 +528,8 @@ def update_zabbix_assets(snipeit_api):
521528
symbol in snipeit_assets_keys[i] for symbol in forbidden_symbols
522529
):
523530
print(
524-
f"{snipeit_assets_keys[i]} contains forbidden symbols! They are going to be changed to '_'."
531+
f"{snipeit_assets_keys[i]} contains forbidden symbols! They "
532+
f"are going to be changed to '_'."
525533
)
526534
new_key = copy(snipeit_assets_keys[i])
527535
for s in forbidden_symbols:
@@ -533,7 +541,8 @@ def update_zabbix_assets(snipeit_api):
533541

534542
if snipeit_configuration_error:
535543
print(
536-
"\nSnipeIT configuration errors have been detected! Fix them and then continue."
544+
"\nSnipeIT configuration errors have been detected! "
545+
"Fix them and then continue."
537546
)
538547
return
539548

@@ -561,7 +570,8 @@ def update_zabbix_assets(snipeit_api):
561570

562571
if keys_not_present_in_snipeit.__len__() > 0:
563572
print(
564-
"\nAssets present in Zabbix but not in SnipeIT (these will be removed):"
573+
"\nAssets present in Zabbix but not in SnipeIT "
574+
"(these will be removed):"
565575
)
566576
print("\n".join(keys_not_present_in_snipeit))
567577

@@ -570,7 +580,8 @@ def update_zabbix_assets(snipeit_api):
570580
for key in common_keys:
571581
if snipeit_assets[key] != current_zabbix_assets[key]:
572582
print(
573-
f"{key} has wrong IP! (Zabbix one will be updated from {current_zabbix_assets[key]} to {snipeit_assets[key]})"
583+
f"{key} has wrong IP! (Zabbix one will be updated from "
584+
f"{current_zabbix_assets[key]} to {snipeit_assets[key]})"
574585
)
575586
keys_for_ip_change.append(key)
576587

@@ -750,8 +761,10 @@ def main():
750761
rte_parser.add_argument(
751762
"--skip-snipeit",
752763
action="store_true",
753-
help="Skips Snipe-IT related actions like checkout and check-in. \
754-
Useful for OSFV homelab.",
764+
help=(
765+
f"Skips Snipe-IT related actions like checkout and check-in. "
766+
f"Useful for OSFV homelab."
767+
),
755768
)
756769
rte_subparsers = rte_parser.add_subparsers(
757770
title="subcommands", dest="rte_cmd", help="RTE subcommands"
@@ -983,7 +996,8 @@ def main():
983996
)
984997
else:
985998
exit(
986-
f"failed to retrieve model name from snipe-it. check again arguments, or try providing model manually."
999+
f"failed to retrieve model name from snipe-it. check "
1000+
f"again arguments, or try providing model manually."
9871001
)
9881002
else:
9891003
exit(f"model name not present. check again arguments.")
@@ -992,7 +1006,8 @@ def main():
9921006

9931007
if not args.skip_snipeit:
9941008
print(
995-
f"Using rte command is invasive action, checking first if the device is not used..."
1009+
f"Using rte command is invasive action, checking first if the "
1010+
f"device is not used..."
9961011
)
9971012
already_checked_out = check_out_asset(snipeit_api, asset_id)
9981013

@@ -1053,16 +1068,16 @@ def main():
10531068
if not args.skip_snipeit:
10541069
if already_checked_out:
10551070
print(
1056-
f"Since the asset {asset_id} has been checkout manually \
1057-
by you prior running this script, it will NOT be checked \
1058-
in automatically. Please return the device when work is \
1059-
finished."
1071+
f"Since the asset {asset_id} has been checkout manually "
1072+
f"by you prior running this script, it will NOT be checked "
1073+
f"in automatically. Please return the device when work is "
1074+
f"finished."
10601075
)
10611076
else:
10621077
print(
1063-
f"Since the asset {asset_id} has been checkout \
1064-
automatically by this script, it is automatically checked \
1065-
in as well."
1078+
f"Since the asset {asset_id} has been checkout "
1079+
f"automatically by this script, it is automatically "
1080+
f"checked in as well."
10661081
)
10671082
check_in_asset(snipeit_api, asset_id)
10681083
elif args.command == "sonoff":
@@ -1080,7 +1095,8 @@ def main():
10801095
print(f"No asset found with RTE IP: {args.rte_ip}")
10811096

10821097
print(
1083-
f"Using rte command is invasive action, checking first if the device is not used..."
1098+
f"Using rte command is invasive action, checking first if the "
1099+
f"device is not used..."
10841100
)
10851101
already_checked_out = check_out_asset(snipeit_api, asset_id)
10861102

@@ -1097,11 +1113,15 @@ def main():
10971113

10981114
if already_checked_out:
10991115
print(
1100-
f"Since the asset {asset_id} has been checkout manually by you prior running this script, it will NOT be checked in automatically. Please return the device when work is finished."
1116+
f"Since the asset {asset_id} has been checkout manually by "
1117+
f"you prior running this script, it will NOT be checked in "
1118+
f"automatically. Please return the device when work is "
1119+
f"finished."
11011120
)
11021121
else:
11031122
print(
1104-
f"Since the asset {asset_id} has been checkout automatically by this script, it is automatically checked in as well."
1123+
f"Since the asset {asset_id} has been checkout automatically "
1124+
f"by this script, it is automatically checked in as well."
11051125
)
11061126
check_in_asset(snipeit_api, asset_id)
11071127
elif args.command == "list_models":

osfv_cli/src/osfv/libs/models.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ def load_model_data(self, dut_model, exit_on_failure=True):
109109
else:
110110
if exit_on_failure:
111111
exit(
112-
f"Required field '{field}' is missing in model config."
112+
f"Required field '{field}' is missing in model "
113+
f"config."
113114
)
114115
else:
115116
model_YML_status = False

osfv_cli/src/osfv/libs/rte.py

+23-12
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def __init__(self, rte_ip, dut_model, sonoff):
4646
if not self.sonoff_sanity_check():
4747
raise SonoffNotFound(
4848
exit(
49-
f"Missing value for 'sonoff_ip' or Sonoff not found in SnipeIT"
49+
f"Missing value for 'sonoff_ip' or Sonoff not found "
50+
f"in SnipeIT"
5051
)
5152
)
5253

@@ -104,11 +105,13 @@ def relay_get(self):
104105

105106
def relay_set(self, relay_state):
106107
"""
107-
Sets the state of the relay by configuring the GPIO relay pin accordingly.
108+
Sets the state of the relay by configuring the GPIO relay pin
109+
accordingly.
108110
109111
Args:
110-
relay_state (str): Desired state of the relay, either "on" (sets GPIO pin to "high")
111-
or "off" (sets GPIO pin to "low").
112+
relay_state (str): Desired state of the relay, either "on"
113+
(sets GPIO pin to "high") or "off"
114+
(sets GPIO pin to "low").
112115
"""
113116
gpio_state = None
114117
if relay_state == self.PSU_STATE_ON:
@@ -119,15 +122,17 @@ def relay_set(self, relay_state):
119122

120123
def reset_cmos(self):
121124
"""
122-
Resets the CMOS by setting the GPIO CMOS pin to "low" for 10 seconds, then returning it to a "high-z" state.
125+
Resets the CMOS by setting the GPIO CMOS pin to "low" for 10 seconds,
126+
then returning it to a "high-z" state.
123127
"""
124128
self.gpio_set(self.GPIO_CMOS, "low")
125129
time.sleep(10)
126130
self.gpio_set(self.GPIO_CMOS, "high-z")
127131

128132
def spi_enable(self):
129133
"""
130-
Enables the SPI interface by configuring GPIO pins based on the voltage level required by the flash chip.
134+
Enables the SPI interface by configuring GPIO pins based on the voltage
135+
level required by the flash chip.
131136
"""
132137
voltage = self.dut_data["flash_chip"]["voltage"]
133138

@@ -154,7 +159,8 @@ def spi_disable(self):
154159

155160
def psu_on(self):
156161
"""
157-
Connect main power supply to the DUT by setting either relay or Sonoff to ON state.
162+
Connect main power supply to the DUT by setting either relay
163+
or Sonoff to ON state.
158164
"""
159165
if self.dut_data["pwr_ctrl"]["sonoff"] is True:
160166
self.sonoff.turn_on()
@@ -170,7 +176,8 @@ def psu_on(self):
170176

171177
def psu_off(self):
172178
"""
173-
Disconnect main power supply from the DUT by setting either relay or Sonoff to OFF state.
179+
Disconnect main power supply from the DUT by setting either relay
180+
or Sonoff to OFF state.
174181
"""
175182
# TODO: rework using abstract interfaces for power control?
176183
if self.dut_data["pwr_ctrl"]["sonoff"] is True:
@@ -198,14 +205,16 @@ def psu_get(self):
198205

199206
def discharge_psu(self):
200207
"""
201-
Push power button 5 times in the loop to make sure the charge from PSU is dissipated
208+
Push power button 5 times in the loop to make sure the charge
209+
from PSU is dissipated
202210
"""
203211
for _ in range(5):
204212
self.power_off(3)
205213

206214
def pwr_ctrl_before_flash(self, programmer, power_state):
207215
"""
208-
Move the DUT into specific power state required for external flashing operation. Defined in the model config file.
216+
Move the DUT into specific power state required for external flashing
217+
operation. Defined in the model config file.
209218
"""
210219

211220
# Always start from the same state (PSU active)
@@ -232,7 +241,8 @@ def pwr_ctrl_before_flash(self, programmer, power_state):
232241
self.discharge_psu()
233242
else:
234243
exit(
235-
f"Power state: '{power_state}' is not supported. Please check model config."
244+
f"Power state: '{power_state}' is not supported. Please check "
245+
f"model config."
236246
)
237247

238248
def pwr_ctrl_after_flash(self, programmer):
@@ -245,7 +255,8 @@ def pwr_ctrl_after_flash(self, programmer):
245255

246256
def flash_cmd(self, args, read_file=None, write_file=None):
247257
"""
248-
Send the firmware file to RTE and execute flashrom command over SSH to flash the DUT.
258+
Send the firmware file to RTE and execute flashrom command over SSH to
259+
flash the DUT.
249260
"""
250261
try:
251262
self.pwr_ctrl_before_flash(

osfv_cli/src/osfv/libs/rtectrl_api.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
class rtectrl:
1010
"""
11-
A class to control and interact with GPIO pins on an RTE device using its REST API.
11+
A class to control and interact with GPIO pins on an RTE device
12+
using its REST API.
1213
1314
Attributes:
1415
GPIO_MIN (int): Minimum valid GPIO number (0).
@@ -82,7 +83,8 @@ def gpio_set(self, gpio_no, state_str, sleep=0):
8283
state_str (str): Desired state for the GPIO pin.
8384
For pins 1-12: "low" or "high-z".
8485
For pins 0, 13-19: "high" or "low".
85-
sleep (int, optional): Duration in seconds for which to maintain the state. Default is 0.
86+
sleep (int, optional): Duration in seconds for which to maintain the
87+
state. Default is 0.
8688
8789
Raises:
8890
GPIOWrongNumberError: If the GPIO number is outside the valid range.
@@ -146,7 +148,8 @@ def _get_request(self, endpoint):
146148

147149
def _patch_request(self, endpoint, data):
148150
"""
149-
Sends a PATCH request to the specified API endpoint with the provided data.
151+
Sends a PATCH request to the specified API endpoint with the
152+
provided data.
150153
151154
Args:
152155
endpoint (str): API endpoint to send the PATCH request to.

0 commit comments

Comments
 (0)