Skip to content

Commit 1828516

Browse files
usb_device-msd test: fix powershell unmount script issue
Running PowerShell script on some windows machines is blocked. To avoid this problem script was replace by the code run directly in PowerShell console.
1 parent 4bd1d15 commit 1828516

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

TESTS/host_tests/pyusb_msd.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -204,25 +204,16 @@ def _disk_path_mac(serial):
204204
@staticmethod
205205
def _unmount_windows(serial):
206206
disk_path = MSDUtils._disk_path_windows(serial)
207-
tmp_file = tempfile.NamedTemporaryFile(suffix='.ps1', delete=False)
208-
try:
209-
# create unmount script
210-
tmp_file.write('$disk_leter=$args[0]\n')
211-
tmp_file.write('$driveEject = New-Object -comObject Shell.Application\n')
212-
tmp_file.write('$driveEject.Namespace(17).ParseName($disk_leter).InvokeVerb("Eject")\n')
213-
# close to allow open by other process
214-
tmp_file.close()
215-
216-
try_count = 10
217-
while try_count:
218-
p = subprocess.Popen(["powershell.exe", tmp_file.name + " " + disk_path], stdout=sys.stdout)
219-
p.communicate()
220-
try_count -= 1
221-
if MSDUtils._disk_path_windows(serial) is None:
222-
return True
223-
time.sleep(1)
224-
finally:
225-
os.remove(tmp_file.name)
207+
cmd_string = r'(New-Object -comObject Shell.Application).Namespace(17).ParseName("{}").InvokeVerb("Eject")'.format(disk_path)
208+
209+
try_count = 10
210+
while try_count:
211+
p = subprocess.Popen(["powershell.exe", cmd_string], stdout=sys.stdout)
212+
p.communicate()
213+
try_count -= 1
214+
if MSDUtils._disk_path_windows(serial) is None:
215+
return True
216+
time.sleep(1)
226217

227218
return False
228219

0 commit comments

Comments
 (0)