Skip to content

Commit 21afea4

Browse files
ruff
1 parent efe4372 commit 21afea4

File tree

1 file changed

+24
-19
lines changed
  • installation_and_upgrade/ibex_install_utils/tasks

1 file changed

+24
-19
lines changed

installation_and_upgrade/ibex_install_utils/tasks/vhd_tasks.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919

2020
class Vhd:
21-
def __init__(self, name, source_filename, dest_filename, mount_point):
21+
def __init__(
22+
self, name: str, source_filename: str, dest_filename: str, mount_point: str
23+
) -> None:
2224
self.name = name
2325
self.source_filename = source_filename
2426
self.dest_filename = dest_filename
@@ -65,7 +67,7 @@ class VHDTasks(BaseTasks):
6567
"""
6668

6769
@task("Copy VHDs to local area")
68-
def copy_vhds_to_local_area(self):
70+
def copy_vhds_to_local_area(self) -> None:
6971
if os.path.exists(LOCAL_VHD_DIR):
7072
try:
7173
shutil.rmtree(LOCAL_VHD_DIR)
@@ -80,7 +82,7 @@ def copy_vhds_to_local_area(self):
8082
os.path.join(LOCAL_VHD_DIR, vhd.source_filename),
8183
)
8284

83-
def _create_file_and_wait_for_it_to_be_deleted(self, filename, timeout):
85+
def _create_file_and_wait_for_it_to_be_deleted(self, filename: str, timeout: int) -> None:
8486
with open(filename, "w") as f:
8587
f.write("")
8688

@@ -110,24 +112,24 @@ def _create_file_and_wait_for_it_to_be_deleted(self, filename, timeout):
110112
print("--- end scheduled task output ---")
111113
print("---")
112114
raise IOError(
113-
f"File at {filename} still existed after {timeout}s, check VHD scheduled task is running "
114-
f"correctly "
115+
f"File at {filename} still existed after {timeout}s, "
116+
"check VHD scheduled task is running correctly "
115117
)
116118

117119
@task("Request VHDs to be mounted")
118-
def request_mount_vhds(self):
120+
def request_mount_vhds(self) -> None:
119121
self._create_file_and_wait_for_it_to_be_deleted(
120122
FILE_TO_REQUEST_VHD_MOUNTING, VHD_MOUNT_DISMOUNT_TIMEOUT
121123
)
122124

123125
@task("Request VHDs to be dismounted")
124-
def request_dismount_vhds(self):
126+
def request_dismount_vhds(self) -> None:
125127
self._create_file_and_wait_for_it_to_be_deleted(
126128
FILE_TO_REQUEST_VHD_DISMOUNTING, VHD_MOUNT_DISMOUNT_TIMEOUT
127129
)
128130

129131
@task("Mount VHDs")
130-
def mount_vhds(self):
132+
def mount_vhds(self) -> None:
131133
if not os.path.exists(FILE_TO_REQUEST_VHD_MOUNTING):
132134
return
133135

@@ -150,18 +152,20 @@ def mount_vhds(self):
150152
# Mount the VHD and write it's assigned drive letter to a file.
151153
admin_commands.add_command(
152154
"powershell",
153-
r'-command "Hyper-V\Mount-VHD -path {vhd_file} -Passthru | Get-Disk | Get-Partition | Get-Volume | foreach {{ $_.DriveLetter }} | out-file -filepath {driveletter_file} -Encoding ASCII -NoNewline"'.format(
155+
r'-command "Hyper-V\Mount-VHD -path {vhd_file} -Passthru | Get-Disk | '
156+
r"Get-Partition | Get-Volume | foreach {{ $_.DriveLetter }} | "
157+
r'out-file -filepath {driveletter_file} -Encoding ASCII -NoNewline"'.format(
154158
vhd_file=os.path.join(LOCAL_VHD_DIR, vhd.source_filename),
155159
driveletter_file=driveletter_file,
156160
),
157161
)
158162

159-
# Append :\\ to drive letter, e.g. E -> E:\\ (this is necessary so that directory junctions work correctly)
163+
# Append :\\ to drive letter, e.g. E -> E:\\
164+
# (this is necessary so that directory junctions work correctly)
160165
admin_commands.add_command(
161166
"powershell",
162-
r'-command "echo :\\ | out-file -filepath {driveletter_file} -Encoding ASCII -Append -NoNewline"'.format(
163-
driveletter_file=driveletter_file
164-
),
167+
r'-command "echo :\\ | out-file -filepath {driveletter_file} '
168+
r'-Encoding ASCII -Append -NoNewline"'.format(driveletter_file=driveletter_file),
165169
)
166170

167171
# If parent of mount point doesn't exist mklink will fail, create it to avoid this
@@ -187,13 +191,14 @@ def mount_vhds(self):
187191
os.remove(FILE_TO_REQUEST_VHD_MOUNTING)
188192

189193
@task("Dismount VHDs")
190-
def dismount_vhds(self):
194+
def dismount_vhds(self) -> None:
191195
if not os.path.exists(FILE_TO_REQUEST_VHD_DISMOUNTING):
192196
return
193197

194198
admin_commands = AdminCommandBuilder()
195199

196-
# Belt and braces - mysql should already be stopped, but make sure by explicitly stopping it again.
200+
# Belt and braces - mysql should already be stopped, but make sure by
201+
# explicitly stopping it again.
197202
admin_commands.add_command("sc", "stop MYSQL80", expected_return_val=None)
198203

199204
for vhd in VHDS:
@@ -213,8 +218,8 @@ def dismount_vhds(self):
213218
r'/c "del /s /q {mount_point}"'.format(mount_point=vhd.mount_point),
214219
expected_return_val=None,
215220
)
216-
# If we don't have a backup then use rmdir to only delete the mount point (does nothing if the dir
217-
# is non-empty)
221+
# If we don't have a backup then use rmdir to only delete the mount point
222+
# (does nothing if the dir is non-empty)
218223
admin_commands.add_command(
219224
"cmd",
220225
r'/c "rmdir {mount_point}"'.format(mount_point=vhd.mount_point),
@@ -235,7 +240,7 @@ def dismount_vhds(self):
235240
os.remove(FILE_TO_REQUEST_VHD_DISMOUNTING)
236241

237242
@task("Deploy VHDS")
238-
def deploy_vhds(self):
243+
def deploy_vhds(self) -> None:
239244
if self._ibex_version is not None:
240245
build_folder = os.path.join(
241246
REMOTE_VHD_DEST_DIR, "Releases", "{}".format(self._ibex_version)
@@ -257,7 +262,7 @@ def deploy_vhds(self):
257262
shutil.rmtree(LOCAL_VHD_DIR)
258263

259264
@task("Initialize var dir")
260-
def initialize_var_dir(self):
265+
def initialize_var_dir(self) -> None:
261266
"""
262267
Creates the folder structure for the C:\\instrument\\var directory.
263268
"""

0 commit comments

Comments
 (0)