Clone of official tools
detect_targets.py@43:2a7da56ebd24, 2018-09-25 (annotated)
- Committer:
- theotherjimmy
- Date:
- Tue Sep 25 13:43:09 2018 -0500
- Revision:
- 43:2a7da56ebd24
- Parent:
- 41:2a77626a4c21
Release 5.10.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
screamer | 13:ab47a20b66f0 | 1 | #! /usr/bin/env python2 |
screamer | 13:ab47a20b66f0 | 2 | """ |
screamer | 13:ab47a20b66f0 | 3 | mbed SDK |
screamer | 13:ab47a20b66f0 | 4 | Copyright (c) 2011-2013 ARM Limited |
screamer | 13:ab47a20b66f0 | 5 | |
screamer | 13:ab47a20b66f0 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
screamer | 13:ab47a20b66f0 | 7 | you may not use this file except in compliance with the License. |
screamer | 13:ab47a20b66f0 | 8 | You may obtain a copy of the License at |
screamer | 13:ab47a20b66f0 | 9 | |
screamer | 13:ab47a20b66f0 | 10 | http://www.apache.org/licenses/LICENSE-2.0 |
screamer | 13:ab47a20b66f0 | 11 | |
screamer | 13:ab47a20b66f0 | 12 | Unless required by applicable law or agreed to in writing, software |
screamer | 13:ab47a20b66f0 | 13 | distributed under the License is distributed on an "AS IS" BASIS, |
screamer | 13:ab47a20b66f0 | 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
screamer | 13:ab47a20b66f0 | 15 | See the License for the specific language governing permissions and |
screamer | 13:ab47a20b66f0 | 16 | limitations under the License. |
screamer | 13:ab47a20b66f0 | 17 | """ |
theotherjimmy |
43:2a7da56ebd24 | 18 | from __future__ import print_function |
screamer | 13:ab47a20b66f0 | 19 | import sys |
screamer | 13:ab47a20b66f0 | 20 | import os |
The Other Jimmy |
35:da9c89f8be7d | 21 | import re |
screamer | 13:ab47a20b66f0 | 22 | |
screamer | 13:ab47a20b66f0 | 23 | ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) |
screamer | 13:ab47a20b66f0 | 24 | sys.path.insert(0, ROOT) |
screamer | 13:ab47a20b66f0 | 25 | |
screamer | 13:ab47a20b66f0 | 26 | from tools.options import get_default_options_parser |
screamer | 13:ab47a20b66f0 | 27 | |
screamer | 13:ab47a20b66f0 | 28 | # Check: Extra modules which are required by core test suite |
screamer | 13:ab47a20b66f0 | 29 | from tools.utils import check_required_modules |
screamer | 13:ab47a20b66f0 | 30 | check_required_modules(['prettytable']) |
screamer | 13:ab47a20b66f0 | 31 | |
screamer | 13:ab47a20b66f0 | 32 | # Imports related to mbed build api |
screamer | 13:ab47a20b66f0 | 33 | from tools.build_api import mcu_toolchain_matrix |
screamer | 13:ab47a20b66f0 | 34 | from tools.test_api import get_autodetected_MUTS_list |
theotherjimmy |
41:2a77626a4c21 | 35 | from tools.test_api import get_module_avail |
The Other Jimmy |
35:da9c89f8be7d | 36 | from argparse import ArgumentParser |
screamer | 13:ab47a20b66f0 | 37 | |
theotherjimmy |
41:2a77626a4c21 | 38 | try: |
theotherjimmy |
41:2a77626a4c21 | 39 | import mbed_lstools |
theotherjimmy |
41:2a77626a4c21 | 40 | except: |
theotherjimmy |
41:2a77626a4c21 | 41 | pass |
screamer | 13:ab47a20b66f0 | 42 | |
screamer | 29:1210849dba19 | 43 | def main(): |
screamer | 29:1210849dba19 | 44 | """Entry Point""" |
screamer | 13:ab47a20b66f0 | 45 | try: |
screamer | 13:ab47a20b66f0 | 46 | # Parse Options |
The Other Jimmy |
35:da9c89f8be7d | 47 | parser = ArgumentParser() |
screamer | 13:ab47a20b66f0 | 48 | |
screamer | 22:9e85236d8716 | 49 | parser.add_argument("-S", "--supported-toolchains", |
screamer | 29:1210849dba19 | 50 | action="store_true", |
screamer | 29:1210849dba19 | 51 | dest="supported_toolchains", |
screamer | 29:1210849dba19 | 52 | default=False, |
screamer | 29:1210849dba19 | 53 | help="Displays supported matrix of" |
screamer | 29:1210849dba19 | 54 | " targets and toolchains") |
screamer | 13:ab47a20b66f0 | 55 | |
screamer | 22:9e85236d8716 | 56 | parser.add_argument('-f', '--filter', |
screamer | 29:1210849dba19 | 57 | dest='general_filter_regex', |
screamer | 29:1210849dba19 | 58 | default=None, |
screamer | 29:1210849dba19 | 59 | help='Filter targets') |
screamer | 13:ab47a20b66f0 | 60 | |
screamer | 22:9e85236d8716 | 61 | parser.add_argument("-v", "--verbose", |
screamer | 29:1210849dba19 | 62 | action="store_true", |
screamer | 29:1210849dba19 | 63 | dest="verbose", |
screamer | 29:1210849dba19 | 64 | default=False, |
screamer | 29:1210849dba19 | 65 | help="Verbose diagnostic output") |
screamer | 13:ab47a20b66f0 | 66 | |
screamer | 22:9e85236d8716 | 67 | options = parser.parse_args() |
screamer | 13:ab47a20b66f0 | 68 | |
screamer | 13:ab47a20b66f0 | 69 | # Only prints matrix of supported toolchains |
screamer | 13:ab47a20b66f0 | 70 | if options.supported_toolchains: |
theotherjimmy |
43:2a7da56ebd24 | 71 | print(mcu_toolchain_matrix( |
theotherjimmy |
43:2a7da56ebd24 | 72 | platform_filter=options.general_filter_regex)) |
screamer | 13:ab47a20b66f0 | 73 | exit(0) |
screamer | 13:ab47a20b66f0 | 74 | |
screamer | 13:ab47a20b66f0 | 75 | # If auto_detect attribute is present, we assume other auto-detection |
screamer | 13:ab47a20b66f0 | 76 | # parameters like 'toolchains_filter' are also set. |
screamer | 29:1210849dba19 | 77 | muts = get_autodetected_MUTS_list() |
screamer | 13:ab47a20b66f0 | 78 | |
The Other Jimmy |
35:da9c89f8be7d | 79 | mcu_filter = options.general_filter_regex or ".*" |
The Other Jimmy |
35:da9c89f8be7d | 80 | |
screamer | 13:ab47a20b66f0 | 81 | count = 0 |
screamer | 29:1210849dba19 | 82 | for mut in muts.values(): |
theotherjimmy |
43:2a7da56ebd24 | 83 | if re.match(mcu_filter, mut['mcu'] or "Unknown"): |
theotherjimmy |
41:2a77626a4c21 | 84 | interface_version = get_interface_version(mut['disk']) |
theotherjimmy |
43:2a7da56ebd24 | 85 | print("") |
theotherjimmy |
43:2a7da56ebd24 | 86 | print("[mbed] Detected %s, port %s, mounted %s, interface " |
theotherjimmy |
43:2a7da56ebd24 | 87 | "version %s:" % |
theotherjimmy |
43:2a7da56ebd24 | 88 | (mut['mcu'], mut['port'], mut['disk'], interface_version)) |
theotherjimmy |
43:2a7da56ebd24 | 89 | print("[mbed] Supported toolchains for %s" % mut['mcu']) |
theotherjimmy |
43:2a7da56ebd24 | 90 | print(mcu_toolchain_matrix(platform_filter=mut['mcu'])) |
The Other Jimmy |
35:da9c89f8be7d | 91 | count += 1 |
screamer | 29:1210849dba19 | 92 | |
screamer | 13:ab47a20b66f0 | 93 | if count == 0: |
theotherjimmy |
43:2a7da56ebd24 | 94 | print("[mbed] No mbed targets were detected on your system.") |
screamer | 13:ab47a20b66f0 | 95 | |
screamer | 29:1210849dba19 | 96 | except KeyboardInterrupt: |
theotherjimmy |
43:2a7da56ebd24 | 97 | print("\n[CTRL+c] exit") |
screamer | 29:1210849dba19 | 98 | except Exception as exc: |
screamer | 13:ab47a20b66f0 | 99 | import traceback |
screamer | 13:ab47a20b66f0 | 100 | traceback.print_exc(file=sys.stdout) |
theotherjimmy |
43:2a7da56ebd24 | 101 | print("[ERROR] %s" % str(exc)) |
screamer | 13:ab47a20b66f0 | 102 | sys.exit(1) |
theotherjimmy |
41:2a77626a4c21 | 103 | |
theotherjimmy |
41:2a77626a4c21 | 104 | def get_interface_version(mount_point): |
theotherjimmy |
41:2a77626a4c21 | 105 | """ Function returns interface version from the target mounted on the specified mount point |
theotherjimmy |
41:2a77626a4c21 | 106 | |
theotherjimmy |
41:2a77626a4c21 | 107 | mount_point can be acquired via the following: |
theotherjimmy |
41:2a77626a4c21 | 108 | muts = get_autodetected_MUTS_list() |
theotherjimmy |
41:2a77626a4c21 | 109 | for mut in muts.values(): |
theotherjimmy |
41:2a77626a4c21 | 110 | mount_point = mut['disk'] |
theotherjimmy |
41:2a77626a4c21 | 111 | |
theotherjimmy |
41:2a77626a4c21 | 112 | @param mount_point Name of disk where platform is connected to host machine. |
theotherjimmy |
41:2a77626a4c21 | 113 | """ |
theotherjimmy |
41:2a77626a4c21 | 114 | if get_module_avail('mbed_lstools'): |
theotherjimmy |
41:2a77626a4c21 | 115 | try : |
theotherjimmy |
43:2a7da56ebd24 | 116 | mbedls = mbed_lstools.create() |
theotherjimmy |
43:2a7da56ebd24 | 117 | mbeds = mbedls.list_mbeds(unique_names=True, read_details_txt=True) |
theotherjimmy |
41:2a77626a4c21 | 118 | |
theotherjimmy |
43:2a7da56ebd24 | 119 | for mbed in mbeds: |
theotherjimmy |
43:2a7da56ebd24 | 120 | if mbed['mount_point'] == mount_point: |
theotherjimmy |
41:2a77626a4c21 | 121 | |
theotherjimmy |
43:2a7da56ebd24 | 122 | if 'daplink_version' in mbed: |
theotherjimmy |
43:2a7da56ebd24 | 123 | return mbed['daplink_version'] |
theotherjimmy |
41:2a77626a4c21 | 124 | except : |
theotherjimmy |
41:2a77626a4c21 | 125 | return 'unknown' |
theotherjimmy |
41:2a77626a4c21 | 126 | |
theotherjimmy |
41:2a77626a4c21 | 127 | return 'unknown' |
screamer | 29:1210849dba19 | 128 | |
screamer | 29:1210849dba19 | 129 | if __name__ == '__main__': |
screamer | 29:1210849dba19 | 130 | main() |