Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/autotest/validate_board_list.py
Views: 1798
#!/usr/bin/env python12'''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"6380, # TARGET_HW_ARK_CAN_FLOW and Reserved "ARK CAN FLOW"6420, # TARGET_HW_UVIFY_CORE and AP_HW_F4BY65])6667dict_by_id = {}68dict_by_name = {}69for (board_id, name) in tuples:70print("Checking (%u, %s)" % (board_id, name))71if board_id in dict_by_id and board_id not in board_id_whitelist:72raise ValueError("Duplicate ID %s in file for (%s) and (%s)" %73(board_id, dict_by_id[board_id], name))74if name in dict_by_name:75raise ValueError("Duplicate name %s in file for (%s) and (%s)" %76(name, dict_by_name[name], board_id))77dict_by_name[name] = board_id78dict_by_id[board_id] = name7980def run(self):81parsed = self.parse_filepath_content(self.filepath)82self.validate_filepath_content(parsed)83return 0848586if __name__ == '__main__':87validator = ValidateBoardList()88validator.run()899091