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 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 getKeywordList(path): keyword_list = [] keyword_type_dict = {} keyword_ref_dict = {} keyword_file = os.path.join(path, 'keywords.txt') if os.path.isfile(keyword_file): lines = utils.readFile(keyword_file, mode = 'lines') for line in lines: line = line.strip() if line and (not '#' in line): line = line.replace('\t', ' ') word_list = line.split(' ') while len(word_list) < 3: word_list.append('') keyword = word_list[0] keyword_list.append(keyword) if 'KEYWORD' in word_list[2]: keyword_type_dict[keyword] = word_list[2] keyword_ref_dict[keyword] = '' else: keyword_type_dict[keyword] = word_list[1] keyword_ref_dict[keyword] = word_list[2] if ('{}' in keyword) or ('[]' in keyword) or ('()' in keyword): for letter in keyword: keyword_list.append(letter) keyword_type_dict[letter] = keyword_type_dict[keyword] keyword_ref_dict[letter] = keyword_ref_dict[keyword] return (keyword_list, keyword_type_dict, keyword_ref_dict)
def on_done(self, index): if index == -1: return sel_path = self.path_list[index] if os.path.isfile(sel_path): active_file = self.window.active_view().file_name() sketch_folder = os.path.split(active_file)[0] is_new = True basename = os.path.split(sel_path)[1] basename = utils.regFilename(basename) file_path = os.path.join(sketch_folder, basename) if os.path.exists(file_path): is_new = False if is_new: content = utils.readFile(sel_path) utils.writeFile(file_path, content) view = self.window.open_file(file_path) else: org_msg = '%(File_Exists)s' msg = org_msg % cur_lang.getDisplayTextDict() is_new = sublime.message_dialog(msg) else: (self.level, self.path_list) = utils.enterNext(index, self.level, self.top_path_list, sel_path) file_list = utils.getFileList(self.path_list) self.window.show_quick_panel(file_list, self.on_done)
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 run(self): state = True if self.window.active_view().is_dirty(): text = '%(Discard_All_Changes)s' msg = text % cur_lang.getDisplayTextDict() state = sublime.ok_cancel_dialog(msg) if state: file_path = self.window.active_view().file_name() content = utils.readFile(file_path) edit = self.window.active_view().begin_edit() self.window.active_view().replace(edit, sublime.Region(0, self.window.active_view().size()), content) self.window.active_view().end_edit(edit)
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 genDefaultTransDict(self): plugin_root = utils.getPluginRoot() template_dir = os.path.join(plugin_root, 'template') mod_dir = os.path.join(plugin_root, 'stino') dirs = [plugin_root, template_dir, mod_dir] pattern = re.compile(r'%\([\S\s]+?\)s') for cur_dir in dirs: files = os.listdir(cur_dir) files = [os.path.join(cur_dir, cur_file) for cur_file in files if (not '.pyc' in cur_file) and (not '.sublime' in cur_file) and (not '.tm' in cur_file)] files = [cur_file for cur_file in files if os.path.isfile(cur_file)] for cur_file in files: lines = utils.readFile(cur_file, mode = 'lines') for cur_line in lines: match = pattern.search(cur_line) if match: captions = pattern.findall(cur_line) for caption in captions: caption = caption[2:-2] caption_txt = caption.replace('_', ' ') if not caption in self.trans_dict: self.trans_dict[caption] = caption_txt