def getBoardList(path): board_list = [] board_file_dict = {} processors_of_board = {} usb_types_of_board = {} keyboard_layouts_of_board = {} info_file = os.path.join(path, 'boards.txt') if os.path.isfile(info_file): text = utils.readFile(info_file) blocks = utils.readFile(info_file, mode = 'blocks') if '.container=' in text: for block in blocks: processor_list = [] has_processor = False for line in block: if '.name=' in line: (key, board) = utils.getKeyValue(line) if '.container=' in line: (key, board) = utils.getKeyValue(line) has_processor = True break if '.cpu=' in line: (key, cpu) = utils.getKeyValue(line) if not has_processor: board_list.append(board) board_file_dict[board] = info_file processors_of_board[board] = processor_list else: if not board in board_list: board_list.append(board) board_file_dict[board] = info_file processors_of_board[board] = processor_list processors_of_board[board].append(cpu) else: for block in blocks: if block: line = block[0] (key, board) = utils.getKeyValue(line) board_list.append(board) processor_list = [] usb_types = [] keyboard_layouts = [] processor_blocks = utils.getBlocks(block, sep = '## ') for processor_block in processor_blocks: if processor_block: processor_line = processor_block[0] (key, processor) = utils.getKeyValue(processor_line) processor_list.append(processor) processors_of_board[board] = processor_list usb_types_of_board[board] = usb_types keyboard_layouts_of_board[board] = keyboard_layouts board_file_dict[board] = info_file return (board_list, board_file_dict, processors_of_board, usb_types_of_board, keyboard_layouts_of_board)
def genInfoDictFromBlock(info_block): info_key_list = [] info_dict = {} name_line = info_block[0] (name_key, name) = utils.getKeyValue(name_line) name_key = name_key.replace('.name', '.') if name_key[-1] != '.': name_key += '.' for line in info_block[1:]: (key, value) = utils.getKeyValue(line) key = key.replace(name_key, '') info_key_list.append(key) info_dict[key] = value return (info_key_list, info_dict)
def getTeensyBoardList(path): board_list = [] board_file_dict = {} processors_of_board = {} usb_types_of_board = {} keyboard_layouts_of_board = {} info_file = os.path.join(path, 'boards.txt') if os.path.isfile(info_file): text = utils.readFile(info_file) lines = utils.readFile(info_file, mode = 'lines') menu_lines = [] for line in lines: if 'menu' in line: menu_lines.append(line) else: break menu_items = [] menu_item_caption_dict = {} for line in menu_lines: (key, value) = utils.getKeyValue(line) menu_items.append(key) menu_item_caption_dict[key] = value blocks = utils.readFile(info_file, mode = 'blocks') for block in blocks: (key, board) = utils.getKeyValue(block[0]) board_list.append(board) board_file_dict[board] = info_file usb_types = [] processors = [] keyboard_layouts = [] is_menu = False for line in block: if not is_menu: if menu_items[0] in line: is_menu = True if is_menu: if 'name' in line and not '#' in line: (key, value) = utils.getKeyValue(line) if 'usb' in key: usb_types.append(value) elif 'speed' in key: processors.append(value) elif 'keys' in key: keyboard_layouts.append(value) usb_types_of_board[board] = usb_types processors_of_board[board] = processors keyboard_layouts_of_board[board] = keyboard_layouts return (board_list, board_file_dict, processors_of_board, usb_types_of_board, keyboard_layouts_of_board)
def getBoardInfoBlock150(board_file_path, board): board_info_block = [] lines = osfile.readFileLines(board_file_path) info_block_list = utils.splitToBlocks(lines, sep = '.name') for info_block in info_block_list: for line in info_block: if '.name' in line: (key, board_name) = utils.getKeyValue(line) if '.container' in line: (key, board_name) = utils.getKeyValue(line) break if board_name == board: board_info_block = info_block break return board_info_block
def genLangList(self): plugin_root = utils.getPluginRoot() lang_dir = os.path.join(plugin_root, 'lang') files = os.listdir(lang_dir) for lang_file in files: lang_file = os.path.join(lang_dir, lang_file) if os.path.isfile(lang_file): f = open(lang_file, 'r') lines = f.readlines() f.close() for line in lines: (key, value) = utils.getKeyValue(line) if key == 'LANG': value = value.decode('utf-8', 'replace') pattern = re.compile(r'\([\S\s]+\)') match = pattern.search(value) if match: lang = match.group()[1:-1] else: lang = value self.lang_list.append(lang) self.lang_text_dict[lang] = value self.file_dict[value] = lang_file break self.lang_list.sort()
def getPlatformFromFile(platform_file_path): lines = osfile.readFileLines(platform_file_path) for line in lines: if 'name=' in line: (key, value) = utils.getKeyValue(line) platform = value break return platform
def getProgrammerInfoBlock(programmer_file_path, programmer): lines = osfile.readFileLines(programmer_file_path) info_block_list = utils.splitToBlocks(lines, sep = '.name') for info_block in info_block_list: programmer_name_line = info_block[0] (key, programmer_name) = utils.getKeyValue(programmer_name_line) if programmer_name == programmer: programmer_info_block = info_block break return programmer_info_block
def getBoardInfoBlock(board_file_path, board): board_info_block = [] lines = osfile.readFileLines(board_file_path) info_block_list = utils.splitToBlocks(lines, sep = '.name', none_sep = 'menu.') for info_block in info_block_list: board_name_line = info_block[0] (key, board_name) = utils.getKeyValue(board_name_line) if board_name == board: board_info_block = info_block break return board_info_block
def parseBoardHeader(boards_file_header_block): board_type_list = [] board_type_caption_dict = {} for line in boards_file_header_block: line = line.strip() if line and (not '#' in line): if '=' in line: (board_type, board_type_caption) = utils.getKeyValue(line) if not board_type in board_type_list: board_type_list.append(board_type) board_type_caption_dict[board_type] = board_type_caption return (board_type_list, board_type_caption_dict)
def parseBoardFile(platform, boards_file_path): board_list = [] board_file_dict = {} board_type_list_dict = {} board_item_list_dict = {} type_caption_dict = {} (boards_file_header_block, boards_file_body_block) = splitBoardsFile(boards_file_path) (board_type_list, board_type_caption_dict) = parseBoardHeader(boards_file_header_block) for board_type in board_type_caption_dict: type_key = utils.genKey(board_type, platform) type_caption_dict[type_key] = board_type_caption_dict[board_type] board_info_block_list = utils.splitToBlocks(boards_file_body_block, sep = '.name', none_sep = 'menu.') for board_info_block in board_info_block_list: board_name_line = board_info_block[0] (key, board) = utils.getKeyValue(board_name_line) if not board in board_list: board_list.append(board) board_key = utils.genKey(board, platform) board_file_dict[board_key] = boards_file_path board_type_list_dict[board_key] = [] for board_type in board_type_list: item_list = [] board_type_info_block = utils.getTypeInfoBlock(board_info_block, board_type) item_blocks = utils.splitToBlocks(board_type_info_block, sep = '.name', key_length = 4) for item_block in item_blocks: item_name_line = item_block[0] (key, item) = utils.getKeyValue(item_name_line) if not item in item_list: item_list.append(item) if item_list: board_type_list_dict[board_key].append(board_type) key = utils.genKey(board_type, board_key) board_item_list_dict[key] = item_list return (board_list, board_file_dict, board_type_list_dict, board_item_list_dict, type_caption_dict)
def parsePlatformInfo(platform_file_path): platform_info_key_list = [] platform_info_dict = {} lines = osfile.readFileLines(platform_file_path) for line in lines: line = line.strip() if line and (not '#' in line): (key, value) = utils.getKeyValue(line) if 'tools.' in key: key = regulariseToolsKey(key) platform_info_key_list.append(key) platform_info_dict[key] = value return (platform_info_key_list, platform_info_dict)
def getProgrammerList(path): programmer_list = [] programmer_file_dict = {} info_file = os.path.join(path, 'programmers.txt') if os.path.isfile(info_file): blocks = utils.readFile(info_file, mode = 'blocks') for block in blocks: if block: line = block[0] (key, value) = utils.getKeyValue(line) programmer_list.append(value) programmer_file_dict[value] = info_file return (programmer_list, programmer_file_dict)
def parseBoardFile150(platform, boards_file_path): board_list = [] board_file_dict = {} board_type_list_dict = {} board_item_list_dict = {} board_type = 'menu.cpu' board_type_list = [board_type] type_key = utils.genKey(board_type, platform) type_caption_dict = {type_key:'Processor'} lines = osfile.readFileLines(boards_file_path) board_info_block_list = utils.splitToBlocks(lines, sep = '.name') for board_info_block in board_info_block_list: cpu = '' for line in board_info_block: if '.name' in line: (key, board) = utils.getKeyValue(line) if '.cpu' in line: (key, cpu) = utils.getKeyValue(line) if '.container' in line: (key, board) = utils.getKeyValue(line) break board_key = utils.genKey(board, platform) key = utils.genKey(board_type, board_key) if not board in board_list: board_list.append(board) board_file_dict[board_key] = boards_file_path if cpu: board_type_list_dict[board_key] = board_type_list board_item_list_dict[key] = [cpu] else: if cpu and (not cpu in board_item_list_dict[key]): board_item_list_dict[key].append(cpu) return (board_list, board_file_dict, board_type_list_dict, board_item_list_dict, type_caption_dict)
def genTransDict(self): language = self.Settings.get('language') if language: if language in self.lang_text_dict.values(): lang_file = self.file_dict[language] f = open(lang_file, 'r') lines = f.readlines() f.close() for line in lines: line = line.strip() if line and (not '#' in line): (key, value) = utils.getKeyValue(line) value = value.decode('utf-8', 'replace') self.trans_dict[key] = value
def removeOptionInfoFromBlock(board_info_block, board_type_value_dict): info_block_list = [] board_common_info_block = getBoardCommonInfoBlock(board_info_block) info_block_list.append(board_common_info_block) for board_type in board_type_value_dict: value = board_type_value_dict[board_type] board_type_info_block = getBoardTypeInfoBlock(board_info_block, board_type) option_info_block_list = genOptionInfoBlockList(board_type_info_block) for option_info_block in option_info_block_list: name_line = option_info_block[0] (key, name) = utils.getKeyValue(name_line) if name == value: info_block_list.append(option_info_block) break return info_block_list
def parseProgrammerInfo(platform, core_root): programmer_list = [] programmer_file_dict = {} programmers_file_path = os.path.join(core_root, 'programmers.txt') if os.path.isfile(programmers_file_path): lines = osfile.readFileLines(programmers_file_path) programmer_info_block_list = utils.splitToBlocks(lines, sep = '.name') for programmer_info_block in programmer_info_block_list: programmer_name_line = programmer_info_block[0] (key, programmer) = utils.getKeyValue(programmer_name_line) if not programmer in programmer_list: programmer_list.append(programmer) programmer_key = utils.genKey(programmer, platform) programmer_file_dict[programmer_key] = programmers_file_path return (programmer_list, programmer_file_dict)
def getPlatform(path): platform = 'Arduino AVR Boards' info_file = os.path.join(path, 'platform.txt') if os.path.isfile(info_file): lines = utils.readFile(info_file, mode = 'lines') for line in lines: (key, value) = utils.getKeyValue(line) if key == 'name': platform = value break elif os.path.split(path)[1] != 'arduino': dirs = utils.listDir(path, with_files = False) if 'cores' in dirs: platform = os.path.split(path)[1] platform += ' %(Board)s' return platform
def genOptionInfoBlockList(info_block): block_list = utils.splitToBlocks(info_block, sep = '.name', key_length = 4) name_key_list = [] for block in block_list: name_line = block[0] (key, value) = utils.getKeyValue(name_line) key = key.replace('.name', '.') name_key_list.append(key) option_info_block_list = [] for name_key in name_key_list: option_info_block = [] for line in info_block: if name_key in line: option_info_block.append(line) option_info_block_list.append(option_info_block) return option_info_block_list