Beispiel #1
0
	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
Beispiel #2
0
	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
Beispiel #3
0
	def removeBuildSourceFiles(self):
		file_list = osfile.listDir(self.build_path)
		for cur_file in file_list:
			cur_file_ext = os.path.splitext(cur_file)[1]
			if cur_file_ext in src.src_ext_list or cur_file_ext in src.header_ext_list:
				cur_file_path = os.path.join(self.build_path, cur_file)
				os.remove(cur_file_path)
Beispiel #4
0
	def genIncludeLibraryPath(self):
		self.genHeaderList()

		include_library_path_list = [self.build_path, self.core_folder_path]
		if 'build.variant' in self.info_dict:
			include_library_path_list.append(self.variant_folder_path)

		lib_path_list = []
		library_path_list = self.arduino_info.getLibraryPathList(self.platform)
		for library_path in library_path_list:
			header_list_from_library = src.getHeaderListFromFolder(library_path)
			for header in header_list_from_library:
				if header in self.src_header_list:
					library_path = library_path.replace(os.path.sep, '/')
					lib_path_list.append(library_path)
					break

		lib_sub_path_list = []
		for lib_path in lib_path_list:
			folder_list = osfile.listDir(lib_path, with_files = False)
			for folder in folder_list:
				folder_lower = folder.lower()
				if 'examples' in folder_lower:
					continue
				folder_path = os.path.join(lib_path, folder)
				folder_path = folder_path.replace(os.path.sep, '/')
				lib_sub_path_list.append(folder_path)
		self.lib_path_list = lib_path_list
		self.include_library_path_list = include_library_path_list + lib_path_list + lib_sub_path_list
Beispiel #5
0
def getHeaderListFromFolder(folder_path):
	header_list = []
	file_list = osfile.listDir(folder_path, with_dirs = False)
	for cur_file in file_list:
		cur_file_ext = os.path.splitext(cur_file)[1]
		if cur_file_ext in header_ext_list:
			header_list.append(cur_file)
	return header_list
Beispiel #6
0
def hasMainSketchInFolder(folder_path):
	state = False
	file_list = osfile.listDir(folder_path, with_dirs = False)
	for cur_file in file_list:
		cur_file_path = os.path.join(folder_path, cur_file)
		if isMainSketch(cur_file_path):
			state = True
			break
	return state
Beispiel #7
0
def findSrcFileList(path, ext_list):
	path_list = []
	file_list = osfile.listDir(path, with_dirs = False)
	for cur_file in file_list:
		cur_file_ext = os.path.splitext(cur_file)[1]
		if cur_file_ext in ext_list:
			cur_file_path = os.path.join(path, cur_file)
			path_list.append(cur_file_path)
	return path_list
Beispiel #8
0
def openExample(path):
	sublime.run_command('new_window')
	window = sublime.windows()[-1]
	file_list = osfile.listDir(path, with_dirs = False)
	for cur_file in file_list:
		cur_file_ext = os.path.splitext(cur_file)[1]
		if cur_file_ext in src_ext_list or cur_file_ext in header_ext_list:
			cur_file_path = os.path.join(path, cur_file)
			window.open_file(cur_file_path)
Beispiel #9
0
def isSketchFolder(path):
	state = False
	src_ext_list = src.src_ext_list
	file_list = osfile.listDir(path, with_dirs = False)
	for cur_file in file_list:
		cur_file_ext = os.path.splitext(cur_file)[1]
		if cur_file_ext in src_ext_list:
			state = True
			break
	return state
Beispiel #10
0
def isLibraryFolder(path):
	state = False
	header_ext_list = src.header_ext_list
	file_list = osfile.listDir(path, with_dirs = False)
	for cur_file in file_list:
		cur_file_ext = os.path.splitext(cur_file)[1]
		if cur_file_ext in header_ext_list:
			state = True
			break
	return state
Beispiel #11
0
def isLibraryFolder(path):
	state = False
	header_ext_list = src.header_ext_list
	file_list = osfile.listDir(path, with_dirs = False)
	for cur_file in file_list:
		cur_file_ext = os.path.splitext(cur_file)[1]
		if cur_file_ext in header_ext_list:
			state = True
			break
	return state
Beispiel #12
0
	def genSketchList(self):
		self.sketch_list = []
		self.sketch_path_dict = {}
		sketchbook_root = self.getSketchbookRoot()
		dir_list = osfile.listDir(sketchbook_root, with_files = False)
		for cur_dir in dir_list:
			cur_dir_path = os.path.join(sketchbook_root, cur_dir)
			if isSketchFolder(cur_dir_path):
				self.sketch_list.append(cur_dir)
				self.sketch_path_dict[cur_dir] = cur_dir_path
Beispiel #13
0
def parseExampleInfo(platform, root):
	example_list = []
	example_path_dict = {}
	examples_path = os.path.join(root, 'examples')
	dir_list = osfile.listDir(examples_path, with_files = False)
	for cur_dir in dir_list:
		example_list.append(cur_dir)
		key = utils.genKey(cur_dir, platform)
		cur_dir_path = os.path.join(examples_path, cur_dir)
		example_path_dict[key] = cur_dir_path
	return (example_list, example_path_dict)
Beispiel #14
0
def parseExampleInfo(platform, root):
	example_list = []
	example_path_dict = {}
	examples_path = os.path.join(root, 'examples')
	dir_list = osfile.listDir(examples_path, with_files = False)
	for cur_dir in dir_list:
		example_list.append(cur_dir)
		key = utils.genKey(cur_dir, platform)
		cur_dir_path = os.path.join(examples_path, cur_dir)
		example_path_dict[key] = cur_dir_path
	return (example_list, example_path_dict)
Beispiel #15
0
	def genCoreRootList(self):
		core_root_list = []
		arduino_root = self.getArduinoRoot()
		sketchbook_root = self.getSketchbookRoot()
		path_list = [arduino_root, sketchbook_root]
		for path in path_list:
			hardware_path = os.path.join(path, 'hardware')
			dir_list = osfile.listDir(hardware_path, with_files = False)
			for cur_dir in dir_list:
				if cur_dir == 'tools':
					continue
				cur_dir_path = os.path.join(hardware_path, cur_dir)
				if isCoreRoot(cur_dir_path):
					core_root_list.append(cur_dir_path)
				else:
					subdir_list = osfile.listDir(cur_dir_path)
					for cur_subdir in subdir_list:
						cur_subdir_path = os.path.join(cur_dir_path, cur_subdir)
						if isCoreRoot(cur_subdir_path):
							core_root_list.append(cur_subdir_path)
		return core_root_list
Beispiel #16
0
def parseLibraryInfo(platform, root):
	library_list = []
	library_path_dict = {}
	libraries_path = os.path.join(root, 'libraries')
	dir_list = osfile.listDir(libraries_path, with_files = False)
	for cur_dir in dir_list:
		cur_dir_path = os.path.join(libraries_path, cur_dir)
		if isLibraryFolder(cur_dir_path):
			library_list.append(cur_dir)
			key = utils.genKey(cur_dir, platform)
			library_path_dict[key] = cur_dir_path
	return (library_list, library_path_dict)
Beispiel #17
0
	def genCoreRootList(self):
		core_root_list = []
		arduino_root = self.getArduinoRoot()
		sketchbook_root = self.getSketchbookRoot()
		path_list = [arduino_root, sketchbook_root]
		for path in path_list:
			hardware_path = os.path.join(path, 'hardware')
			dir_list = osfile.listDir(hardware_path, with_files = False)
			for cur_dir in dir_list:
				if cur_dir == 'tools':
					continue
				cur_dir_path = os.path.join(hardware_path, cur_dir)
				if isCoreRoot(cur_dir_path):
					core_root_list.append(cur_dir_path)
				else:
					subdir_list = osfile.listDir(cur_dir_path)
					for cur_subdir in subdir_list:
						cur_subdir_path = os.path.join(cur_dir_path, cur_subdir)
						if isCoreRoot(cur_subdir_path):
							core_root_list.append(cur_subdir_path)
		return core_root_list
Beispiel #18
0
def parseLibraryInfo(platform, root):
	library_list = []
	library_path_dict = {}
	libraries_path = os.path.join(root, 'libraries')
	dir_list = osfile.listDir(libraries_path, with_files = False)
	for cur_dir in dir_list:
		cur_dir_path = os.path.join(libraries_path, cur_dir)
		if isLibraryFolder(cur_dir_path):
			library_list.append(cur_dir)
			key = utils.genKey(cur_dir, platform)
			library_path_dict[key] = cur_dir_path
	return (library_list, library_path_dict)
Beispiel #19
0
def openSketch(sketch):
	sketchbook_root = const.settings.get('sketchbook_root')
	folder_path = os.path.join(sketchbook_root, sketch)
	full_file_list = osfile.listDir(folder_path, with_dirs = False)

	file_list = []
	for cur_file in full_file_list:
		cur_file_ext = os.path.splitext(cur_file)[1]
		if cur_file_ext in src_ext_list or cur_file_ext in header_ext_list:
			file_list.append(cur_file)

	file_path_list = [os.path.join(folder_path, cur_file) for cur_file in file_list]

	sublime.run_command('new_window')
	window = sublime.windows()[-1]

	for cur_file_path in file_path_list:
		window.open_file(cur_file_path)
Beispiel #20
0
	def genLanguageList(self):
		self.language_list = []
		self.language_text_list = []
		self.language_file_dict = {}
		self.language_text_dict = {}
		self.text_language_dict = {}
		language_root = const.language_root
		file_list = osfile.listDir(language_root, with_dirs = False)
		for cur_file in file_list:
			cur_file_path = os.path.join(language_root, cur_file)
			if cur_file in self.abv_language_dict:
				language_abv = cur_file
				language = self.abv_language_dict[language_abv]
				language_text = self.abv_text_dict[language_abv]
				
				if not language in self.language_list:
					self.language_list.append(language)
					self.language_file_dict[language] = cur_file_path
					self.language_text_dict[language] = language_text
					self.text_language_dict[language_text] = language
		self.language_list.sort()
		for language in self.language_list:
			language_text = self.language_text_dict[language]
			self.language_text_list.append(language_text)
Beispiel #21
0
    def genLanguageList(self):
        self.language_list = []
        self.language_text_list = []
        self.language_file_dict = {}
        self.language_text_dict = {}
        self.text_language_dict = {}
        language_root = const.language_root
        file_list = osfile.listDir(language_root, with_dirs=False)
        for cur_file in file_list:
            cur_file_path = os.path.join(language_root, cur_file)
            if cur_file in self.abv_language_dict:
                language_abv = cur_file
                language = self.abv_language_dict[language_abv]
                language_text = self.abv_text_dict[language_abv]

                if not language in self.language_list:
                    self.language_list.append(language)
                    self.language_file_dict[language] = cur_file_path
                    self.language_text_dict[language] = language_text
                    self.text_language_dict[language_text] = language
        self.language_list.sort()
        for language in self.language_list:
            language_text = self.language_text_dict[language]
            self.language_text_list.append(language_text)