|
21 | 21 |
|
22 | 22 | from mbed_os_tools.detect.lstools_base import (
|
23 | 23 | FSInteraction,
|
24 |
| - MbedDetectLsToolsBase, |
| 24 | + MbedLsToolsBase, |
25 | 25 | )
|
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) |
0 commit comments