Path: blob/master/Tools/autotest/validate_board_list.py
9692 views
#!/usr/bin/env python312'''3Check Tools/bootloader/board_types.txt for problems45AP_FLAKE8_CLEAN67'''89import re101112class ValidateBoardList(object):1314class BoardType(object):15def __init__(self, name, board_id):16self.name = name17self.board_id = board_id1819def __init__(self):20self.filepath = "Tools/AP_Bootloader/board_types.txt"2122def read_filepath(self, filepath):23'''return contents of filepath'''24content = ""25with open(filepath) as fh:26content += fh.read()27fh.close()28return content2930def parse_filepath_content(self, filepath):31'''read contents of filepath, returns a list of (id, name) tuples'''32content = self.read_filepath(filepath)33ret = []34for line in content.split("\n"):35# strip comments:36line = re.sub("#.*", "", line)37# remove empty lines:38if not len(line) or line.isspace():39continue40# remove trailing whitespace41line = line.rstrip()42m = re.match(r"^(.*?)\s+(\d+)$", line)43if m is None:44raise ValueError("Failed to match (%s)" % line)45print("line: (%s)" % str(line))46ret.append((int(m.group(2)), m.group(1)))47return ret4849def validate_filepath_content(self, tuples):50'''validate a list of (id, name) tuples'''5152# a list of board IDs which can map to multiple names for53# historical reasons:54board_id_whitelist = frozenset([559, # fmuv2 and fmuv35610, # TARGET_HW_PX4_FMU_V4_PRO and TARGET_HW_PX4_PIO_V35713, # TARGET_HW_PX4_FMU_V4_PRO and TARGET_HW_PX4_PIO_V35829, # TARGET_HW_AV_V1 and TARGET_HW_AV_X_V15951, # TARGET_HW_PX4_FMU_V5X and Reserved PX4 [BL] FMU v5X.x6052, # TARGET_HW_PX4_FMU_V6 and Reserved "PX4 [BL] FMU v6.x"6153, # TARGET_HW_PX4_FMU_V6X and Reserved "PX4 [BL] FMU v6X.x"6257, # TARGET_HW_ARK_FMU_V6X and Reserved "ARK [BL] FMU v6X.x"6359, # TARGET_HW_ARK_FPV and Reserved "ARK [BL] FPV"6480, # TARGET_HW_ARK_CAN_FLOW and Reserved "ARK CAN FLOW"6520, # TARGET_HW_UVIFY_CORE and AP_HW_F4BY66])6768dict_by_id = {}69dict_by_name = {}70for (board_id, name) in tuples:71print("Checking (%u, %s)" % (board_id, name))72if board_id in dict_by_id and board_id not in board_id_whitelist:73raise ValueError("Duplicate ID %s in file for (%s) and (%s)" %74(board_id, dict_by_id[board_id], name))75if name in dict_by_name:76raise ValueError("Duplicate name %s in file for (%s) and (%s)" %77(name, dict_by_name[name], board_id))78dict_by_name[name] = board_id79dict_by_id[board_id] = name8081def run(self):82parsed = self.parse_filepath_content(self.filepath)83self.validate_filepath_content(parsed)84return 0858687if __name__ == '__main__':88validator = ValidateBoardList()89validator.run()909192