Skip to content

Commit fa4f337

Browse files
Merge pull request #65 from bridadan/move_detect_deprecated_functions
Move detect deprecated functions
2 parents 2d58465 + e67cc75 commit fa4f337

File tree

8 files changed

+287
-240
lines changed

8 files changed

+287
-240
lines changed

packages/mbed-ls/mbed_lstools/lstools_base.py

Lines changed: 1 addition & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -21,189 +21,5 @@
2121

2222
from mbed_os_tools.detect.lstools_base import (
2323
FSInteraction,
24-
MbedDetectLsToolsBase,
24+
MbedLsToolsBase,
2525
)
26-
27-
logger = logging.getLogger("mbedls.lstools_base")
28-
logger.addHandler(logging.NullHandler())
29-
30-
def deprecated(reason):
31-
"""Deprecate a function/method with a decorator"""
32-
def actual_decorator(func):
33-
@functools.wraps(func)
34-
def new_func(*args, **kwargs):
35-
logger.warning("Call to deprecated function %s. %s",
36-
func.__name__, reason)
37-
return func(*args, **kwargs)
38-
return new_func
39-
return actual_decorator
40-
41-
class MbedLsToolsBase(MbedDetectLsToolsBase):
42-
""" Base class for mbed-lstools, defines mbed-ls tools interface for
43-
mbed-enabled devices detection for various hosts
44-
"""
45-
46-
@deprecated("Functionality has been moved into 'list_mbeds'. "
47-
"Please use list_mbeds with 'unique_names=True' and "
48-
"'read_details_txt=True'")
49-
def list_mbeds_ext(self):
50-
"""! Function adds extra information for each mbed device
51-
@return Returns list of mbed devices plus extended data like 'platform_name_unique'
52-
@details Get information about mbeds with extended parameters/info included
53-
"""
54-
55-
return self.list_mbeds(unique_names=True, read_details_txt=True)
56-
57-
@deprecated("List formatting methods are deprecated for a simpler API. "
58-
"Please use 'list_mbeds' instead.")
59-
def list_manufacture_ids(self):
60-
"""! Creates list of all available mappings for target_id -> Platform
61-
@return String with table formatted output
62-
"""
63-
from prettytable import PrettyTable, HEADER
64-
65-
columns = ['target_id_prefix', 'platform_name']
66-
pt = PrettyTable(columns, junction_char="|", hrules=HEADER)
67-
for col in columns:
68-
pt.align[col] = 'l'
69-
70-
for target_id_prefix, platform_name in sorted(self.plat_db.items()):
71-
pt.add_row([target_id_prefix, platform_name])
72-
73-
return pt.get_string()
74-
75-
@deprecated("List formatting methods are deprecated to simplify the API. "
76-
"Please use 'list_mbeds' instead.")
77-
def list_platforms(self):
78-
"""! Useful if you just want to know which platforms are currently available on the system
79-
@return List of (unique values) available platforms
80-
"""
81-
result = []
82-
mbeds = self.list_mbeds()
83-
for i, val in enumerate(mbeds):
84-
platform_name = str(val['platform_name'])
85-
if platform_name not in result:
86-
result.append(platform_name)
87-
return result
88-
89-
@deprecated("List formatting methods are deprecated to simplify the API. "
90-
"Please use 'list_mbeds' instead.")
91-
def list_platforms_ext(self):
92-
"""! Useful if you just want to know how many platforms of each type are currently available on the system
93-
@return Dict of platform: platform_count
94-
"""
95-
result = {}
96-
mbeds = self.list_mbeds()
97-
for i, val in enumerate(mbeds):
98-
platform_name = str(val['platform_name'])
99-
if platform_name not in result:
100-
result[platform_name] = 1
101-
else:
102-
result[platform_name] += 1
103-
return result
104-
105-
@deprecated("List formatting methods are deprecated to simplify the API. "
106-
"Please use 'list_mbeds' instead.")
107-
def list_mbeds_by_targetid(self):
108-
"""! Get information about mbeds with extended parameters/info included
109-
@return Returns dictionary where keys are TargetIDs and values are mbed structures
110-
@details Ordered by target id (key: target_id).
111-
"""
112-
result = {}
113-
mbed_list = self.list_mbeds_ext()
114-
for mbed in mbed_list:
115-
target_id = mbed['target_id']
116-
result[target_id] = mbed
117-
return result
118-
119-
@deprecated("List formatting methods are deprecated to simplify the API. "
120-
"Please use 'list_mbeds' instead.")
121-
def get_string(self, border=False, header=True, padding_width=1, sortby='platform_name'):
122-
"""! Printing with some sql table like decorators
123-
@param border Table border visibility
124-
@param header Table header visibility
125-
@param padding_width Table padding
126-
@param sortby Column used to sort results
127-
@return Returns string which can be printed on console
128-
"""
129-
from prettytable import PrettyTable, HEADER
130-
result = ''
131-
mbeds = self.list_mbeds(unique_names=True, read_details_txt=True)
132-
if mbeds:
133-
""" ['platform_name', 'mount_point', 'serial_port', 'target_id'] - columns generated from USB auto-detection
134-
['platform_name_unique', ...] - columns generated outside detection subsystem (OS dependent detection)
135-
"""
136-
columns = ['platform_name', 'platform_name_unique', 'mount_point', 'serial_port', 'target_id', 'daplink_version']
137-
pt = PrettyTable(columns, junction_char="|", hrules=HEADER)
138-
for col in columns:
139-
pt.align[col] = 'l'
140-
141-
for mbed in mbeds:
142-
row = []
143-
for col in columns:
144-
row.append(mbed[col] if col in mbed and mbed[col] else 'unknown')
145-
pt.add_row(row)
146-
result = pt.get_string(border=border, header=header, padding_width=padding_width, sortby=sortby)
147-
return result
148-
149-
# Private functions supporting API
150-
151-
@deprecated("This method will be removed from the public API. "
152-
"Please use 'list_mbeds' instead")
153-
def get_json_data_from_file(self, json_spec_filename, verbose=False):
154-
"""! Loads from file JSON formatted string to data structure
155-
@return None if JSON can be loaded
156-
"""
157-
try:
158-
with open(json_spec_filename) as data_file:
159-
try:
160-
return json.load(data_file)
161-
except ValueError as json_error_msg:
162-
logger.error("Parsing file(%s): %s", json_spec_filename, json_error_msg)
163-
return None
164-
except IOError as fileopen_error_msg:
165-
logger.warning(fileopen_error_msg)
166-
return None
167-
168-
@deprecated("This method will be removed from the public API. "
169-
"Please use 'list_mbeds' instead")
170-
def get_htm_target_id(self, mount_point):
171-
target_id, _ = self._read_htm_ids(mount_point)
172-
return target_id
173-
174-
@deprecated("This method will be removed from the public API. "
175-
"Please use 'list_mbeds' instead")
176-
def get_mbed_htm(self, mount_point):
177-
_, build_info = self._read_htm_ids(mount_point)
178-
return build_info
179-
180-
@deprecated("This method will be removed from the public API. "
181-
"Please use 'list_mbeds' instead")
182-
def get_mbed_htm_comment_section_ver_build(self, line):
183-
return self._mbed_htm_comment_section_ver_build(line)
184-
185-
@deprecated("This method will be removed from the public API. "
186-
"Please use 'list_mbeds' instead")
187-
def get_mbed_htm_lines(self, mount_point):
188-
return self._htm_lines(mount_point)
189-
190-
@deprecated("This method will be removed from the public API. "
191-
"Please use 'list_mbeds' instead")
192-
def get_details_txt(self, mount_point):
193-
return self._details_txt(mount_point)
194-
195-
@deprecated("This method will be removed from the public API. "
196-
"Please use 'list_mbeds' instead")
197-
def parse_details_txt(self, lines):
198-
return self._parse_details(lines)
199-
200-
@deprecated("This method will be removed from the public API. "
201-
"Please use 'list_mbeds' instead")
202-
def scan_html_line_for_target_id(self, line):
203-
return self._target_id_from_htm(line)
204-
205-
@staticmethod
206-
@deprecated("This method will be removed from the public API. "
207-
"Please use 'list_mbeds' instead")
208-
def run_cli_process(cmd, shell=True):
209-
return MbedLsToolsBase._run_cli_process(cmd, shell)

packages/mbed-ls/test/mbedls_toolsbase.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ def test_list_mbeds_invalid_platform(self):
102102
'target_id_usb_id': u'not_in_target_db',
103103
'serial_port': "dummy_serial_port"}]
104104
for qos in [FSInteraction.BeforeFilter, FSInteraction.AfterFilter]:
105-
with patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase._read_htm_ids") as _read_htm,\
106-
patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready") as _mpr,\
105+
with patch("mbed_lstools.lstools_base.MbedLsToolsBase._read_htm_ids") as _read_htm,\
106+
patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as _mpr,\
107107
patch("mbed_os_tools.detect.platform_database.PlatformDatabase.get") as _get,\
108108
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir:
109109
_mpr.return_value = True
@@ -121,7 +121,7 @@ def test_list_mbeds_unmount_mid_read(self):
121121
self.base.return_value = [{'mount_point': 'dummy_mount_point',
122122
'target_id_usb_id': u'0240DEADBEEF',
123123
'serial_port': "dummy_serial_port"}]
124-
with patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready") as _mpr,\
124+
with patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as _mpr,\
125125
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir:
126126
_mpr.return_value = True
127127
_listdir.side_effect = OSError
@@ -133,7 +133,7 @@ def _test(mock):
133133
self.base.return_value = [{'mount_point': 'dummy_mount_point',
134134
'target_id_usb_id': u'0240DEADBEEF',
135135
'serial_port': "dummy_serial_port"}]
136-
with patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready") as _mpr,\
136+
with patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as _mpr,\
137137
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir,\
138138
patch('mbed_os_tools.detect.lstools_base.open', mock, create=True):
139139
_mpr.return_value = True
@@ -179,7 +179,7 @@ def _handle_open(*args, **kwargs):
179179
return DEFAULT
180180

181181
m = mock_open(read_data=details_txt_contents)
182-
with patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready") as _mpr,\
182+
with patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as _mpr,\
183183
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir,\
184184
patch('mbed_os_tools.detect.lstools_base.open', m, create=True) as mocked_open:
185185
mocked_open.side_effect = _handle_open
@@ -195,9 +195,9 @@ def _test(mock):
195195
self.base.return_value = [{'mount_point': 'dummy_mount_point',
196196
'target_id_usb_id': u'0240DEADBEEF',
197197
'serial_port': "dummy_serial_port"}]
198-
with patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready") as _mpr,\
198+
with patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as _mpr,\
199199
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir,\
200-
patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase._update_device_from_htm") as _htm,\
200+
patch("mbed_lstools.lstools_base.MbedLsToolsBase._update_device_from_htm") as _htm,\
201201
patch('mbed_os_tools.detect.lstools_base.open', mock, create=True):
202202
_mpr.return_value = True
203203
_htm.side_effect = None
@@ -219,7 +219,7 @@ def test_list_mbeds_unmount_mid_read_list_unmounted(self):
219219
self.base.return_value = [{'mount_point': 'dummy_mount_point',
220220
'target_id_usb_id': u'0240DEADBEEF',
221221
'serial_port': "dummy_serial_port"}]
222-
with patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready") as _mpr,\
222+
with patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as _mpr,\
223223
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir:
224224
_mpr.return_value = True
225225
_listdir.side_effect = OSError
@@ -357,8 +357,8 @@ def test_fs_never(self):
357357
'serial_port': 'invalid_serial_port'
358358
}
359359
self.base.return_value = [device]
360-
with patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase._update_device_from_fs") as _up_fs,\
361-
patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready") as mount_point_ready:
360+
with patch("mbed_lstools.lstools_base.MbedLsToolsBase._update_device_from_fs") as _up_fs,\
361+
patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as mount_point_ready:
362362
mount_point_ready.return_value = True
363363

364364
filter = None
@@ -395,9 +395,9 @@ def test_fs_after(self):
395395
'mount_point': 'invalid_mount_point',
396396
'serial_port': 'invalid_serial_port'
397397
}
398-
with patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase._read_htm_ids") as _read_htm,\
399-
patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase._details_txt") as _up_details,\
400-
patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready") as mount_point_ready,\
398+
with patch("mbed_lstools.lstools_base.MbedLsToolsBase._read_htm_ids") as _read_htm,\
399+
patch("mbed_lstools.lstools_base.MbedLsToolsBase._details_txt") as _up_details,\
400+
patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as mount_point_ready,\
401401
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir:
402402
new_device_id = "00017531642046"
403403
_read_htm.return_value = (new_device_id, {})
@@ -469,9 +469,9 @@ def test_fs_before(self):
469469
'mount_point': 'invalid_mount_point',
470470
'serial_port': 'invalid_serial_port'
471471
}
472-
with patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase._read_htm_ids") as _read_htm,\
473-
patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase._details_txt") as _up_details,\
474-
patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready") as mount_point_ready,\
472+
with patch("mbed_lstools.lstools_base.MbedLsToolsBase._read_htm_ids") as _read_htm,\
473+
patch("mbed_lstools.lstools_base.MbedLsToolsBase._details_txt") as _up_details,\
474+
patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as mount_point_ready,\
475475
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir:
476476
new_device_id = u'00017575430420'
477477
_read_htm.return_value = (new_device_id, {})
@@ -564,8 +564,8 @@ def test_list_mbeds_valid_platform(self):
564564
self.base.return_value = [{'mount_point': 'dummy_mount_point',
565565
'target_id_usb_id': u'0240DEADBEEF',
566566
'serial_port': None}]
567-
with patch('mbed_lstools.lstools_base.MbedDetectLsToolsBase._read_htm_ids') as _read_htm,\
568-
patch('mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready') as _mpr,\
567+
with patch('mbed_lstools.lstools_base.MbedLsToolsBase._read_htm_ids') as _read_htm,\
568+
patch('mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready') as _mpr,\
569569
patch('mbed_os_tools.detect.platform_database.PlatformDatabase.get') as _get,\
570570
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir:
571571
_mpr.return_value = True

src/mbed_os_tools/detect/darwin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from plistlib import readPlistFromString as loads
2424
from xml.parsers.expat import ExpatError
2525

26-
from .lstools_base import MbedDetectLsToolsBase
26+
from .lstools_base import MbedLsToolsBase
2727

2828
import logging
2929

@@ -108,12 +108,12 @@ def _dfs_usb_info(obj, parents):
108108
return output
109109

110110

111-
class MbedLsToolsDarwin(MbedDetectLsToolsBase):
111+
class MbedLsToolsDarwin(MbedLsToolsBase):
112112
""" mbed-enabled platform detection on Mac OS X
113113
"""
114114

115115
def __init__(self, **kwargs):
116-
MbedDetectLsToolsBase.__init__(self, **kwargs)
116+
MbedLsToolsBase.__init__(self, **kwargs)
117117
self.mac_version = float(".".join(platform.mac_ver()[0].split(".")[:2]))
118118

119119
def find_candidates(self):

src/mbed_os_tools/detect/linux.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import re
1717
import os
1818

19-
from .lstools_base import MbedDetectLsToolsBase
19+
from .lstools_base import MbedLsToolsBase
2020

2121
import logging
2222

@@ -35,14 +35,14 @@ def _readlink(link):
3535
return content
3636

3737

38-
class MbedLsToolsLinuxGeneric(MbedDetectLsToolsBase):
38+
class MbedLsToolsLinuxGeneric(MbedLsToolsBase):
3939
""" mbed-enabled platform for Linux with udev
4040
"""
4141

4242
def __init__(self, **kwargs):
4343
"""! ctor
4444
"""
45-
MbedDetectLsToolsBase.__init__(self, **kwargs)
45+
MbedLsToolsBase.__init__(self, **kwargs)
4646
self.nlp = re.compile(r"(pci|usb)-[0-9a-zA-Z:_-]*_(?P<usbid>[0-9a-zA-Z]*)-.*$")
4747
self.mmp = re.compile(r"(?P<dev>(/[^/ ]*)+) on (?P<dir>(/[^/ ]*)+) ")
4848
self.udp = re.compile(r"^[0-9]+-[0-9]+[^:\s]*$")

0 commit comments

Comments
 (0)