def forceUpdatePaths(self, buildData): ''' This function is called when there are no valid paths found in existing 'buildData.json' file. ''' for (path, pathName) in self.toolsList: while (True): newPath = utils.getUserPath(pathName) if utils.fileFolderExists(newPath): buildData[path] = newPath msg = "\tPath to '" + pathName + "' updated." print(msg) break # out of while loop else: msg = "\tPath to '" + pathName + "' not valid:\n\t" + str( newPath) print(msg) gccExePath = buildData[self.bStr.gccExePath] buildData[self.bStr.gccInludePath] = utils.getGccIncludePath( gccExePath) openOCDTargetPath = buildData[self.bStr.openOCDTargetPath] buildData[self.bStr.openOCDInterfacePath] = utils.getSTLinkPath( openOCDTargetPath) print("Tools paths updated.\n") return buildData
def getCubeMxExePath(): ''' Get absolute path to STM32CubeMX.exe either by windows default associated program or user input. ''' cubeMxPath = utils.findExecutablePath('ioc', raiseException=False) if cubeMxPath is not None: if os.path.exists(cubeMxPath): cubeMxPath = utils.pathWithForwardSlashes(cubeMxPath) print("STM32CubeMX.exe path automatically updated.") return cubeMxPath else: while cubeMxPath is None: cubeMxPath = utils.getUserPath('STM32CubeMX.exe') if os.path.exists(cubeMxPath): cubeMxPath = utils.pathWithForwardSlashes(cubeMxPath) return cubeMxPath else: cubeMxPath = None
def updatePath(self, pathName, default): ''' This function is called when a path is detected as invalid or the user requests to update paths. ''' # check if default path is command pathDefault = None if utils.commandExists(default): pathDefault = shutil.which(default) # if not a command, check if it's a path elif utils.pathExists(default): pathDefault = default if pathDefault is not None: msg = "\n\tDefault path to '" + pathName + "' detected at '" + pathDefault + "'\n\tUse this path? [y/n]: " if utils.getYesNoAnswer(msg): return pathDefault # default not detected or user wants custom path/command newPath = utils.getUserPath(pathName) return newPath
def getKeilProjectPath(paths: Paths): ''' Try to find Keil *.uvprojx file. If found, this file is used as project file. If not found, throw error. If multiple files found, user is asked to enter specific file path. Return files absolute paths: *.uvprojx ''' KEIL_PROJECT_FILE_EXTENSION = '.uvprojx' # Get the list of all files in directory tree at given path allFiles = utils.getAllFilesInFolderTree(paths.rootFolder) keilProjectFiles = [] for theFile in allFiles: if theFile.find(KEIL_PROJECT_FILE_EXTENSION) != -1: keilProjectFiles.append(theFile) if len(keilProjectFiles) == 0: errorMsg = "Unable to find any Keil project files ending with " + KEIL_PROJECT_FILE_EXTENSION + ". " errorMsg += "Is folder structure correct?\n\t" errorMsg += "Searched files in folder tree: " + paths.rootFolder raise Exception(errorMsg) elif len(keilProjectFiles) == 1: # only one keil project file available, take this one print("Keil project file found:", keilProjectFiles[0]) return keilProjectFiles[0] else: print("More than one Keil project files available. Select the right one.") keilProjectPath = None while keilProjectPath is None: keilProjectPath = utils.getUserPath('Keil project (.uvprojx)') if os.path.exists(keilProjectPath): break else: keilProjectPath = None print("Keil project path updated.") return keilProjectPath