def missing_func_param(self, file_list, line, variable_init, param): final_file_list = [] for file in file_list: if file not in final_file_list: final_file_list.append(file) for file in final_file_list: if not clearcase.is_checked_out(file): clearcase.checkout(file) a1 = '"' my_re = re.escape(a1) + r'(.*)' + re.escape(a1) + ' in call to "(.*)"' k = re.search(my_re, line) #print k.group(1) # Lot of opportuinities for optimization in this area, if you notice the file gets opened and # closed 4 times, we can open and close just once. This will reduce run time print k.group(2) for file in final_file_list: base_name = os.path.basename(file)[:-4] read1 = open(file, 'r') lines = read1.readlines() print(base_name) index_of = lines.index('package body ' + base_name + ' is\n') #variable_init = 'G_Use_ICAO_Altitude_State_Conditions : boolian := True;' lines.insert(index_of + 1, variable_init) read1.close() write1 = open(file, 'w') write1.write(''.join(lines)) write1.close() g = open(file, 'r') lines = g.read() g.close() find = re.findall( re.escape('.') + k.group(2) + '(.*?);', lines, re.DOTALL | re.IGNORECASE) for line in find: if line <> '': list1 = line.split(',') list1.insert(2, '\n' + param) new_string = ",".join(list1) lines = lines.replace(line, new_string) g = open(file, 'w') g.write(lines) g.close()
def ProcessFileModificationsDictionary(self, fileModificationsDictionary): self.FileToEditWithPath = range(MAX_NUMBER_OF_SRC_FILES_ALLOWED_TO_BE_MODIFIED) filenameArray = range(MAX_NUMBER_OF_SRC_FILES_ALLOWED_TO_BE_MODIFIED) self.FileToEditIndex = -1 # Determine the paths to all of the files to be modified. for filename in fileModificationsDictionary.keys(): self.PrintToScreenAndFile("filename = %s" % filename, True) # Check if the file exists in one of the allowed folders. If not, return an error. if not self.IsFileFoundInDiagnosticSourceFileFolder(filename): UnexpectedError = "File '%s' was not found in any of the allowed folders" % filename self.PrintToScreenAndFile(UnexpectedError, False) raise RuntimeError, UnexpectedError filenameArray[self.FileToEditIndex] = filename # Loop through all of the files to edit and process each one. for self.currentFileToEditIndex in range(0, self.FileToEditIndex + 1): # Check if the file is already checked out. self.PrintToScreenAndFile("Checking if file %s is already checked out..." % self.FileToEditWithPath[self.currentFileToEditIndex], True) if clearcase.isCheckedOut(self.FileToEditWithPath[self.currentFileToEditIndex]): UnexpectedError = "File %s already Checked Out!" % self.FileToEditWithPath[self.currentFileToEditIndex] self.PrintToScreenAndFile(UnexpectedError, False) raise RuntimeError, UnexpectedError self.PrintToScreenAndFile("File %s is not already checked out" % self.FileToEditWithPath[self.currentFileToEditIndex], True) # Check the file out. self.PrintToScreenAndFile("Checking out file %s" % self.FileToEditWithPath[self.currentFileToEditIndex], True) if clearcase.checkout(self.FileToEditWithPath[self.currentFileToEditIndex], False, 'Temporary Checkout for Fault Injection Test.') != None: UnexpectedError = "Error while trying to checkout file %s!" % self.FileToEditWithPath[self.currentFileToEditIndex] self.PrintToScreenAndFile(UnexpectedError, False) raise RuntimeError, UnexpectedError self.PrintToScreenAndFile("File %s has been checked out." % self.FileToEditWithPath[self.currentFileToEditIndex], True) # Modify the file. self.ModifyFile(fileModificationsDictionary, filenameArray[self.currentFileToEditIndex], self.FileToEditWithPath[self.currentFileToEditIndex]) # Copy the modified file to the build results folder. self.PrintToScreenAndFile("Copying modified file %s" % self.FileToEditWithPath[self.currentFileToEditIndex], True) if shutil.copyfile(self.FileToEditWithPath[self.currentFileToEditIndex], self.BuildResultsSubFolderName + "\\" + filenameArray[self.currentFileToEditIndex] + ".modified") != None: UnexpectedError = "Error while trying to copy modified file %s!" % self.FileToEditWithPath[self.currentFileToEditIndex] self.PrintToScreenAndFile(UnexpectedError, False) raise RuntimeError, UnexpectedError self.PrintToScreenAndFile("Modified file %s has been copied as %s" % (self.FileToEditWithPath[self.currentFileToEditIndex], filenameArray[self.currentFileToEditIndex] + ".modified"), True)
def ModifyAndBuildFaultInjectionFile(self, fileModificationsDictionary, TestName): makefileModificationsDictionaryRM = { \ 'makefile': [ \ # # # # # # # # # # # # # # # # # # # # # # # # # ''' # Start Fault Injection Point 1 # End Fault Injection Point 1 # Fault Injection Code Start RM :=cmd /C del /F /Q # Fault Injection Code End ''' ] } makefileModificationsDictionaryDEL = { \ 'makefile':[ \ # # # # # # # # # # # # # # # # # # # # # # # # # ''' # Start Fault Injection Point 2 # End Fault Injection Point 2 # Fault Injection Code Start -$(RM) ".\\apexbin.h" -$(RM) ".\\._2" -$(RM) ".\\._4" -$(RM) ".\\apex.*" -$(RM) ".\\*.bin" -$(RM) ".\\OS\\*.o" -$(RM) ".\\OS\\*.d" -$(RM) ".\\*.o" -$(RM) ".\\*.d" -$(RM) ".\\ControlBus\\*.o" -$(RM) ".\\ControlBus\\*.d" -$(RM) ".\\OS\\*.o" -$(RM) ".\\OS\\*.d" -$(RM) ".\\Utility\\*.o" -$(RM) ".\\Utility\\*.d" # Fault Injection Code End ''' ] } if len(sys.argv) != 0 : if sys.argv[1] == "BlackfinDiag" : self.ProductName = BLACKFIN_PRODUCT_NAME self.Init(TestName) self.DiagEditPath = self.ViewPath + "\\" + BLACKFIN_PRODUCT_FOLDER + "\\" + BLACKFIN_DIAG_PATH self.CleanBuildCmd = ".\\" + BLACKFIN_BUILD_SCRIPT + " " + self.BranchPath + " " + BLACKFIN_PROJECT_FOLDER + " " + BLACKFIN_MAKE_CLEAN_CMD self.BuildExecutableCmd = ".\\" + BLACKFIN_BUILD_SCRIPT + " " + self.BranchPath + " " + BLACKFIN_PROJECT_FOLDER + " " + BLACKFIN_MAKE_CMD self.ResultsOfBuildFolder = self.ViewPath + "\\" + BLACKFIN_PRODUCT_FOLDER + "\\" + BLACKFIN_PROJECT_FOLDER + "\\" + BLACKFIN_BUILD_TYPE_FOLDER self.MakeFileWithPath = "" elif sys.argv[1] == "BlackfinOS" : self.ProductName = BLACKFIN_PRODUCT_NAME self.Init(TestName) self.DiagEditPath = self.ViewPath + "\\" + BLACKFIN_PRODUCT_FOLDER + "\\" + BLACKFIN_OS_PATH self.CleanBuildCmd = ".\\" + BLACKFIN_BUILD_SCRIPT + " " + self.BranchPath + " " + BLACKFIN_PROJECT_FOLDER + " " + BLACKFIN_MAKE_CLEAN_CMD self.BuildExecutableCmd = ".\\" + BLACKFIN_BUILD_SCRIPT + " " + self.BranchPath + " " + BLACKFIN_PROJECT_FOLDER + " " + BLACKFIN_MAKE_CMD self.ResultsOfBuildFolder = self.ViewPath + "\\" + BLACKFIN_PRODUCT_FOLDER + "\\" + BLACKFIN_PROJECT_FOLDER + "\\" + BLACKFIN_BUILD_TYPE_FOLDER self.MakeFileWithPath = "" elif sys.argv[1] == "ApexDiag" : self.ProductName = APEX_PRODUCT_NAME self.Init(TestName) self.DiagEditPath = self.ViewPath + "\\" + APEX_PRODUCT_FOLDER + "\\" + APEX_DIAG_PATH self.CleanBuildCmd = ".\\" + APEX_BUILD_SCRIPT + " " + self.BranchPath + " " + APEX_MAKE_CLEAN_CMD self.BuildExecutableCmd = ".\\" + APEX_BUILD_SCRIPT + " " + self.BranchPath + " " + APEX_MAKE_CMD self.ResultsOfBuildFolder = self.ViewPath + "\\" + APEX_PRODUCT_FOLDER + "\\" + APEX_PROJECT_FOLDER self.MakeFileWithPath = self.ViewPath + "\\" + APEX_PRODUCT_FOLDER + "\\" + APEX_PROJECT_FOLDER + "\\makefile" if clearcase.isCheckedOut(self.MakeFileWithPath): if clearcase.uncheckout(self.MakeFileWithPath, keep = True) != None: UnexpectedError = "Error while trying to uncheckout file %s!" % self.MakeFileWithPath self.PrintToScreenAndFile(UnexpectedError, False) raise RuntimeError, UnexpectedError UnexpectedError = "File %s already Checked Out!" % self.MakeFileWithPath self.PrintToScreenAndFile(UnexpectedError, False) raise RuntimeError, UnexpectedError self.PrintToScreenAndFile("File %s is not already checked out" % self.MakeFileWithPath, True) # Check the file out. self.PrintToScreenAndFile("Checking out file %s" % self.MakeFileWithPath, True) if clearcase.checkout(self.MakeFileWithPath, False, 'Temporary Checkout for Fault Injection Test.') != None: UnexpectedError = "Error while trying to checkout file %s!" % self.MakeFileWithPath self.PrintToScreenAndFile(UnexpectedError, False) raise RuntimeError, UnexpectedError self.PrintToScreenAndFile("File %s has been checked out." % self.MakeFileWithPath, True) # Modify the file. self.ModifyFile(makefileModificationsDictionaryRM, "makefile", self.MakeFileWithPath) self.ModifyFile(makefileModificationsDictionaryDEL, "makefile", self.MakeFileWithPath) elif sys.argv[1] == "ApexOS" : self.ProductName = APEX_PRODUCT_NAME self.Init(TestName) self.DiagEditPath = self.ViewPath + "\\" + APEX_PRODUCT_FOLDER + "\\" + APEX_OS_PATH self.CleanBuildCmd = ".\\" + APEX_BUILD_SCRIPT + " " + self.BranchPath + " " + APEX_MAKE_CLEAN_CMD self.BuildExecutableCmd = ".\\" + APEX_BUILD_SCRIPT + " " + self.BranchPath + " " + APEX_MAKE_CMD self.ResultsOfBuildFolder = self.ViewPath + "\\" + APEX_PRODUCT_FOLDER + "\\" + APEX_PROJECT_FOLDER self.MakeFileWithPath = self.ViewPath + "\\" + APEX_PRODUCT_FOLDER + "\\" + APEX_PROJECT_FOLDER + "\\makefile" if clearcase.isCheckedOut(self.MakeFileWithPath): if clearcase.uncheckout(self.MakeFileWithPath, keep = True) != None: UnexpectedError = "Error while trying to uncheckout file %s!" % self.MakeFileWithPath self.PrintToScreenAndFile(UnexpectedError, False) raise RuntimeError, UnexpectedError UnexpectedError = "File %s already Checked Out!" % self.MakeFileWithPath self.PrintToScreenAndFile(UnexpectedError, False) raise RuntimeError, UnexpectedError self.PrintToScreenAndFile("File %s is not already checked out" % self.MakeFileWithPath, True) # Check the file out. self.PrintToScreenAndFile("Checking out file %s" % self.MakeFileWithPath, True) if clearcase.checkout(self.MakeFileWithPath, False, 'Temporary Checkout for Fault Injection Test.') != None: UnexpectedError = "Error while trying to checkout file %s!" % self.MakeFileWithPath self.PrintToScreenAndFile(UnexpectedError, False) raise RuntimeError, UnexpectedError self.PrintToScreenAndFile("File %s has been checked out." % self.MakeFileWithPath, True) # Modify the file. self.ModifyFile(makefileModificationsDictionaryRM, "makefile", self.MakeFileWithPath) self.ModifyFile(makefileModificationsDictionaryDEL, "makefile", self.MakeFileWithPath) else : raise RuntimeError, "Invalid command line arg" self.ModifyFileBuildFaultInjectionTest(fileModificationsDictionary, TestName)