def genOriginalMenuText(self): show_arduino_menu = const.settings.get('show_arduino_menu') show_serial_monitor_menu = const.settings.get( 'show_serial_monitor_menu') preference_menu_file = os.path.join(self.template_root, 'menu_preference') serial_monitor_menu_file = os.path.join(self.template_root, 'menu_serial') menu_text = osfile.readFileText(preference_menu_file) if show_arduino_menu: if self.arduino_info.isReady(): arduino_menu_file_name = 'menu_full' else: arduino_menu_file_name = 'menu_mini' arduino_menu_file = os.path.join(self.template_root, arduino_menu_file_name) menu_text += ',\n' menu_text += osfile.readFileText(arduino_menu_file) if show_serial_monitor_menu: menu_text += ',\n' menu_text += osfile.readFileText(serial_monitor_menu_file) menu_text += '\n]' self.original_menu_text = menu_text
def genBuildSrcText(arduino_version, src_path_list, main_src_path): if main_src_path: src_path_list.remove(main_src_path) src_path_list.insert(0, main_src_path) # all_include_list = [] all_declaration_list = [] # all_header_text = '' # all_body_text = '' for src_path in src_path_list: declaration_list = splitSrcText(src_path) # all_include_list += include_list all_declaration_list += declaration_list # all_header_text += header_text # all_body_text += body_text if arduino_version < 100: include_text = '#include <WProgram.h>\n' else: include_text = '#include <Arduino.h>\n' # for include in all_include_list: # include_text += '%s\n' % include declaration_text = '\n' for declaration in all_declaration_list: declaration_text += '%s;\n' % declaration declaration_text += '\n' build_src_text = '// %s\n' % src_path_list[0] build_src_text += include_text src_text = osfile.readFileText(src_path_list[0]) simple_src_text = src.removeComments(src_text) (first_function, first_function_index) = src.findFirstFunction(simple_src_text) index = src_text.index(first_function) header_text = src_text[:index] body_text = src_text[index:] build_src_text += header_text build_src_text += declaration_text build_src_text += body_text for src_path in src_path_list[1:]: build_src_text += '\n// %s\n' % src_path src_text = osfile.readFileText(src_path) build_src_text += src_text return build_src_text
def genDefaultTransDict(self): self.trans_dict = {} pattern_text = r'%\(([\S\s]+?)\)s' pattern = re.compile(pattern_text) # display_pattern_text = r"display_text\s*?=\s*?'([\S\s]+?)'" display_pattern_text = r"display_text\s*?=\s*?'((?:[^'\\']|\\.)+?)'" display_pattern = re.compile(display_pattern_text, re.S) plugin_root = const.plugin_root script_root = const.script_root template_root = const.template_root root_list = [plugin_root, script_root, template_root] for cur_dir in root_list: file_list = osfile.listDir(cur_dir, with_dirs = False) for cur_file in file_list: if ('menu_' in cur_file and not 'sublime' in cur_file) \ or (os.path.splitext(cur_file)[1] == '.py'): cur_file_path = os.path.join(cur_dir, cur_file) text = osfile.readFileText(cur_file_path) key_list = pattern.findall(text) for key in key_list: if not key in self.trans_dict: value = key.replace('_', ' ') self.trans_dict[key] = value key_list = display_pattern.findall(text) for key in key_list: if not key in self.trans_dict: self.trans_dict[key] = key
def genSyntaxText(self): constant_list = [] keyword_list = [] function_list = [] if self.arduino_info.isReady(): platform = self.getPlatform() for keyword in self.arduino_info.getKeywordList(platform): if len(keyword) > 1: keyword_type = self.arduino_info.getKeywordType(platform, keyword) if keyword_type: if 'LITERAL' in keyword_type: constant_list.append(keyword) elif keyword_type == 'KEYWORD1': keyword_list.append(keyword) else: function_list.append(keyword) text = '' text += self.genDictBlock(constant_list, 'constant.arduino') text += self.genDictBlock(keyword_list, 'storage.modifier.arduino') text += self.genDictBlock(function_list, 'support.function.arduino') temp_file = os.path.join(self.template_root, 'syntax') self.syntax_text = osfile.readFileText(temp_file) self.syntax_text = self.syntax_text.replace('(_$dict$_)', text)
def genSyntaxText(self): constant_list = [] keyword_list = [] function_list = [] if self.arduino_info.isReady(): platform = self.getPlatform() for keyword in self.arduino_info.getKeywordList(platform): if len(keyword) > 1: keyword_type = self.arduino_info.getKeywordType( platform, keyword) if keyword_type: if 'LITERAL' in keyword_type: constant_list.append(keyword) elif keyword_type == 'KEYWORD1': keyword_list.append(keyword) else: function_list.append(keyword) text = '' text += self.genDictBlock(constant_list, 'constant.arduino') text += self.genDictBlock(keyword_list, 'storage.modifier.arduino') text += self.genDictBlock(function_list, 'support.function.arduino') temp_file = os.path.join(self.template_root, 'syntax') self.syntax_text = osfile.readFileText(temp_file) self.syntax_text = self.syntax_text.replace('(_$dict$_)', text)
def genDefaultTransDict(self): self.trans_dict = {} pattern_text = r'%\(([\S\s]+?)\)s' pattern = re.compile(pattern_text) # display_pattern_text = r"display_text\s*?=\s*?'([\S\s]+?)'" display_pattern_text = r"display_text\s*?=\s*?'((?:[^'\\']|\\.)+?)'" display_pattern = re.compile(display_pattern_text, re.S) plugin_root = const.plugin_root script_root = const.script_root template_root = const.template_root root_list = [plugin_root, script_root, template_root] for cur_dir in root_list: file_list = osfile.listDir(cur_dir, with_dirs=False) for cur_file in file_list: if ('menu_' in cur_file and not 'sublime' in cur_file) \ or (os.path.splitext(cur_file)[1] == '.py'): cur_file_path = os.path.join(cur_dir, cur_file) text = osfile.readFileText(cur_file_path) key_list = pattern.findall(text) for key in key_list: if not key in self.trans_dict: value = key.replace('_', ' ') self.trans_dict[key] = value key_list = display_pattern.findall(text) for key in key_list: if not key in self.trans_dict: self.trans_dict[key] = key
def genDefaultTransDict(self): self.trans_dict = {} pattern_text = r'%\([\S\s]+?\)s' display_pattern_text = r"display_text\s*?=\s*?'[\S\s]+?'" plugin_root = const.plugin_root script_root = const.script_root template_root = const.template_root root_list = [plugin_root, script_root, template_root] for cur_dir in root_list: file_list = osfile.listDir(cur_dir, with_dirs = False) for cur_file in file_list: if ('menu_' in cur_file and not 'sublime' in cur_file) \ or (os.path.splitext(cur_file)[1] == '.py'): cur_file_path = os.path.join(cur_dir, cur_file) text = osfile.readFileText(cur_file_path) key_list = re.findall(pattern_text, text) for key in key_list: key = key[2:-2] if not key in self.trans_dict: value = key.replace('_', ' ') self.trans_dict[key] = value key_list = re.findall(display_pattern_text, text) for key in key_list: index = key.index("'") key = key[index+1:-1] if not key in self.trans_dict: self.trans_dict[key] = key
def genBuildMainSrcFile(self): filename = os.path.split(self.main_src_path)[1] filename += '.cpp' self.build_main_src_path = os.path.join(self.build_path, filename) self.build_main_src_path = self.build_main_src_path.replace(os.path.sep, '/') sketch_text = osfile.readFileText(self.main_src_path) simple_sketch_text = src.genSimpleSrcText(sketch_text) declaration_list = src.genSrcDeclarationList(simple_sketch_text) function_list = src.genSrcFunctionList(simple_sketch_text) function_list.remove('void setup ()') function_list.remove('void loop ()') new_declaration_list = [] for function in function_list: if not function in declaration_list: if not function in new_declaration_list: new_declaration_list.append(function) header_text = '#include <Arduino.h>\n' for declaration in new_declaration_list: header_text += declaration header_text += ';\n' build_src_text = header_text + sketch_text osfile.writeFile(self.build_main_src_path, build_src_text) self.sketch_src_path_list.remove(self.main_src_path) self.sketch_src_path_list.append(self.build_main_src_path)
def genHeaderList(self): src_header_list = [] for sketch_src_path in self.sketch_src_path_list: src_text = osfile.readFileText(sketch_src_path) header_list = src.genHeaderListFromSketchText(src_text) src_header_list += header_list src_header_list = utils.removeRepeatItemFromList(src_header_list) self.src_header_list = src_header_list
def findMainSrcFile(src_path_list): main_src_path = '' main_src_number = 0 for src_path in src_path_list: src_text = osfile.readFileText(src_path) if src.isMainSrcText(src_text): main_src_path = src_path main_src_number += 1 return (main_src_number, main_src_path)
def genBuildSrcText0(insertion_src_text, src_path_list, main_src_path): if main_src_path: src_path_list.remove(main_src_path) src_path_list.append(main_src_path) build_src_text = insertion_src_text for src_path in src_path_list: build_src_text += '\n// %s\n' % src_path build_src_text += osfile.readFileText(src_path) return build_src_text
def createNewSketch(filename): sketchbook_root = const.settings.get('sketchbook_root') folder_path = os.path.join(sketchbook_root, filename) file_path = os.path.join(folder_path, filename) file_path += '.ino' template_file_path = os.path.join(const.template_root, 'sketch') os.mkdir(folder_path) text = osfile.readFileText(template_file_path) osfile.writeFile(file_path, text) openSketch(folder_path)
def genDefaultLanguageFile(self): template_root = const.template_root language_root = const.language_root template_file_path = os.path.join(template_root, 'language') text = osfile.readFileText(template_file_path) text += '\n' for key in self.trans_dict: text += 'msgid "%s"\n' % key text += 'msgstr "%s"\n\n' % self.trans_dict[key] default_file_path = os.path.join(language_root, 'en') osfile.writeFile(default_file_path, text)
def combineSrcText(src_path_list, main_src_path): if main_src_path: src_path_list.remove(main_src_path) src_path_list.append(main_src_path) org_src_text = '' for src_path in src_path_list: build_src_text += '\n// %s\n' % src_path src_text = osfile.readFileText(src_path) org_src_text += src_text org_src_text += '\n' return org_src_text
def getTextFromSketch(sketch): sketch_text = '' if isinstance(sketch, type(sublime.active_window().active_view())): sketch_text = getTextFromView(sketch) else: if os.path.isfile(sketch): sketch_ext = os.path.splitext(sketch)[1] if sketch_ext in src_ext_list: sketch_text = osfile.readFileText(sketch) elif isinstance(sketch, basestring): sketch_text = sketch return sketch_text
def genOriginalMenuText(self): show_arduino_menu = const.settings.get('show_arduino_menu') show_serial_monitor_menu = const.settings.get('show_serial_monitor_menu') preference_menu_file = os.path.join(self.template_root, 'menu_preference') serial_monitor_menu_file = os.path.join(self.template_root, 'menu_serial') menu_text = osfile.readFileText(preference_menu_file) if show_arduino_menu: if self.arduino_info.isReady(): arduino_menu_file_name = 'menu_full' else: arduino_menu_file_name = 'menu_mini' arduino_menu_file = os.path.join(self.template_root, arduino_menu_file_name) menu_text += ',\n' menu_text += osfile.readFileText(arduino_menu_file) if show_serial_monitor_menu: menu_text += ',\n' menu_text += osfile.readFileText(serial_monitor_menu_file) menu_text += '\n]' self.original_menu_text = menu_text
def genCommandsText(self): temp_filename = 'commands_mini' if self.arduino_info.isReady(): show_arduino_menu = const.settings.get('show_arduino_menu') if show_arduino_menu: temp_filename = 'commands_full' temp_file_path = os.path.join(self.template_root, temp_filename) temp_file_text = osfile.readFileText(temp_file_path) if temp_filename == 'commands_full': select_commands_text = self.genSelectCommandsText() temp_file_text = temp_file_text.replace('(_$item$_)', select_commands_text) self.commands_text = temp_file_text
def genDefaultLanguageFile(self): template_root = const.template_root language_root = const.language_root template_file_path = os.path.join(template_root, 'language') text = osfile.readFileText(template_file_path) text += '\n' key_list = [] for key in self.trans_dict: key_list.append(key) key_list.sort() for key in key_list: text += 'msgid "%s"\n' % key text += 'msgstr "%s"\n\n' % self.trans_dict[key] default_file_path = os.path.join(language_root, 'original_text') osfile.writeFile(default_file_path, text)
def genInsertionDelarationList(src_path_list): declaration_list = [] function_list = [] for src_path in src_path_list: src_text = osfile.readFileText(src_path) (header_text, body_text) = src.splitSrcByFisrtFunction(src_text) declaration_list += src.genSrcDeclarationList(header_text) function_list += src.genSrcFunctionList(body_text) function_list = removeMainFunctionsFromList(function_list) new_declaration_list = [] for function in function_list: if not function in declaration_list: if not function in new_declaration_list: new_declaration_list.append(function) return new_declaration_list
def splitSrcText(src_path): src_text = osfile.readFileText(src_path) # simple_src_text = src.genSimpleSrcText(src_text) simple_src_text = src.removeComments(src_text) (header_text, body_text) = src.splitSrcByFisrtFunction(simple_src_text) # include_list = src.genIncludeList(header_text) declaration_list = src.genSrcDeclarationList(header_text) function_list = src.genSrcFunctionList(body_text) # for includes_text in include_list: # header_text = header_text.replace(includes_text, '') new_declaration_list = [] # function_list = removeMainFunctionsFromList(function_list) for function in function_list: if not function in declaration_list: if not function_list in new_declaration_list: new_declaration_list.append(function) return new_declaration_list
def isBoard150(boards_file_path): state = False text = osfile.readFileText(boards_file_path) if '.container=' in text: state = True return state