Example #1
0
def copyDataFolders(srcRootPath, destRootPath, ownerAccount=None):
    copySuccess = True
    
    # Check if there is available space on destination drive
    # to copy folders.
    freeSpace = getFreeSpace(destRootPath, "GB")
    
    # Get total size of source folders
    srcSize = getDirSize(srcRootPath, "GB")

    print '{:<34}{:>10.4f}{:>3}'.format("Available space to copy folders:", freeSpace, " GB")
    print '{:<34}{:>10.4f}{:>3}'.format("Size of folders to copy:", srcSize, " GB")
    print
        
    if srcSize >= freeSpace:
        totalCopySuccess = False
        print
        print "ERROR: Not enough available space to copy folders/files."
        print 
    else:
        
        # Get list of top-level directories and files
        returnFolders = 1   #Yes
        recursive = 0       #No
        dirList = listFiles(srcRootPath, "*", recursive, returnFolders)
        
        x = 0
        for srcPath in dirList:
            # List may have files so test for directory
            if os.path.isdir(srcPath):
                pathType = "Folder"
            elif os.path.isfile(srcPath):
                pathType = "File"
            else:
                pathType = ""
                
            # "Create" destination path
            destPath = os.path.join(destRootPath, os.path.basename(srcPath))
            
            print
            print "- Copying " + pathType.lower() + "..."
            print '{:<16}{:<100}'.format("\tSource:", srcPath)
            print '{:<16}{:<100}'.format("\tDestination:", destPath)
            
            # Copy data and check results
            results = copyData(srcPath, destPath)
            success = checkResults(results, printMsg)
            if not success:
                copySuccess = success
                
            # Change ownership function doesn't seem to be working
            # so for time being lets comment out this function call.
            # if not success:
            #     copySuccess = success
            # else:
            #     if ownerAccount:
            #         changeOwnership(destPath, ownerAccount)
                    
    return copySuccess
Example #2
0
def createAGSConnFile(username, password):

    success = True
    printMsg = True

    try:
        print
        print "--Create ArcGIS Administrative connection file..."
        print
        
        # Set connection folder and file variables
        fileRoot = "ops-server-config"
        scriptPath = sys.argv[0]
        agsConnFolderPath = scriptPath[:(scriptPath.find(fileRoot) + len(fileRoot))]
        agsConnFile = "OpsServer_admin.ags"
        agsConnFilePath = agsConnFolderPath + os.sep + agsConnFile
        
        # Create ArcGIS Server connection file
        print "\tCreating admin connection file " + agsConnFilePath + "..."
        
        results = createAGSConnectionFile(agsConnFolderPath, agsConnFile, servername,
                            username, password, serverPort)
        success = checkResults(results, printMsg)
            
    except:
        success = False
        
        # Get the traceback object
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]
     
        # Concatenate information together concerning the error into a message string
        pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
        
        # Print Python error messages for use in Python / Python Window
        print
        print "***** ERROR ENCOUNTERED *****"
        print pymsg + "\n"
        
    finally:
        # Return success flag
        return success    
def createAGSConnFile(servername, username, password, serverport, useSSL):

    success = True
    printMsg = True
    agsConnFilePath = None

    try:

        # Set connection folder and file variables
        agsConnFolderPath = os.path.dirname(sys.argv[0])
        agsConnFile = "OpsServer_publish.ags"
        agsConnFilePath = os.path.join(agsConnFolderPath, agsConnFile)

        results = createAGSConnectionFile(agsConnFolderPath, agsConnFile,
                                          servername, username, password,
                                          serverport, useSSL,
                                          "PUBLISH_GIS_SERVICES")

        success = checkResults(results, printMsg)

        if not os.path.exists(agsConnFilePath):
            agsConnFilePath = None

    except:
        success = False

        # Get the traceback object
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]

        # Concatenate information together concerning the error into a message string
        pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(
            sys.exc_info()[1])

        # Print Python error messages for use in Python / Python Window
        print
        print "***** ERROR ENCOUNTERED *****"
        print pymsg + "\n"

    finally:
        # Return success flag
        return agsConnFilePath
def createAGSConnFile(servername, username, password, serverport, useSSL):

    success = True
    printMsg = True
    agsConnFilePath = None
    
    try:
        
        # Set connection folder and file variables
        agsConnFolderPath = os.path.dirname(sys.argv[0])
        agsConnFile = "OpsServer_publish.ags"
        agsConnFilePath = os.path.join(agsConnFolderPath, agsConnFile)
        
        results = createAGSConnectionFile(agsConnFolderPath, agsConnFile, servername,
                            username, password, serverport, useSSL, "PUBLISH_GIS_SERVICES")
        
        success = checkResults(results, printMsg)
        
        if not os.path.exists(agsConnFilePath):
            agsConnFilePath = None
            
    except:
        success = False
        
        # Get the traceback object
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]
     
        # Concatenate information together concerning the error into a message string
        pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
        
        # Print Python error messages for use in Python / Python Window
        print
        print "***** ERROR ENCOUNTERED *****"
        print pymsg + "\n"
        
    finally:
        # Return success flag
        return agsConnFilePath
def repairMosaicDatasets(dataDrive):
    
    try:
        
        totalSuccess = True
        
        newPath = OpsServerConfig.getEnvDataRootPath(dataDrive)

        # "Create" RepairMosaicDatasetPaths GP tool Original Path/New Path
        # parameter string
        repairOrigNewPath = ""
        for regName in installOnlyPublishingFolders.keys():
            repairOrigNewPath = repairOrigNewPath + "; " + \
                    installOnlyPublishingFolders[regName] + " " + newPath
        # Remove leading semicolon
        repairOrigNewPath = repairOrigNewPath.replace("; ", "", 1)

        rootSearchPath = newPath
        
        # Get list of all folders ending in ".gdb"
        print
        print "Searching " + rootSearchPath + " looking for file geodatabases..."
        gdbList = findFolderPath(rootSearchPath, "*.gdb", False)
        
        # Ensure that list only contains entries that are local geodatabase
        # (file geodatabase); just in case there happens to be a folder with ".gdb"
        # that is not a geodatabase
        gdbList[:] = [gdb for gdb in gdbList if
                      arcpy.Describe(gdb).workspaceType.upper() == "LOCALDATABASE"]
        
        # Loop through all file geodatabases and repair paths for any non-referenced
        # mosaic datasets
        for gdb in gdbList:
            print
            print "Found file geodatabase: " + gdb
            print "\tChecking for existence of non-referenced mosaic datasets..."
            
            # Get any mosaic datasets in geodatabase
            arcpy.env.workspace = gdb
            mdList = arcpy.ListDatasets("*", "Mosaic")
            
            # Modify list to contain only non-reference mosaic datasets
            mdList[:] = [md for md in mdList if not arcpy.Describe(md).referenced]
            
            if len(mdList) == 0:
                print "\tNone found."
            else:
                print "\tFound " + str(len(mdList)) + " non-referenced mosaic dataset(s)."
            
            for md in mdList:
                print
                print "\tRepairing paths in mosaic dataset '" + md + "'..."
                results = repairMosaicDatasetPaths(md, repairOrigNewPath)
                success = checkResults(results, printMsg)
                if not success:
                    totalSuccess = success
    
    except:
        
        # Get the traceback object
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]
     
        # Concatenate information together concerning the error into a message string
        pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
     
        # Print Python error messages for use in Python / Python Window
        print
        print "***** ERROR ENCOUNTERED *****"
        print pymsg + "\n"
        
    finally:
        print
        print
        if totalSuccess:
            print "Done repairing mosaic dataset paths."
        else:
            print "ERROR occurred during mosaic dataset path repair."
        print
        
        return totalSuccess
Example #6
0
                print
                print "\tERROR: Network Analyst extension license unavailable. Can't copy databases."
                print

        if continueCopy:
            for db in dbsToCopy:
                print
                print "- Copying " + db.upper() + " database data..."
                srcPath = srcDBs[db]
                destPath = destDBs[db]
                print "{:<14}{:<100}".format("\tSource:", srcPath)
                print "{:<14}{:<100}".format("\tDestination:", destPath)
                print
                results = copyGDBData(srcPath, destPath)
                print
                success = checkResults(results, printMsg)
                if not success:
                    totalCopySuccess = success

    # ---------------------------------------------------------------------
    # Copy Folders (except cache folders)
    # ---------------------------------------------------------------------

    if copyFolders:

        print "--------------------------------------------"
        print "Copy folders..."
        print "--------------------------------------------"

        success = copyDataFolders(StagingFolder, DestinationFolder, agsServerAccount)
        if not success:
Example #7
0
                print
                print "\tERROR: Network Analyst extension license unavailable. Can't copy databases."
                print

        if continueCopy:
            for db in dbsToCopy:
                print
                print "- Copying " + db.upper() + " database data..."
                srcPath = srcDBs[db]
                destPath = destDBs[db]
                print '{:<14}{:<100}'.format("\tSource:", srcPath)
                print '{:<14}{:<100}'.format("\tDestination:", destPath)
                print
                results = copyGDBData(srcPath, destPath)
                print
                success = checkResults(results, printMsg)
                if not success:
                    totalCopySuccess = success

    # ---------------------------------------------------------------------
    # Copy Folders (except cache folders)
    # ---------------------------------------------------------------------

    if copyFolders:

        print "--------------------------------------------"
        print "Copy folders..."
        print "--------------------------------------------"

        success = copyDataFolders(StagingFolder, DestinationFolder,
                                  agsServerAccount)
def repairMosaicDatasets(dataDrive):

    try:

        totalSuccess = True

        newPath = OpsServerConfig.getEnvDataRootPath(dataDrive)

        # "Create" RepairMosaicDatasetPaths GP tool Original Path/New Path
        # parameter string
        repairOrigNewPath = ""
        for regName in installOnlyPublishingFolders.keys():
            repairOrigNewPath = repairOrigNewPath + "; " + \
                    installOnlyPublishingFolders[regName] + " " + newPath
        # Remove leading semicolon
        repairOrigNewPath = repairOrigNewPath.replace("; ", "", 1)

        rootSearchPath = newPath

        # Get list of all folders ending in ".gdb"
        print
        print "Searching " + rootSearchPath + " looking for file geodatabases..."
        gdbList = findFolderPath(rootSearchPath, "*.gdb", False)

        # Ensure that list only contains entries that are local geodatabase
        # (file geodatabase); just in case there happens to be a folder with ".gdb"
        # that is not a geodatabase
        gdbList[:] = [
            gdb for gdb in gdbList
            if arcpy.Describe(gdb).workspaceType.upper() == "LOCALDATABASE"
        ]

        # Loop through all file geodatabases and repair paths for any non-referenced
        # mosaic datasets
        for gdb in gdbList:
            print
            print "Found file geodatabase: " + gdb
            print "\tChecking for existence of non-referenced mosaic datasets..."

            # Get any mosaic datasets in geodatabase
            arcpy.env.workspace = gdb
            mdList = arcpy.ListDatasets("*", "Mosaic")

            # Modify list to contain only non-reference mosaic datasets
            mdList[:] = [
                md for md in mdList if not arcpy.Describe(md).referenced
            ]

            if len(mdList) == 0:
                print "\tNone found."
            else:
                print "\tFound " + str(
                    len(mdList)) + " non-referenced mosaic dataset(s)."

            for md in mdList:
                print
                print "\tRepairing paths in mosaic dataset '" + md + "'..."
                results = repairMosaicDatasetPaths(md, repairOrigNewPath)
                success = checkResults(results, printMsg)
                if not success:
                    totalSuccess = success

    except:

        # Get the traceback object
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]

        # Concatenate information together concerning the error into a message string
        pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(
            sys.exc_info()[1])

        # Print Python error messages for use in Python / Python Window
        print
        print "***** ERROR ENCOUNTERED *****"
        print pymsg + "\n"

    finally:
        print
        print
        if totalSuccess:
            print "Done repairing mosaic dataset paths."
        else:
            print "ERROR occurred during mosaic dataset path repair."
        print

        return totalSuccess