Esempio n. 1
0
    def verifyToolsPaths(self, toolsPaths, request=False):
        '''
        This function checks if paths in 'toolsPaths.json' are a valid paths.
        If any path is not valid/missing, user is asked for update via updatePath().
        If 'request' is set to True, user is asked to update path even if it is a valid path.

        Returns updated valid tools paths.
        '''
        for pathName in self.bStr.toolsPaths:
            try:
                mustBeUpdated = False
                if pathName in toolsPaths:
                    # 'toolsPaths.json' keys are not lists. Always a plain path (string)
                    if not utils.pathExists(toolsPaths[pathName]):
                        mustBeUpdated = True
                        # path not valid, check if command
                        if utils.commandExists(toolsPaths[pathName]):
                            mustBeUpdated = False

                    if mustBeUpdated:
                        if toolsPaths[pathName] != '':
                            # avoid reporting invalid file path, if there is an empty string
                            msg = "\n\nInvalid path detected in '" + pathName + "' key."
                            print(msg)
                    else:
                        if request:
                            msg = "\n\nValid path(s) for " + pathName + " detected: '" + toolsPaths[
                                pathName] + "'."
                            msg += "\n\tUpdate? [y/n]: "
                            if utils.getYesNoAnswer(msg):
                                mustBeUpdated = True

                else:  # this key is missing in toolsPaths.json!
                    mustBeUpdated = True

                if mustBeUpdated:
                    if pathName in self.bStr.derivedPaths:
                        continue

                    elif pathName == self.bStr.openOcdConfig:
                        # get openOcdConfig - special handler
                        toolsPaths[pathName] = utils.getOpenOcdConfig(
                            toolsPaths[self.bStr.openOcdPath])

                    elif pathName in self.pathsDescriptionsData:
                        name = self.pathsDescriptionsData[pathName]['name']
                        defaultPath = self.pathsDescriptionsData[pathName][
                            'defaultPath']
                        toolsPaths[pathName] = self.updatePath(
                            name, defaultPath)

                    else:
                        toolsPaths[pathName] = self.updatePath(pathName, None)

            except Exception as err:
                toolsPaths[pathName] = self.updatePath(pathName, None)

        for pathName in self.bStr.derivedPaths:
            if pathName == self.bStr.pythonExec:
                toolsPaths[self.bStr.pythonExec] = utils.getPython3Executable()

            elif pathName == self.bStr.gccInludePath:
                toolsPaths[self.bStr.gccInludePath] = utils.getGccIncludePath(
                    toolsPaths[self.bStr.gccExePath])

            else:
                errorMsg = "ideScripts design error: pathName '" + pathName + "' is in 'self.bStr.derivedPaths' list, "
                errorMsg += "but no 'get()' handler is specified."
                utils.printAndQuit(errorMsg)

        return toolsPaths
Esempio n. 2
0
    def verifyExistingPaths(self, buildData, request=False):
        '''
        This function checks if configuration paths (not workspace sources) from 'buildData.json' are valid paths.
        Common configuration paths are previoulsy fetched from 'toolsPaths.json'.
        If any path is not valid/missing, user is asked for update via updatePath().

        Returns updated valid paths.
        '''
        for pathName in self.bStr.configurationPaths:
            mustBeUpdated = False
            try:
                isPathValid = False
                if pathName in buildData:
                    pathToCheck = buildData[pathName]
                    if isinstance(pathToCheck, list):
                        for path in pathToCheck:
                            if not utils.pathExists(path):
                                break
                        else:
                            isPathValid = True
                    else:  # not a list, a single path expected
                        if utils.pathExists(pathToCheck):
                            isPathValid = True
                        else:
                            # path not valid, check if command
                            if utils.commandExists(pathToCheck):
                                isPathValid = True

                if isPathValid:
                    if request:  # if the user made the path verification request
                        msg = "\n\nValid paths for " + pathName + " detected: '" + str(pathToCheck) + "'.\n\tUpdate? [y/n]: "
                        if utils.getYesNoAnswer(msg):
                            mustBeUpdated = True
                else:
                    # non-valid path, must be updated
                    mustBeUpdated = True

                if mustBeUpdated:
                    if pathName in [self.bStr.pythonExec, self.bStr.gccInludePath]:
                        # derived paths, build later
                        continue

                    elif pathName in self.toolsList:
                        name = self.toolsList[pathName]["name"]
                        defaultPath = self.toolsList[pathName]["defaultPath"]
                        buildData[pathName] = self.updatePath(name, defaultPath)

                    # handle special paths cases - custom get() handlers
                    elif pathName == self.bStr.openOcdInterfacePath:
                        buildData[pathName] = utils.getOpenOcdInterface(buildData[self.bStr.openOcdPath])

                    elif pathName == self.bStr.openOcdConfig:
                        # get openOcdConfig
                        buildData[self.bStr.openOcdConfig] = utils.getOpenOcdConfig(buildData[self.bStr.openOcdInterfacePath])

                    # basic path question, default name
                    else:
                        buildData[pathName] = self.updatePath(pathName, None)

            except Exception as err:
                buildData[pathName] = self.updatePath(pathName, None)

        # get gccIncludePath
        buildData[self.bStr.gccInludePath] = utils.getGccIncludePath(buildData[self.bStr.gccExePath])
        # get python3 executable
        buildData[self.bStr.pythonExec] = utils.getPython3Executable()

        return buildData