Skip to content

Commit 3c43330

Browse files
committed
Moving deprecated mbed-ls functions into detect module
1 parent 16109cd commit 3c43330

File tree

2 files changed

+181
-186
lines changed

2 files changed

+181
-186
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)

src/mbed_os_tools/detect/lstools_base.py

Lines changed: 180 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from os import listdir
2121
from os.path import expanduser, isfile, join, exists, isdir
2222
import logging
23+
import functools
24+
import json
2325

2426
from .platform_database import (
2527
PlatformDatabase,
@@ -34,13 +36,25 @@
3436
logger.addHandler(logging.NullHandler())
3537

3638

39+
def deprecated(reason):
40+
"""Deprecate a function/method with a decorator"""
41+
def actual_decorator(func):
42+
@functools.wraps(func)
43+
def new_func(*args, **kwargs):
44+
logger.warning("Call to deprecated function %s. %s",
45+
func.__name__, reason)
46+
return func(*args, **kwargs)
47+
return new_func
48+
return actual_decorator
49+
50+
3751
class FSInteraction(object):
3852
BeforeFilter = 1
3953
AfterFilter = 2
4054
Never = 3
4155

4256

43-
class MbedDetectLsToolsBase(object):
57+
class MbedLsToolsBase(object):
4458
""" Base class for mbed-lstools, defines mbed-ls tools interface for
4559
mbed-enabled devices detection for various hosts
4660
"""
@@ -573,3 +587,168 @@ def _run_cli_process(cmd, shell=True):
573587
p = Popen(cmd, shell=shell, stdout=PIPE, stderr=PIPE)
574588
_stdout, _stderr = p.communicate()
575589
return _stdout, _stderr, p.returncode
590+
591+
@deprecated("Functionality has been moved into 'list_mbeds'. "
592+
"Please use list_mbeds with 'unique_names=True' and "
593+
"'read_details_txt=True'")
594+
def list_mbeds_ext(self):
595+
"""! Function adds extra information for each mbed device
596+
@return Returns list of mbed devices plus extended data like 'platform_name_unique'
597+
@details Get information about mbeds with extended parameters/info included
598+
"""
599+
600+
return self.list_mbeds(unique_names=True, read_details_txt=True)
601+
602+
@deprecated("List formatting methods are deprecated for a simpler API. "
603+
"Please use 'list_mbeds' instead.")
604+
def list_manufacture_ids(self):
605+
"""! Creates list of all available mappings for target_id -> Platform
606+
@return String with table formatted output
607+
"""
608+
from prettytable import PrettyTable, HEADER
609+
610+
columns = ['target_id_prefix', 'platform_name']
611+
pt = PrettyTable(columns, junction_char="|", hrules=HEADER)
612+
for col in columns:
613+
pt.align[col] = 'l'
614+
615+
for target_id_prefix, platform_name in sorted(self.plat_db.items()):
616+
pt.add_row([target_id_prefix, platform_name])
617+
618+
return pt.get_string()
619+
620+
@deprecated("List formatting methods are deprecated to simplify the API. "
621+
"Please use 'list_mbeds' instead.")
622+
def list_platforms(self):
623+
"""! Useful if you just want to know which platforms are currently available on the system
624+
@return List of (unique values) available platforms
625+
"""
626+
result = []
627+
mbeds = self.list_mbeds()
628+
for i, val in enumerate(mbeds):
629+
platform_name = str(val['platform_name'])
630+
if platform_name not in result:
631+
result.append(platform_name)
632+
return result
633+
634+
@deprecated("List formatting methods are deprecated to simplify the API. "
635+
"Please use 'list_mbeds' instead.")
636+
def list_platforms_ext(self):
637+
"""! Useful if you just want to know how many platforms of each type are currently available on the system
638+
@return Dict of platform: platform_count
639+
"""
640+
result = {}
641+
mbeds = self.list_mbeds()
642+
for i, val in enumerate(mbeds):
643+
platform_name = str(val['platform_name'])
644+
if platform_name not in result:
645+
result[platform_name] = 1
646+
else:
647+
result[platform_name] += 1
648+
return result
649+
650+
@deprecated("List formatting methods are deprecated to simplify the API. "
651+
"Please use 'list_mbeds' instead.")
652+
def list_mbeds_by_targetid(self):
653+
"""! Get information about mbeds with extended parameters/info included
654+
@return Returns dictionary where keys are TargetIDs and values are mbed structures
655+
@details Ordered by target id (key: target_id).
656+
"""
657+
result = {}
658+
mbed_list = self.list_mbeds_ext()
659+
for mbed in mbed_list:
660+
target_id = mbed['target_id']
661+
result[target_id] = mbed
662+
return result
663+
664+
@deprecated("List formatting methods are deprecated to simplify the API. "
665+
"Please use 'list_mbeds' instead.")
666+
def get_string(self, border=False, header=True, padding_width=1, sortby='platform_name'):
667+
"""! Printing with some sql table like decorators
668+
@param border Table border visibility
669+
@param header Table header visibility
670+
@param padding_width Table padding
671+
@param sortby Column used to sort results
672+
@return Returns string which can be printed on console
673+
"""
674+
from prettytable import PrettyTable, HEADER
675+
result = ''
676+
mbeds = self.list_mbeds(unique_names=True, read_details_txt=True)
677+
if mbeds:
678+
""" ['platform_name', 'mount_point', 'serial_port', 'target_id'] - columns generated from USB auto-detection
679+
['platform_name_unique', ...] - columns generated outside detection subsystem (OS dependent detection)
680+
"""
681+
columns = ['platform_name', 'platform_name_unique', 'mount_point', 'serial_port', 'target_id', 'daplink_version']
682+
pt = PrettyTable(columns, junction_char="|", hrules=HEADER)
683+
for col in columns:
684+
pt.align[col] = 'l'
685+
686+
for mbed in mbeds:
687+
row = []
688+
for col in columns:
689+
row.append(mbed[col] if col in mbed and mbed[col] else 'unknown')
690+
pt.add_row(row)
691+
result = pt.get_string(border=border, header=header, padding_width=padding_width, sortby=sortby)
692+
return result
693+
694+
# Private functions supporting API
695+
696+
@deprecated("This method will be removed from the public API. "
697+
"Please use 'list_mbeds' instead")
698+
def get_json_data_from_file(self, json_spec_filename, verbose=False):
699+
"""! Loads from file JSON formatted string to data structure
700+
@return None if JSON can be loaded
701+
"""
702+
try:
703+
with open(json_spec_filename) as data_file:
704+
try:
705+
return json.load(data_file)
706+
except ValueError as json_error_msg:
707+
logger.error("Parsing file(%s): %s", json_spec_filename, json_error_msg)
708+
return None
709+
except IOError as fileopen_error_msg:
710+
logger.warning(fileopen_error_msg)
711+
return None
712+
713+
@deprecated("This method will be removed from the public API. "
714+
"Please use 'list_mbeds' instead")
715+
def get_htm_target_id(self, mount_point):
716+
target_id, _ = self._read_htm_ids(mount_point)
717+
return target_id
718+
719+
@deprecated("This method will be removed from the public API. "
720+
"Please use 'list_mbeds' instead")
721+
def get_mbed_htm(self, mount_point):
722+
_, build_info = self._read_htm_ids(mount_point)
723+
return build_info
724+
725+
@deprecated("This method will be removed from the public API. "
726+
"Please use 'list_mbeds' instead")
727+
def get_mbed_htm_comment_section_ver_build(self, line):
728+
return self._mbed_htm_comment_section_ver_build(line)
729+
730+
@deprecated("This method will be removed from the public API. "
731+
"Please use 'list_mbeds' instead")
732+
def get_mbed_htm_lines(self, mount_point):
733+
return self._htm_lines(mount_point)
734+
735+
@deprecated("This method will be removed from the public API. "
736+
"Please use 'list_mbeds' instead")
737+
def get_details_txt(self, mount_point):
738+
return self._details_txt(mount_point)
739+
740+
@deprecated("This method will be removed from the public API. "
741+
"Please use 'list_mbeds' instead")
742+
def parse_details_txt(self, lines):
743+
return self._parse_details(lines)
744+
745+
@deprecated("This method will be removed from the public API. "
746+
"Please use 'list_mbeds' instead")
747+
def scan_html_line_for_target_id(self, line):
748+
return self._target_id_from_htm(line)
749+
750+
@staticmethod
751+
@deprecated("This method will be removed from the public API. "
752+
"Please use 'list_mbeds' instead")
753+
def run_cli_process(cmd, shell=True):
754+
return MbedLsToolsBase._run_cli_process(cmd, shell)

0 commit comments

Comments
 (0)