def parse_id_to_devices(self, tid): """ :param tid: target id """ flasher = Flash() available = flasher.get_available_device_mapping() target_ids = [] available_target_ids = [] if not available: print("Could not find any connected device") return EXIT_CODE_DEVICES_MISSING if 'all' in tid: for device in available: target_ids.append(device['target_id']) else: for item in tid: for device in available: available_target_ids.append(device['target_id']) if device['target_id'] == item or \ device['target_id'].startswith(item): if device['target_id'] not in target_ids: target_ids.append(device['target_id']) if not target_ids: print("Could not find given target_id from attached devices") print("Available target_ids:") print(available_target_ids) return EXIT_CODE_COULD_NOT_MAP_DEVICE if len(target_ids) == 1: return target_ids[0] return target_ids
def subcmd_flash_handler(self, args): """ flash command handler """ flasher = Flash() available = flasher.get_available_device_mapping() available_target_ids = [] retcode = 0 #print(args) if args.input: if not isfile(args.input): print("Could not find given file: %s" % args.input) return EXIT_CODE_FILE_MISSING else: print("File is missing") return EXIT_CODE_FILE_MISSING if args.platform_name: if args.platform_name not in flasher.get_supported_targets(): print("Not supported platform: %s" % args.platform_name) print("Supported platforms: %s" % flasher.get_supported_targets()) return EXIT_CODE_NOT_SUPPORTED_PLATFORM if not args.tid: print("Target_id is missing") return EXIT_CODE_NO_TARGET_ID if 'all' in args.tid: retcode = flasher.flash(build=args.input, target_id='all', platform_name=args.platform_name, method=args.method, no_reset=args.no_reset) if len(available) <= 0: print("Could not find any connected device") return EXIT_CODE_DEVICES_MISSING available_platforms, target_ids_to_flash = \ self.prepare_platforms_and_targets(available, args.tid, available_target_ids) if not target_ids_to_flash: print("Could not find given target_id from attached devices") print("Available target_ids:") print(available_target_ids) return EXIT_CODE_COULD_NOT_MAP_DEVICE elif len(available_platforms) > 1: if not args.platform_name: print("More than one platform detected for given target_id") print("Please specify the platform with -t <PLATFORM_NAME>") print("Found platforms:") print(available_platforms) return EXIT_CODE_PLATFORM_REQUIRED else: #print(target_ids_to_flash) retcode = flasher.flash(build=args.input, target_id=target_ids_to_flash, platform_name=available_platforms[0], method=args.method, no_reset=args.no_reset) return retcode