def createLibraryExamplesMenu(self): """ Shows the examples of the library in a menu """ examples = [] children = [] library_paths = Paths.getLibraryFolders() for path in library_paths: sub_paths = glob.glob(path) for sub in sub_paths: sub = os.path.join(sub, '*') libs = glob.glob(sub) for lib in libs: caption = os.path.basename(os.path.dirname(lib)) new_caption = search(r"^(\w+)_ID?", caption) if (new_caption is not None): caption = new_caption.group(1) if os.path.isdir(lib) and os.listdir( lib) and 'examples' in lib: file_examples = os.path.join(lib, '*') file_examples = glob.glob(file_examples) for file in file_examples: caption_example = os.path.basename(file) temp_info = {} temp_info['caption'] = caption_example temp_info['command'] = 'open_example' temp_info['args'] = {'example_path': file} children.append(temp_info) temp_info = {} temp_info['caption'] = caption temp_info['children'] = children examples.append(temp_info) children = [] examples.append({'caption': '-'}) # get preset menu_lib_example = self.getTemplateMenu(file_name='examples.json') # save file menu_lib_example[0]['children'][0]['children'] = examples self.saveSublimeMenu(data=menu_lib_example, sub_folder='library_example', user_path=True)
def createLibraryExamplesMenu(self): """ Shows the examples of the library in a menu """ examples = [] children = [] library_paths = Paths.getLibraryFolders() for path in library_paths: sub_paths = glob.glob(path) for sub in sub_paths: sub = os.path.join(sub, '*') libs = glob.glob(sub) for lib in libs: caption = os.path.basename(os.path.dirname(lib)) new_caption = search(r"^(\w+)_ID?", caption) if(new_caption is not None): caption = new_caption.group(1) if os.path.isdir(lib) and os.listdir(lib) and 'examples' in lib: file_examples = os.path.join(lib, '*') file_examples = glob.glob(file_examples) for file in file_examples: caption_example = os.path.basename(file) temp_info = {} temp_info['caption'] = caption_example temp_info['command'] = 'open_example' temp_info['args'] = {'example_path': file} children.append(temp_info) temp_info = {} temp_info['caption'] = caption temp_info['children'] = children examples.append(temp_info) children = [] examples.append({'caption': '-'}) # get preset menu_lib_example = self.getTemplateMenu(file_name='examples.json') # save file menu_lib_example[0]['children'][0]['children'] = examples self.saveSublimeMenu(data=menu_lib_example, sub_folder='library_example', user_path=True)
def getKeywords(): """ Gets the keywords from the installed libraries Returns: [list] -- list of object with the keywords """ try: from . import Paths except: from libs import Paths keywords = [] keywords_dirs = Paths.getLibraryFolders() for path in keywords_dirs: sub_dirs = glob.glob(path) for sub_dir in sub_dirs: key_file = os.path.join(sub_dir, 'keywords.txt') if (os.path.isfile(key_file)): keywords.append(Keywords.KeywordsFile(key_file)) return keywords
def getKeywords(): """ Gets the keywords from the installed libraries Returns: [list] -- list of object with the keywords """ try: from . import Paths except: from libs import Paths keywords = [] keywords_dirs = Paths.getLibraryFolders() for path in keywords_dirs: sub_dirs = glob.glob(path) for sub_dir in sub_dirs: key_file = os.path.join(sub_dir, 'keywords.txt') if(os.path.isfile(key_file)): keywords.append(Keywords.KeywordsFile(key_file)) return keywords
def createLibraryImportMenu(self): """ Creates the import library menu this method search in the user and core libraries """ library_paths = Paths.getLibraryFolders() added_lib = [] children = [] # get preset menu_import_lib = self.getTemplateMenu(file_name='import_library.json') for library_dir in library_paths: # add separator if 'arduinoteensy' not in library_dir: temp_info = {} temp_info['caption'] = '-' children.append(temp_info) sub_path = glob.glob(library_dir) # search in sub path for library in sub_path: # Add core libraries if '__cores__' in library: core_subs = os.path.join(library, '*') core_subs = glob.glob(core_subs) for core_sub in core_subs: core_sub_subs = os.path.join(core_sub, '*') core_sub_subs = glob.glob(core_sub_subs) for core_lib in core_sub_subs: caption = os.path.basename(core_lib) if caption not in added_lib: temp_info = {} temp_info['caption'] = caption temp_info['command'] = 'add_library' temp_info['args'] = {'library_path': library} children.append(temp_info) added_lib.append(caption) # the rest of the libraries caption = os.path.basename(library) # get library name from json file pio_libs = os.path.join('platformio', 'lib') if pio_libs in library: # get library json details library_json = os.path.join(library, 'library.json') if (not os.path.exists(library_json)): library_json = os.path.join(library, 'library.properties') # when there´s json content, read it json = JSONFile(library_json) json = json.getData() if (json != {}): caption = json['name'] if caption not in added_lib and '__cores__' not in caption: temp_info = {} temp_info['caption'] = caption temp_info['command'] = 'add_library' temp_info['args'] = {'library_path': library} children.append(temp_info) added_lib.append(caption) # save file menu_import_lib[0]['children'][0]['children'] = children self.saveSublimeMenu(data=menu_import_lib, sub_folder='import_library', user_path=True)
def createLibraryImportMenu(self): """ Creates the import library menu this method search in the user and core libraries """ library_paths = Paths.getLibraryFolders() added_lib = [] children = [] # get preset menu_import_lib = self.getTemplateMenu(file_name='import_library.json') for library_dir in library_paths: # add separator if 'arduinoteensy' not in library_dir: temp_info = {} temp_info['caption'] = '-' children.append(temp_info) sub_path = glob.glob(library_dir) # search in sub path for library in sub_path: # Add core libraries if '__cores__' in library: core_subs = os.path.join(library, '*') core_subs = glob.glob(core_subs) for core_sub in core_subs: core_sub_subs = os.path.join(core_sub, '*') core_sub_subs = glob.glob(core_sub_subs) for core_lib in core_sub_subs: caption = os.path.basename(core_lib) if caption not in added_lib: temp_info = {} temp_info['caption'] = caption temp_info['command'] = 'add_library' temp_info['args'] = {'library_path': library} children.append(temp_info) added_lib.append(caption) # the rest of the libraries caption = os.path.basename(library) # get library name from json file pio_libs = os.path.join('platformio', 'lib') if pio_libs in library: # get library json details library_json = os.path.join(library, 'library.json') if (os.path.exists(library_json) == False): library_json = os.path.join(library, 'library.properties') # when there´s json content, read it json = JSONFile(library_json) json = json.getData() if (json != {} ): caption = json['name'] if caption not in added_lib and '__cores__' not in caption: temp_info = {} temp_info['caption'] = caption temp_info['command'] = 'add_library' temp_info['args'] = {'library_path': library} children.append(temp_info) added_lib.append(caption) # save file menu_import_lib[0]['children'][0]['children'] = children self.saveSublimeMenu(data=menu_import_lib, sub_folder='import_library', user_path=True)