Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions mbed_lstools/lstools_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,19 @@ def scan_html_line_for_target_id(self, line):
return result
return None

def mount_point_ready(self, path):
"""! Check if a mount point is ready for file operations
@return Returns True if the given path exists, False otherwise
"""
result = os.path.exists(path)

if result:
self.debug(self.mount_point_ready.__name__, "Mount point %s is ready" % path)
else:
self.debug(self.mount_point_ready.__name__, "Mount point %s does not exist" % (path))

return result

@staticmethod
def run_cli_process(cmd, shell=True):
"""! Runs command as a process and return stdout, stderr and ret code
Expand Down
21 changes: 20 additions & 1 deletion mbed_lstools/lstools_win7.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def get_connected_mbeds(self):
@return Returns [(<mbed_mount_point>, <mbed_id>), ..]
@details Helper function
"""
return [m for m in self.get_mbeds() if os.path.exists(m[0])]
return [m for m in self.get_mbeds() if self.mount_point_ready(m[0])]

def get_mbeds(self):
"""! Function filters devices' mount points for valid TargetID
Expand Down Expand Up @@ -198,3 +198,22 @@ def regbin2str(self, regbin):
"""! Decode registry binary to readable string
"""
return filter(lambda ch: ch in string.printable, regbin)

def mount_point_ready(self, path):
"""! Check if a mount point is ready for file operations
@return Returns True if the given path exists, False otherwise
@details Calling the Windows command `dir` instead of using the python
`os.path.exists`. The latter causes a Python error box to appear claiming
there is "No Disk" for some devices that are in the ejected state. Calling
`dir` prevents this since it uses the Windows API to determine if the
device is ready before accessing the file system.
"""
stdout, stderr, retcode = self.run_cli_process('dir %s' % path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does dir command behave same on all platforms? I guess it will have different behaviour on Windows and Linux.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dir command will only be used on Windows. On Linux it looks like it never actually checks to see if the file system has that mount point via os.path.exists, it just checks the mount point using the mount command.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright I see that it is in Windows implementation.

result = True if retcode == 0 else False

if result:
self.debug(self.mount_point_ready.__name__, "Mount point %s is ready" % path)
else:
self.debug(self.mount_point_ready.__name__, "Mount point %s reported not ready with error '%s'" % (path, stderr.strip()))

return result