def processAnnotateMainTestingFunction_(self, doAdd, language,
                                            functionName):
        dumpFileName = "call_graph.json"
        assert language in (ProgramExecution.Languages.PYTHON,
                            ProgramExecution.Languages.C_PLUS_PLUS)
        sourceExt = ".py" if language == ProgramExecution.Languages.PYTHON else ".cpp"
        mainFileName = os.path.join(TEST_FILES_FOLDER,
                                    functionName + sourceExt)
        expectedFileName = os.path.join(TEST_FILES_FOLDER,
                                        functionName + "_expected" + sourceExt)

        if not doAdd:
            aux = mainFileName
            mainFileName = expectedFileName
            expectedFileName = aux

        mainFileBackup = mainFileName + ".mybkp"

        try:
            shutil.copy(mainFileName, mainFileBackup)
            #Verify second (un)annotation yields the same file
            for i in range(2):
                mySourceCodeParser = SourceCodeParser(language, mainFileName)
                if doAdd:
                    mySourceCodeParser.annotateMainFile(dumpFileName)
                else:
                    mySourceCodeParser.unAnnotateMainFile()
                self.compareFileContents_(mainFileName, expectedFileName)
        finally:
            if os.path.exists(mainFileBackup):
                shutil.copy(mainFileBackup, mainFileName)
                os.remove(mainFileBackup)
예제 #2
0
    def accept(self):
        '''
        User accept. If data is valid, store the project with the help of the ProjectManager.  
        '''
        ok = self.validateProject_()
        if not ok:
            return

        theProjectsManager = project.projectsManagerInstance()
        name = str(self.projectNameTextEdit.toPlainText())
        projectsFolder = str(self.projectsLocationEditBox.toPlainText())
        folder = os.path.join(projectsFolder, name)
        language = self.getSelectedLanguage_()
        solutionFile = str(self.solutionEditBox.toPlainText())
        cppProject = str(self.cppProjectEditBox.toPlainText())
        mainFile = str(self.mainFileEditBox.toPlainText())
        mainFunction = str(self.mainFunctionComboBox.currentText())
        compilingCommand = str(self.compilingCommandEditBox.toPlainText())
        exeCommand = str(self.exeCommandTextEdit.toPlainText())

        aProject = project.Project(name, folder, language, solutionFile,
                                   mainFile, mainFunction, exeCommand, [],
                                   cppProject, compilingCommand)
        #Annotate main file before adding it to the tree

        if self.isEditMode_():
            #If main function changed, unannotate previous main function
            previousMainFunction = self.projectToEdit_.getMainFunction()
            if mainFunction != previousMainFunction:
                mySourceCodeParser = SourceCodeParser(language, mainFile,
                                                      previousMainFunction)
                mySourceCodeParser.unAnnotateMainFile()

        mySourceCodeParser = SourceCodeParser(language, mainFile, mainFunction)
        mainBackupFileName = mainFile + ".bkp"
        shutil.copyfile(mainFile, mainBackupFileName)

        dumpFileName = os.path.join(aProject.getExecutionsFolder(),
                                    name + ".json")
        mySourceCodeParser.annotateMainFile(dumpFileName)

        if language == ProgramExecution.Languages.C_PLUS_PLUS:
            self.addBraCustomInfoToCppProject_(cppProject)

        theProjectsManager.storeProject(aProject)
        theProjectsManager.setCurrentProjectName(aProject.getName())
        QDialog.accept(self)
    def accept(self):
        '''
        User accept. If data is valid, store the project with the help of the ProjectManager.  
        '''
        ok = self.validateProject_()
        if not ok:
            return
        
        theProjectsManager = project.projectsManagerInstance()
        name = str(self.projectNameTextEdit.toPlainText())
        projectsFolder = str(self.projectsLocationEditBox.toPlainText())
        folder = os.path.join(projectsFolder, name)
        language = self.getSelectedLanguage_()
        solutionFile = str(self.solutionEditBox.toPlainText())
        cppProject = str(self.cppProjectEditBox.toPlainText())
        mainFile = str(self.mainFileEditBox.toPlainText())
        mainFunction = str(self.mainFunctionComboBox.currentText())
        compilingCommand = str(self.compilingCommandEditBox.toPlainText())
        exeCommand = str(self.exeCommandTextEdit.toPlainText())
        
        aProject = project.Project(name, folder, language, solutionFile, mainFile, mainFunction, exeCommand, [], cppProject, compilingCommand)
        #Annotate main file before adding it to the tree
        
        if self.isEditMode_():
            #If main function changed, unannotate previous main function
            previousMainFunction = self.projectToEdit_.getMainFunction()
            if mainFunction != previousMainFunction:
                mySourceCodeParser = SourceCodeParser(language, mainFile, previousMainFunction)
                mySourceCodeParser.unAnnotateMainFile()
        
        mySourceCodeParser = SourceCodeParser(language, mainFile, mainFunction)
        mainBackupFileName = mainFile + ".bkp"
        shutil.copyfile(mainFile, mainBackupFileName)
            
        dumpFileName = os.path.join(aProject.getExecutionsFolder(), name + ".json")
        mySourceCodeParser.annotateMainFile(dumpFileName)
        
        if language == ProgramExecution.Languages.C_PLUS_PLUS:
            self.addBraCustomInfoToCppProject_(cppProject)

        theProjectsManager.storeProject(aProject)
        theProjectsManager.setCurrentProjectName(aProject.getName())
        QDialog.accept(self)
 def removeProject(self, projectName):
     '''
     Remove a project.
     '''
     if projectName == self.currentProjectName_:
         self.currentProjectName_ = None
     theProject = self.projects_[projectName]
     #Unannotate Files
     theLanguage = theProject.getLanguage()
     treeFiles = theProject.getTreeFiles()
     mainFile = theProject.getMainFile()
     mainFunction = theProject.getMainFunction()
     aSourceCodeParser = SourceCodeParser(theLanguage, mainFile, mainFunction)
     if theLanguage == ProgramExecution.Languages.C_PLUS_PLUS:
         for sourceFile, _ in treeFiles:
             #Unannotate file
             sourceFileTmp = sourceFile + '.tmp'
             shutil.copy(sourceFile, sourceFileTmp)
             try:
                 aSourceCodeParser.unAnnotateCppFile(sourceFile, sourceFileTmp)
                 shutil.copy(sourceFileTmp, sourceFile)
             finally:
                 if os.path.exists(sourceFileTmp):
                     os.remove(sourceFileTmp)
     aSourceCodeParser.unAnnotateMainFile()
     
     cppProject = theProject.getCppProject()
     cppProjectBkp = getCppProjectFileBackup(cppProject)
     if os.path.exists(cppProjectBkp):
         shutil.copy(cppProjectBkp, cppProject)
         os.remove(cppProjectBkp)
                     
     projectFolder = theProject.getFolder()
     removeFolder(projectFolder)
     del self.projects_[projectName]
     ProjectSerializer.saveProjectsList(self.projects_)