def undo(self):
     copyDirOrFile(self.dst, self.src)
    def __init__(self, module):
        """
        Constructor
        """
        # Initialize application server object
        appServer = ApplicationServer(module, scriptGlobals.appsrvProperties)

        # Check if JBOSS is running
        if getProcessPIDByPathAndIdentifier(module.targetDeploymentPath, appServer.processIdentifier):
            die("The JBOSS server at '" + module.targetDeploymentPath + "' is up. Installation will not continue")

        # Since CRM is deployed on JBOSS some paths have an %s to allow a configurable
        # profile, so do a little sprintf to fix them
        sprintfOnDictionaryValues(module.relativeConfigurationFiles, module.targetDeploymentProfile)
        sprintfOnDictionaryValues(module.relativeCopyableFilesOrFolders, module.targetDeploymentProfile)

        # Prepare directory to keep backups
        previousVersionBackupPath = createDirectoriesRecursively(
            scriptGlobals.workingDir + scriptGlobals.osDirSeparator + "previousVersionBackup"
        )

        # Backup crm-deployment.properties from conf
        # Backup mgage.properties from conf
        # Backup jboss-log4j.xml from conf
        for k, v in module.relativeConfigurationFiles.items():
            exactLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
            exactBackupLocation = previousVersionBackupPath + scriptGlobals.osDirSeparator + k
            copyDirOrFile(exactLocation, exactBackupLocation)  # we do not to have do/undo actions for such operation

        # Backup crm-dtds from docs/dtd
        # Backup crm.war from deploy
        # Backup esb.jar from deploy/
        # Backup ROOT.WAR/crossdmain.xml from deploy/ROOT.WAR
        for k, v in module.relativeCopyableFilesOrFolders.items():
            exactLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
            exactBackupLocation = previousVersionBackupPath + scriptGlobals.osDirSeparator + k
            copyDirOrFile(exactLocation, exactBackupLocation)  # we do not to have do/undo actions for such operation

        # Prepare directory to unpack package
        unzippedPackagePath = createDirectoriesRecursively(
            scriptGlobals.workingDir + scriptGlobals.osDirSeparator + "unzippedPackage"
        )

        # Extract CRM package into tmp dir
        ExtractZipToDir(module.moduleFilename, unzippedPackagePath)

        # Determine last executed script in DB
        dbUsername = readPropertyFromPropertiesFile("VNA_CRM_USERNAMEBASE", module.name, lib.OptParser.options.envprops)
        dbPassword = readPropertyFromPropertiesFile("VNA_CRM_PASSWORDBASE", module.name, lib.OptParser.options.envprops)

        tmpC = readPropertyFromPropertiesFile("DBConnectionString", module.name, lib.OptParser.options.envprops)

        # If string is Clustered string
        if tmpC.lower().find("description") > 0:
            dbConnectionString = tmpC
        else:
            dbHost = tmpC[0 : tmpC.find(":")]
            dbPort = tmpC[tmpC.find(":") + 1 : tmpC.rfind(":")]
            dbSID = tmpC[tmpC.rfind(":") + 1 : len(tmpC)]
            dbConnectionString = (
                "(DESCRIPTION=(LOAD_BALANCE=yes)(ADDRESS=(PROTOCOL=TCP)(HOST=%s)(PORT=%s))(CONNECT_DATA=(SID=%s)))"
                % (dbHost, dbPort, dbSID)
            )

        finalConnectionString = "%s/%s@%s" % (dbUsername, dbPassword, dbConnectionString)

        result = runOracleScript(
            "SELECT EXECUTED_SCRIPT FROM FIREWORKS_SCRIPT_LOG WHERE EXECUTED_ON IN (SELECT MAX(EXECUTED_ON) FROM FIREWORKS_SCRIPT_LOG);",
            finalConnectionString,
            False,
            True,
        )
        lastExecutedPath, lastExecutedFilename = os.path.split(result.strip())

        currentVersion = grepFile(
            module.versionInformationRegex,
            previousVersionBackupPath + scriptGlobals.osDirSeparator + module.relativeVersionInformationPath,
        )
        newVersion = grepFile(
            module.versionInformationRegex,
            unzippedPackagePath + scriptGlobals.osDirSeparator + module.relativeVersionInformationPath,
        )
        currentRevision = grepFile(
            module.revisionInformationRegex,
            previousVersionBackupPath + scriptGlobals.osDirSeparator + module.relativeVersionInformationPath,
        )
        newRevision = grepFile(
            module.revisionInformationRegex,
            unzippedPackagePath + scriptGlobals.osDirSeparator + module.relativeVersionInformationPath,
        )

        currentVersion = (currentVersion.replace(module.versionInformationRegex, "")).strip()
        newVersion = (newVersion.replace(module.versionInformationRegex, "")).strip()
        currentRevision = (currentRevision.replace(module.revisionInformationRegex, "")).strip()
        newRevision = (newRevision.replace(module.revisionInformationRegex, "")).strip()
        currentDirSize = getDirectoryRecursiveSize(previousVersionBackupPath)
        newDirSize = getDirectoryRecursiveSize(unzippedPackagePath)

        # Information Header
        log.info(informationAsciiHeader())

        labels = ("", "Currently Installed Module", "Module To Be Installed")
        data = """Version, %s, %s
           Revision, %s, %s
           Dir Size, %s, %s           
        """ % (
            currentVersion,
            newVersion,
            currentRevision,
            newRevision,
            currentDirSize,
            newDirSize,
        )

        rows = [row.strip().split(",") for row in data.splitlines()]
        log.info("\n\n" + indent([labels] + rows, hasHeader=True))
        log.info("Last script executed on '" + finalConnectionString + "' was '" + lastExecutedFilename + "'")
 def __call__(self):
     copyDirOrFile(self.src, self.dst)