def UndoCheckouts(self):
        FailureToUncheckAll = False

        if self.MakeFileWithPath != "" :
            if clearcase.isCheckedOut(self.MakeFileWithPath):
                self.PrintToScreenAndFile("Undoing makefile checkout", True)
                if clearcase.uncheckout(self.MakeFileWithPath):
                    UnexpectedError = "Error while trying to uncheckout makefile"
                    self.PrintToScreenAndFile(UnexpectedError,False)
                    FailureToUncheckAll = True
        
        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)
                    FailureToUncheckAll = True
                else:
                    self.PrintToScreenAndFile("File %s has been unchecked out" % self.FileToEditWithPath[currentFileToEditIndex], True)
        if FailureToUncheckAll == True:
            raise RuntimeError, "Unable to Checkout All Files"
    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)