def checkCPropertiesFile(self):
        '''
        Check if 'c_cpp_properties.json' file exists. If it does, check if it is a valid JSON file.
        If it doesn't exist, create new according to template.
        '''
        if utils.fileFolderExists(utils.cPropertiesPath):
            # file exists, check if it loads OK
            try:
                with open(utils.cPropertiesPath, 'r') as cPropertiesFile:
                    json.load(cPropertiesFile)

                print("Existing 'c_cpp_properties.json' file found.")
                return

            except Exception as err:
                errorMsg = "Invalid 'c_cpp_properties.json' file. Creating backup and new one.\n"
                errorMsg += "Possible cause: invalid json format or comments (not supported by this scripts). Error:\n"
                errorMsg += str(err)
                print(errorMsg)

                utils.copyAndRename(utils.cPropertiesPath, utils.cPropertiesBackupPath)

                self.createCPropertiesFile()

        else:  # 'c_cpp_properties.json' file does not exist jet, create it according to template string
            self.createCPropertiesFile()
Esempio n. 2
0
    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
Esempio n. 3
0
    def restoreOriginalMakefile(self):
        '''
        Check wether current 'Makefile' has print capabilities. If it has, this means it was already altered by this script.
        If it was, replace it with backup copy: 'Makefile.backup'. 
        If it does not have prin capabilities, is is assumed 'Makefile' was regenerated with CubeMX tool - print function is added and backup file is overwritten with this new 'Makefile'.
        At the end, add 'print-variable' capabilities
        '''
        if utils.fileFolderExists(utils.makefileBackupPath):
            # Makefile.backup exists, check if it is original (no print capabilities)
            if self.hasPrintCapabilities(
                    pathToMakefile=utils.makefileBackupPath):
                errorMsg = "Makefile.backup exist, but looks like it was already modified!\n"
                errorMsg += "Did you manually delete, replace or modify any of Makefiles? "
                errorMsg += "Delete all Makefiles and regenerate with CubeMX."
                utils.printAndQuit(errorMsg)

            else:  # OK - seems like original Makefile, replace Makefile with Makefile.backup, add print capabilities
                utils.copyAndRename(utils.makefileBackupPath,
                                    utils.makefilePath)

        else:  # Makefile.backup does not exist, check if current Makefile has print capabilities.
            if self.hasPrintCapabilities(pathToMakefile=utils.makefilePath):
                errorMsg = "Looks like Makefile was already modified! Makefile.backup does not exist.\n"
                errorMsg += "Did you manually delete, replace or modify any of Makefiles? "
                errorMsg += "Delete all Makefiles and regenerate with CubeMX."
                utils.printAndQuit(errorMsg)

            else:  # Makefile looks like an original one. Create a backup copy and add print capabilities
                utils.copyAndRename(utils.makefilePath,
                                    utils.makefileBackupPath)

        self.addMakefileCustomFunctions(pathToMakefile=utils.makefilePath)
Esempio n. 4
0
 def checkMakefileFile(self):
     '''
     Check if 'Makefile' file exists. If it doesn't, report as error.
     '''
     if not utils.fileFolderExists(utils.makefilePath):
         errorMsg = "Makefile does not exist! Did CubeMX generated Makefile?\n"
         errorMsg += "File name must be 'Makefile'."
         utils.printAndQuit(errorMsg)
Esempio n. 5
0
    def verifyExistingPaths(self, buildData):
        '''
        This function checks if paths specified in 'self.toolsList' exists in 'buildData.json' and check if paths are valid.

        Return 'True' if paths are valid, 'False' otherwise.
        '''

        for path, _ in self.toolsList:
            try:
                pathToCheck = buildData[path]
                if utils.fileFolderExists(pathToCheck):
                    # a valid path exists, ask user if he wish to update
                    continue
                else:  # path not valid
                    return False
            except:
                return False

        return True
Esempio n. 6
0
    def checkWorkspaceFile(self):
        '''
        Check if workspace '*.code-workspace' file exists. If it does, check if it is a valid JSON file.
        If it doesn't exist report error and quit.
        '''
        workspaceFileName = utils.getWorkspaceName()
        if utils.fileFolderExists(utils.workspaceFilePath):
            # file exists, check if it loads OK
            try:
                with open(utils.workspaceFilePath, 'r') as workspaceFile:
                    workspaceFileData = json.load(workspaceFile)

                    print("Existing " + workspaceFileName + " file found.")

            except Exception as err:
                errorMsg = "Invalid " + workspaceFileName + " file.\n"
                errorMsg += "Possible cause: invalid json format or comments (not supported by this scripts). Error:\n"
                errorMsg += str(err)
                print(errorMsg)
Esempio n. 7
0
    def checkBuildDataFile(self):
        '''
        Check if 'buildData.json' file exists. If it does, check if it is a valid JSON file.
        If it doesn't exist, create new according to template.
        '''
        if utils.fileFolderExists(utils.buildDataPath):
            # file exists, check if it loads OK
            try:
                with open(utils.buildDataPath, 'r') as buildDataFile:
                    data = json.load(buildDataFile)

                    print("Existing 'buildData.json' file found.")

            except Exception as err:
                errorMsg = "Invalid 'buildData.json' file. Creating new one. Error:\n"
                errorMsg += "Possible cause: invalid json format or comments (not supported by this scripts). Error:\n"
                errorMsg += str(err)
                print(errorMsg)

                self.createBuildDataFile()

        else:  # 'buildData.json' file does not exist jet, create it according to template string
            self.createBuildDataFile()
            print("New 'buildData.json' file created.")