@@ -132,7 +132,7 @@ def get_connected_mbeds(self):
132132 @return Returns [(<mbed_mount_point>, <mbed_id>), ..]
133133 @details Helper function
134134 """
135- return [m for m in self .get_mbeds () if os . path . exists (m [0 ])]
135+ return [m for m in self .get_mbeds () if self . mount_point_ready (m [0 ])]
136136
137137 def get_mbeds (self ):
138138 """! Function filters devices' mount points for valid TargetID
@@ -198,3 +198,22 @@ def regbin2str(self, regbin):
198198 """! Decode registry binary to readable string
199199 """
200200 return filter (lambda ch : ch in string .printable , regbin )
201+
202+ def mount_point_ready (self , path ):
203+ """! Check if a mount point is ready for file operations
204+ @return Returns True if the given path exists, False otherwise
205+ @details Calling the Windows command `dir` instead of using the python
206+ `os.path.exists`. The latter causes a Python error box to appear claiming
207+ there is "No Disk" for some devices that are in the ejected state. Calling
208+ `dir` prevents this since it uses the Windows API to determine if the
209+ device is ready before accessing the file system.
210+ """
211+ stdout , stderr , retcode = self .run_cli_process ('dir %s' % path )
212+ result = True if retcode == 0 else False
213+
214+ if result :
215+ self .debug (self .mount_point_ready .__name__ , "Mount point %s is ready" % path )
216+ else :
217+ self .debug (self .mount_point_ready .__name__ , "Mount point %s reported not ready with error '%s'" % (path , stderr .strip ()))
218+
219+ return result
0 commit comments