Skip to content

Device type detection now with no files #378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 31, 2018
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
10 changes: 6 additions & 4 deletions mbed_lstools/lstools_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def list_mbeds(
logger.debug("Candidates for display %r", candidates)
result = []
for device in candidates:
device['device_type'] = self._detect_device_type(device)
if ((not device['mount_point'] or
not self.mount_point_ready(device['mount_point'])) and
not self.list_unmounted):
Expand All @@ -146,7 +147,8 @@ def list_mbeds(
"Use the '-u' flag to include it in the list.",
device['target_id_usb_id'])
else:
platform_data = self.plat_db.get(device['target_id_usb_id'][0:4], verbose_data=True)
platform_data = self.plat_db.get(device['target_id_usb_id'][0:4],
device_type=device['device_type'] or 'daplink', verbose_data=True)
device.update(platform_data or {"platform_name": None})
maybe_device = {
FSInteraction.BeforeFilter: self._fs_before_id_check,
Expand All @@ -167,6 +169,9 @@ def list_mbeds(
self.retarget_data[device['target_id']])
except KeyError:
pass

# This is done for API compatibility, would prefer for this to just be None
device['device_type'] = device['device_type'] if device['device_type'] else 'unknown'
result.append(maybe_device)

return result
Expand Down Expand Up @@ -211,13 +216,11 @@ def _update_device_from_fs(self, device, read_details_txt):
output dict attributes read from other files present on the 'mount_point'
"""
if not device.get('mount_point', None):
device['device_type'] = 'unknown'
return

try:
directory_entries = os.listdir(device['mount_point'])
device['directory_entries'] = directory_entries
device['device_type'] = self._detect_device_type(device)
device['target_id'] = device['target_id_usb_id']

{
Expand All @@ -230,7 +233,6 @@ def _update_device_from_fs(self, device, read_details_txt):
'Marking device with mount point "%s" as unmounted due to the '
'following error: %s', device['mount_point'], e)
device['mount_point'] = None
device['device_type'] = 'unknown'


def _detect_device_type(self, device):
Expand Down
25 changes: 19 additions & 6 deletions test/mbedls_toolsbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,8 @@ def test_update_device_from_fs_mid_unmount(self):
with patch('os.listdir') as _listdir:
_listdir.side_effect = OSError
self.base._update_device_from_fs(device, False)
self.assertEqual(device['device_type'], 'unknown')
self.assertEqual(device['mount_point'], None)

def test_update_device_from_fs_unknown(self):
device = {}
self.base._update_device_from_fs(device, False)
self.assertEqual(device['device_type'], 'unknown')

def test_detect_device_test(self):
device_type = self.base._detect_device_type({
'vendor_id': '0483'
Expand All @@ -304,6 +298,25 @@ def test_detect_device_test(self):
})
self.assertEqual(device_type, 'jlink')

def test_device_type_unmounted(self):
self.base.list_unmounted = True
self.base.return_value = [{'mount_point': None,
'target_id_usb_id': u'0240DEADBEEF',
'serial_port': "dummy_serial_port",
'vendor_id': '0d28',
'product_id': '0204'}]
with patch("mbed_lstools.lstools_base.PlatformDatabase.get") as _get,\
patch('os.listdir') as _listdir:
_get.return_value = {
'platform_name': 'foo_target'
}
to_check = self.base.list_mbeds()
#_get.assert_any_call('0240', device_type='daplink', verbose_data=True)
self.assertEqual(len(to_check), 1)
self.assertEqual(to_check[0]['target_id'], "0240DEADBEEF")
self.assertEqual(to_check[0]['platform_name'], 'foo_target')
self.assertEqual(to_check[0]['device_type'], 'daplink')

def test_update_device_details_jlink(self):
jlink_html_contents = ('<html><head><meta http-equiv="refresh" '
'content="0; url=http://www.nxp.com/FRDM-KL27Z"/>'
Expand Down