87 def copy_image(self, image_path=None, disk=None, copy_method=None, port=None, retry_copy=5):
88 """! Closure for copy_image_raw() method.
89 @return Returns result from copy plugin
91 def get_remount_count(disk_path, tries=2):
92 """! Get the remount count from 'DETAILS.TXT' file
93 @return Returns count, None if not-available
95 for cur_try
in range(1, tries + 1):
97 files_on_disk = [x.upper()
for x
in os.listdir(disk_path)]
98 if 'DETAILS.TXT' in files_on_disk:
99 with open(os.path.join(disk_path,
'DETAILS.TXT'),
'r')
as details_txt:
100 for line
in details_txt.readlines():
101 if 'Remount count:' in line:
102 return int(line.replace(
'Remount count: ',
''))
110 self.
logger.prn_err(
"Failed to get remount count due to OSError.", str(e))
111 self.
logger.prn_inf(
"Retrying in 1 second (try %s of %s)" % (cur_try, tries))
116 def check_flash_error(target_id, disk, initial_remount_count):
117 """! Check for flash errors
118 @return Returns false if FAIL.TXT present, else true
121 self.
logger.prn_wrn(
"Target ID not found: Skipping flash check and retry")
124 bad_files = set([
'FAIL.TXT'])
128 mbeds = mbed_lstools.create()
129 mbed_list = mbeds.list_mbeds()
131 mbed_target = next((x
for x
in mbed_list
if x[
'target_id']==target_id),
None)
133 if mbed_target
is not None:
134 if 'mount_point' in mbed_target
and mbed_target[
'mount_point']
is not None:
135 if not initial_remount_count
is None:
136 new_remount_count = get_remount_count(disk)
137 if not new_remount_count
is None and new_remount_count == initial_remount_count:
143 items = set([x.upper()
for x
in os.listdir(mbed_target[
'mount_point'])])
144 common_items = bad_files.intersection(items)
146 print(
"Failed to enumerate disk files, retrying")
149 for common_item
in common_items:
150 full_path = os.path.join(mbed_target[
'mount_point'], common_item)
151 self.
logger.prn_err(
"Found %s"% (full_path))
152 bad_file_contents =
"[failed to read bad file]"
154 with open(full_path,
"r")
as bad_file:
155 bad_file_contents = bad_file.read()
156 except IOError
as error:
157 self.
logger.prn_err(
"Error opening '%s': %s" % (full_path, error))
159 self.
logger.prn_err(
"Error file contents:\n%s" % bad_file_contents)
179 self.
logger.prn_err(
"Error: image path not specified")
182 if not os.path.isfile(image_path):
183 self.
logger.prn_err(
"Error: image file (%s) not found" % image_path)
186 for count
in range(0, retry_copy):
187 initial_remount_count = get_remount_count(disk)
193 result = check_flash_error(target_id, disk, initial_remount_count)
198 def copy_image_raw(self, image_path=None, disk=None, copy_method=None, port=None):
199 """! Copy file depending on method you want to use. Handles exception
200 and return code from shell copy commands.
201 @return Returns result from copy plugin
202 @details Method which is actually copying image to mbed
211 }.get(copy_method, copy_method)
213 result = ht_plugins.call_plugin(
'CopyMethod',
215 image_path=image_path,
217 destination_disk=disk,