diff --git a/tools/detect_targets.py b/tools/detect_targets.py index bf70c1c024..c3474a8e1c 100644 --- a/tools/detect_targets.py +++ b/tools/detect_targets.py @@ -31,9 +31,13 @@ check_required_modules(['prettytable']) # Imports related to mbed build api from tools.build_api import mcu_toolchain_matrix from tools.test_api import get_autodetected_MUTS_list -from tools.test_api import get_mounted_details_txt +from tools.test_api import get_module_avail from argparse import ArgumentParser +try: + import mbed_lstools +except: + pass def main(): """Entry Point""" @@ -76,17 +80,17 @@ def main(): count = 0 for mut in muts.values(): if re.match(mcu_filter, mut['mcu']): - # Grab additional target details about the mut - details_txt = get_mounted_details_txt(mut['disk']) + interface_version = get_interface_version(mut['disk']) print "" - print "[mbed] Detected %s, port %s, mounted %s, interface version %s" % \ - (mut['mcu'], mut['port'], mut['disk'], details_txt['Interface Version']) + print "[mbed] Detected %s, port %s, mounted %s, interface version %s:" % \ + (mut['mcu'], mut['port'], mut['disk'], interface_version) + print "[mbed] Supported toolchains for %s" % mut['mcu'] print mcu_toolchain_matrix(platform_filter=mut['mcu']) count += 1 if count == 0: - print "[mbed] No mbed targets where detected on your system." + print "[mbed] No mbed targets were detected on your system." except KeyboardInterrupt: print "\n[CTRL+c] exit" @@ -95,6 +99,23 @@ def main(): traceback.print_exc(file=sys.stdout) print "[ERROR] %s" % str(exc) sys.exit(1) + +def get_interface_version(mount_point): + """ Function returns interface version from the target mounted on the specified mount point + mount_point = mut['port'] + @param mount_point Name of disk where platform is connected to host machine. + """ + if get_module_avail('mbed_lstools'): + mbeds = mbed_lstools.create() + details_txt = mbeds.get_details_txt(mount_point) + + if 'Interface Version' in details_txt: + return details_txt['Interface Version'] + + elif 'Version' in details_txt: + return details_txt['Version'] + + return 'unknown' if __name__ == '__main__': main() diff --git a/tools/test_api.py b/tools/test_api.py index 13fac4cbe3..c97e499dc5 100644 --- a/tools/test_api.py +++ b/tools/test_api.py @@ -1643,17 +1643,10 @@ def detect_database_verbose(db_url): def get_module_avail(module_name): - """ This function returns True if module_name is already impored module + """ This function returns True if module_name is already imported module """ return module_name in sys.modules.keys() -def get_mounted_details_txt(mount_point): - """ Function returns object containing details.txt information from the specified mount point - @param mount_point Name of disk where platform is connected to host machine. - """ - mbeds = mbed_lstools.create() - return mbeds.get_details_txt(mount_point) - def get_autodetected_MUTS_list(platform_name_filter=None): oldError = None if os.name == 'nt':