def RemoveDeployedApplication(AppToRemove): try: DeployLogger.info("Checking if " + AppToRemove + " exists before trying to remove.") if os.path.exists(AppToRemove): # Check if File is Read only: if not os.access(AppToRemove, os.W_OK): # Directory or File is read-only, make it deleteable: genfunc.Chmod0777(AppToRemove) DeployLogger.info(AppToRemove + " exists - removing.") # Remove File: os.remove(AppToRemove) else: DeployLogger.info(AppToRemove + " does not exists - not removing.") except Exception as e: DeployLogger.error("Undeploying/Removing File " + AppToRemove + " failed.") DeployLogger.error("Exception Information= ", sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]) config.HasError = True raise Exception(e) return
def RemoveDirsFiles(Path): DeployLogger.info("in RemoveDirsFiles: Path to remove dirs/files from = " + Path) try: DeployLogger.info("Deleting Dirs and Files in " + Path) # ------------------------------------------------------------------------- # Recurse through the directories and sub directories and delete files: for root, dirs, files in os.walk(Path, topdown=False): # Delete all the files for file in files: try: fullpath = os.path.join(root, file) DeployLogger.info("removing file = " + fullpath) # Check if File is Read only: if not os.access(fullpath, os.W_OK): # Directory or File is read-only, make it deleteable: genfunc.Chmod0777(fullpath) # Remove File: os.remove(fullpath) except OSError as ose: DeployLogger.error("OSError = ", ose) DeployLogger.error("Exception Information= ", sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]) config.HasError = True raise Exception(ose) except Exception as e: DeployLogger.error( "Exception in removing Files in RemoveDirsFiles() =", e) DeployLogger.error("Exception Information= ", sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]) config.HasError = True raise Exception(e) # ------------------------------------------------------------------------------------------- # Re-curse through the directories and sub directories and Delete all the sub-directories: for root, dirs, files in os.walk(Path, topdown=False): for dir in dirs: dirpath = os.path.join(root, dir) DeployLogger.info("removing directory " + dirpath) try: # Remove Directories: os.rmdir(dirpath) except OSError as ose: DeployLogger.error("OSError = ", ose) DeployLogger.error("Exception Information= ", sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]) config.HasError = True raise Exception(ose) except Exception as e: DeployLogger.error( "Exception in removing subdirectories in RemoveDirsFiles() =", e) DeployLogger.error("Exception Information= ", sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]) config.HasError = True raise Exception(e) except Exception as e: DeployLogger.error("Removing Dirs and Files in " + Path + " failed.") DeployLogger.error("Exception Information= ", sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]) config.HasError = True raise Exception(e) return
DeployLogger.info("Checking if " + config.Application + " exists before undeployment.") if os.path.exists( os.path.join(DeploymentsPath, config.Application + ".deployed")) == True: DeployLogger.info(config.Application + " exists, performing undeployment.") try: # Check if File is Read only: if not os.access( os.path.join(DeploymentsPath, config.Application), os.W_OK): # Directory or File is read-only, make it deleteable: genfunc.Chmod0777( os.path.join(DeploymentsPath, config.Application)) # Remove File: os.remove( os.path.join(DeploymentsPath, config.Application)) # Give deployment scanner time to see application was undeployed/removed time.sleep(5) # Check if .doundeploy file exists, if so remove it. if os.path.exists( os.path.join( DeploymentsPath, config.Application + ".doundeploy")) == True: # Check if File is Read only: