Skip to content

Commit bf3614c

Browse files
acabarbayemadchutney
authored andcommitted
[MacOs] [FIX] mbed-ls does not show any output when STLink external probe connected (#211)
* ensures the xml is valid before parsing it * Decodes the XML content before encoding it again in the same way as what prettify does Ensures BeautifulSoup can be installed properly for all versions of python / platforms Ensures lxml parser is also installed properly when needed * Update src/mbed_os_tools/detect/darwin.py Co-Authored-By: Graham Hammond <[email protected]> * Update requirements.txt Added a comment * Update azure-pipelines.yml Removed a condition which is no longer required * Update darwin.py making the comment more explicit * Update darwin.py Fix Pep8 issue
1 parent 7c5045e commit bf3614c

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

azure-pipelines.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ jobs:
7979
-
8080
script: "python -m pip install --upgrade pip && pip install -r test_requirements.txt"
8181
displayName: "Install mbed-os test dependencies"
82+
-
83+
script: "pip install lxml"
84+
env: { STATIC_DEPS: true }
85+
displayName: "Install lxml separately on Linux/MacOS"
8286
-
8387
script: 'pip install --user "urllib3<1.25"'
8488
displayName: "Fix dependency issue for requests package"

packages/mbed-ls/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
PrettyTable>=0.7.2
2-
mbed-os-tools>=0.0.9,<0.1.0
2+
mbed-os-tools>=0.0.9,<0.1.0

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ junit-xml>=1.0,<2.0
99
lockfile
1010
six>=1.0,<2.0
1111
colorama>=0.3,<0.5
12+
# When using beautiful soup, the XML parser needs to be installed independently. It is only needed on macOs though.
13+
beautifulsoup4
14+
lxml; sys_platform == 'darwin'

src/mbed_os_tools/detect/darwin.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import subprocess
1818
import platform
1919

20+
from bs4 import BeautifulSoup
21+
2022
try:
2123
from plistlib import loads
2224
except ImportError:
@@ -40,7 +42,13 @@ def _plist_from_popen(popen):
4042
if not out:
4143
return []
4244
try:
43-
return loads(out)
45+
# Beautiful soup ensures the XML is properly formed after it is parsed
46+
# so that it can be used by other less lenient commands without problems
47+
xml_representation = BeautifulSoup(out.decode('utf8'), 'xml')
48+
if not xml_representation.get_text():
49+
# The output is not in the XML format
50+
return loads(out)
51+
return loads(xml_representation.decode().encode('utf8'))
4452
except ExpatError:
4553
return []
4654

@@ -85,9 +93,9 @@ def _dfs_usb_info(obj, parents):
8593
"""
8694
output = {}
8795
if (
88-
"BSD Name" in obj
89-
and obj["BSD Name"].startswith("disk")
90-
and mbed_volume_name_match.search(obj["IORegistryEntryName"])
96+
"BSD Name" in obj
97+
and obj["BSD Name"].startswith("disk")
98+
and mbed_volume_name_match.search(obj["IORegistryEntryName"])
9199
):
92100
disk_id = obj["BSD Name"]
93101
usb_info = {"serial": None, "vendor_id": None, "product_id": None, "tty": None}
@@ -177,12 +185,13 @@ def _volumes(self):
177185
if self.mac_version >= 10.11:
178186
cmp_par = "-c"
179187

188+
usb_tree = []
180189
for usb_controller in usb_controllers:
181190
ioreg_usb = subprocess.Popen(
182191
["ioreg", "-a", "-r", cmp_par, usb_controller, "-l"],
183192
stdout=subprocess.PIPE,
184193
)
185-
usb_tree = _plist_from_popen(ioreg_usb)
194+
usb_tree.extend(_plist_from_popen(ioreg_usb))
186195

187196
r = {}
188197

0 commit comments

Comments
 (0)