def UndoCheckouts(self): self.PrintToScreenAndFile("Undoing Checkouts...", True) for currentFileToEditIndex in range(0, self.FileToEditIndex + 1): if ClearCase.isCheckedOut(self.FileToEditWithPath[currentFileToEditIndex]): self.PrintToScreenAndFile("Undoing checkout of file %s..." % self.FileToEditWithPath[currentFileToEditIndex], True) if ClearCase.uncheckout(self.FileToEditWithPath[currentFileToEditIndex], keep = True) != None: UnexpectedError = "Error while trying to uncheckout file %s!" % self.FileToEditWithPath[currentFileToEditIndex] self.PrintToScreenAndFile(UnexpectedError, False) raise RuntimeError, UnexpectedError self.PrintToScreenAndFile("File %s has been unchecked out" % self.FileToEditWithPath[currentFileToEditIndex], True)
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.IsFileFoundInAllowedFolders(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]) # Copy the modified file to the build results folder. self.PrintToScreenAndFile("Copying modified file %s" % self.FileToEditWithPath[self.currentFileToEditIndex], True) if shutil.copy(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)