def main(argv = None):
    # main function - list the source and target datasets, then delete rows/append where there is a match on non-prefixed name
    arcpy.AddToolbox(os.path.join(os.path.dirname(sys.path[0]),"Gizinta.tbx"))
    success = True
    try:

        gzSupport.addMessage("Getting list of datasets for Target " + targetGDB)
        targets = gzSupport.listDatasets(targetGDB)
        tNames = targets[0]
        tFullNames = targets[1]

        gzSupport.addMessage("Getting list of datasets for Source " + sourceGDB)
        sources = gzSupport.listDatasets(sourceGDB)
        sNames = sources[0]
        sFullNames = sources[1]

        t = 0
        arcpy.SetProgressor("Step","Creating Files...",0,len(tNames),1)
        
        for name in tNames:
            arcpy.SetProgressorPosition(t)
            arcpy.SetProgressorLabel("Creating file for " + name + "...")
            # for each source name
            if debug:
                gzSupport.addMessage(name)
            try:
                # look for the matching name in target names
                s = sNames.index(name)
            except:
                # will get here if no match
                s = -1
            if s > -1:
                # create file if there is a match
                fileName = outputFolder + os.sep + prefixStr + name.title() + ".xml"
                if os.path.exists(fileName):
                    os.remove(fileName)
                try:
                    arcpy.gzCreateProject_gizinta(sFullNames[s],tFullNames[t],fileName)
                    retVal = True
                    gzSupport.addMessage("Created "  + fileName)
                except:
                    retVal = False
                if retVal == False:                    
                    gzSupport.addMessage("Failed to create file for "  + name)
                    gzSupport.showTraceback()
                    success = False
            else:
                gzSupport.addMessage("Skipping "  + name)
            t = t + 1
    except:
        gzSupport.showTraceback()
        arcpy.AddError(pymsg)
        success = False

    finally:
        arcpy.ResetProgressor()
        arcpy.SetParameter(gzSupport.successParameterNumber, success)
        arcpy.env.workspace = targetGDB
        arcpy.RefreshCatalog(outputFolder)
        gzSupport.closeLog()
Beispiel #2
0
def main(argv = None):
    # main function - list the datasets and delete rows
    success = True
    try:
        names = gzSupport.listDatasets(sourceGDB)
        tNames = names[0]
        tFullNames = names[1]
        arcpy.SetProgressor("Step","Deleting rows...",0,len(tFullNames),1)
        i = 0
        for name in tFullNames:
            arcpy.SetProgressorPosition(i)
            arcpy.SetProgressorLabel(" Deleting rows in " + name + "...")
            # for each full name
            if len(datasetNames) == 0 or tNames[i].upper() in datasetNames:
                retVal = doTruncate(name)
                gzSupport.logDatasetProcess(name,"deleteRowsGDB",retVal)
                if retVal == False:
                    success = False
            else:
                gzSupport.addMessage("Skipping "  + tNames[i])
            i += i
    except:
        gzSupport.showTraceback()
        gzSupport.addError(pymsg)
        success = False
        gzSupport.logDatasetProcess(name,"deleteRowsGDB",success)
    finally:
        arcpy.SetParameter(SUCCESS, success)
        arcpy.ResetProgressor()
        gzSupport.closeLog()
        arcpy.ClearWorkspaceCache_management(sourceGDB)
Beispiel #3
0
def main(argv=None):
    success = True
    gzSupport.compressGDB(gzSupport.workspace)
    arcpy.ClearWorkspaceCache_management(gzSupport.workspace)
    tables = gzSupport.listDatasets(gzSupport.workspace)
    tNames = tables[0]
    tFullNames = tables[1]
    name = ''

    for dataset in datasets:
        arcpy.env.Workspace = gzSupport.workspace
        name = dataset.getAttributeNode("name").nodeValue
        table = gzSupport.getFullName(name, tNames, tFullNames)
        gzSupport.sourceIDField = dataset.getAttributeNode(
            "sourceIDField").nodeValue
        gzSupport.sourceNameField = dataset.getAttributeNode(
            "sourceNameField").nodeValue
        if not arcpy.Exists(table):
            gzSupport.addError("Feature Class " + table +
                               " does not exist, exiting")
            arcpy.SetParameter(SUCCESS, False)
            return
        if not arcpy.TestSchemaLock(table):
            gzSupport.addError("Unable to obtain a schema lock for " + table +
                               ", exiting")
            arcpy.SetParameter(SUCCESS, False)
            return -1
        desc = arcpy.Describe(table)
        fields = dataset.getElementsByTagName("Field")
        try:
            attrs = [f.name for f in arcpy.ListFields(table)]
            for field in fields:
                arcpy.env.Workspace = gzSupport.workspace
                targetName = gzSupport.getNodeValue(field, "TargetName")
                gzSupport.addGizintaField(table, targetName, field, attrs)

            retVal = setFieldValues(table, fields)
            if retVal == False:
                success = False
            gzSupport.logDatasetProcess(name, "Fields", retVal)
            arcpy.ClearWorkspaceCache_management(gzSupport.workspace)
            gzSupport.cleanupGarbage()

        except:
            gzSupport.showTraceback()
            success = False
            gzSupport.logDatasetProcess("fieldCalculator", name, False)
        finally:
            arcpy.RefreshCatalog(table)
            arcpy.ClearWorkspaceCache_management(gzSupport.workspace)
    if success == False:
        gzSupport.addError(
            "Errors occurred during process, look in log file tools\\log\\fieldCalculator.log for more information"
        )
    if gzSupport.ignoreErrors == True:
        success = True
    arcpy.SetParameter(SUCCESS, success)
    arcpy.ResetProgressor()
    gzSupport.closeLog()
    return
Beispiel #4
0
def main(argv=None):
    # main function - list the datasets and delete rows
    success = True
    try:
        names = gzSupport.listDatasets(sourceGDB)
        tNames = names[0]
        tFullNames = names[1]
        arcpy.SetProgressor("Step", "Deleting rows...", 0, len(tFullNames), 1)
        i = 0
        for name in tFullNames:
            arcpy.SetProgressorPosition(i)
            arcpy.SetProgressorLabel(" Deleting rows in " + name + "...")
            # for each full name
            if len(datasetNames) == 0 or tNames[i].upper() in datasetNames:
                retVal = doTruncate(name)
                gzSupport.logDatasetProcess(name, "deleteRowsGDB", retVal)
                if retVal == False:
                    success = False
            else:
                gzSupport.addMessage("Skipping " + tNames[i])
            i += i
    except:
        gzSupport.showTraceback()
        gzSupport.addError(pymsg)
        success = False
        gzSupport.logDatasetProcess(name, "deleteRowsGDB", success)
    finally:
        arcpy.SetParameter(SUCCESS, success)
        arcpy.ResetProgressor()
        gzSupport.closeLog()
        arcpy.ClearWorkspaceCache_management(sourceGDB)
Beispiel #5
0
def main(argv = None):
    # main function - list the datasets and delete rows
    success = True
    name = ''
    gzSupport.workspace = sourceGDB
    try:
        if len(datasetNames) == 0:
            names = gzSupport.listDatasets(sourceGDB)
            tNames = names[0]
        else:
            tNames = datasetNames
        arcpy.SetProgressor("Step","Deleting rows...",0,len(tNames),1)
        i = 0
        for name in tNames:
            arcpy.SetProgressorPosition(i)
            arcpy.SetProgressorLabel(" Deleting rows in " + name + "...")
            # for each full name
            if len(datasetNames) == 0 or gzSupport.nameTrimmer(name.upper()) in datasetNames:
                retVal = doTruncate(os.path.join(sourceGDB,name))
                gzSupport.logDatasetProcess("deleteRowsGDB",name,retVal)
                if retVal == False:
                    success = False
            else:
                gzSupport.addMessage("Skipping "  + gzSupport.nameTrimmer(name))
            i = i + i
    except:
        gzSupport.showTraceback()
        gzSupport.addError("Failed to delete rows")
        success = False
        gzSupport.logDatasetProcess("deleteRowsGDB",name,success)
    finally:
        arcpy.SetParameter(SUCCESS, success)
        arcpy.ResetProgressor()
        gzSupport.closeLog()
        arcpy.ClearWorkspaceCache_management(sourceGDB)
Beispiel #6
0
def main(argv = None):
    success = True
    gzSupport.compressGDB(gzSupport.workspace)
    tables = gzSupport.listDatasets(gzSupport.workspace)
    tNames = tables[0]
    tFullNames = tables[1]

    if len(datasets) > 0:
        progBar = len(datasets)
        arcpy.SetProgressor("step", "Running QA...", 0,progBar, 1)
    for dataset in datasets:
        arcpy.env.Workspace = gzSupport.workspace
        name = dataset.getAttributeNode("name").nodeValue
        gzSupport.sourceIDField = dataset.getAttributeNode("sourceIDField").nodeValue
        table = gzSupport.getFullName(name,tNames, tFullNames)
        #table = os.path.join(gzSupport.workspace,name)
        fields = dataset.getElementsByTagName("Field")
        name = ''
        try:
            # run qa for dataset
            qaRulesDataset = dataset.getAttributeNode("qa").nodeValue
            gzSupport.addMessage("\nRunning QA (" + qaRulesDataset + ") for " + name)
            retVal = runDatasetChecks(dataset,table,qaRulesDataset)
            if retVal == False:
                success = False

            for field in fields:
                sourceQA = False
                targetQA = False
                fieldName = gzSupport.getNodeValue(field,"TargetName")
                if sourceFieldQA.lower() == "true" and qaRulesDataset.find("CheckFields") > -1:
                    sourceQA = True
                    fieldName = gzSupport.getNodeValue(field,"SourceName")
                if targetFieldQA.lower() == "true" and qaRulesDataset.find("CheckFields") > -1:
                    targetQA = True
                    fieldName = gzSupport.getNodeValue(field,"TargetName")
                retVal = runFieldCheck(dataset,table,field,sourceQA,targetQA)
                if retVal == False:
                    success = False
                try:
                    gzSupport.logDatasetProcess(name,fieldName,retVal)
                except:
                    gzSupport.addMessage("Process not logged for field")
            arcpy.SetProgressorPosition()
        except:
            gzSupport.showTraceback()
            gzSupport.addError("Field Check Error")
            success = False
            gzSupport.logDatasetProcess("sourceTargetQA",name,False)
        finally:
            arcpy.ResetProgressor()
            arcpy.RefreshCatalog(table)
            arcpy.ClearWorkspaceCache_management(gzSupport.workspace)
    if success == False:
        gzSupport.addError("Errors occurred during process, look in log file tools\\log\\sourceTargetQA.log for more information")
    if gzSupport.ignoreErrors == True:
        success = True
    arcpy.SetParameter(SUCCESS, success)
    gzSupport.closeLog()
    return
Beispiel #7
0
def main(argv = None):
    # main function - list the source and target datasets, then append where there is a match on non-prefixed name
    success = True
    name = ''
    arcpy.ClearWorkspaceCache_management(gzSupport.workspace)
    try:
        if len(datasetNames) == 0:
            sources = gzSupport.listDatasets(sourceGDB)
            sNames = sources[0]
            sFullNames = sources[1]
            targets = gzSupport.listDatasets(targetGDB)
            tNames = targets[0]
            tFullNames = targets[1]
        else:
            sNames = datasetNames
        
        s = 0
        arcpy.SetProgressor("Step","Appending rows...",0,len(sNames),1)
        for name in sNames:
            arcpy.SetProgressorPosition(s)
            arcpy.SetProgressorLabel(" Appending rows in " + name + "...")
            # for each source name
            if debug:
                gzSupport.addMessage(name)
            target = os.path.join(targetGDB,name)
            if arcpy.Exists(target):
                # append if there is a match
                if len(datasetNames) == 0 or gzSupport.nameTrimmer(name) in datasetNames:
                    retVal = doAppend(os.path.join(sourceGDB,name),target)
                    gzSupport.logDatasetProcess("appendAlltoGDB",name,retVal)
                    if retVal == False:
                        success = False
                else:
                    gzSupport.addMessage("Skipping "  + gzSupport.nameTrimmer(name))

            s = s + 1
    except:
        gzSupport.showTraceback()
        gzSupport.addError("Unable to append datasets")
        success = False
        gzSupport.logDatasetProcess("appendAlltoGDB",name,success)
    finally:
        arcpy.SetParameter(SUCCESS, success)
        arcpy.ResetProgressor()
        gzSupport.closeLog()
        arcpy.ClearWorkspaceCache_management(targetGDB)
Beispiel #8
0
def main(argv = None):
    # main function - list the source and target datasets, then append where there is a match on non-prefixed name
    success = True
    arcpy.ClearWorkspaceCache_management(gzSupport.workspace)
    try:
        sources = gzSupport.listDatasets(sourceGDB)
        sNames = sources[0]
        sFullNames = sources[1]
        targets = gzSupport.listDatasets(targetGDB)
        tNames = targets[0]
        tFullNames = targets[1]
        s = 0
        arcpy.SetProgressor("Step","Appending rows...",0,len(sFullNames),1)
        for name in sNames:
            arcpy.SetProgressorPosition(s)
            arcpy.SetProgressorLabel(" Deleting rows in " + name + "...")
            # for each source name
            if debug:
                gzSupport.addMessage(name)
            try:
                # look for the matching name in target names
                t = tNames.index(name)
            except:
                # will get here if no match
                t = -1
            if t > -1:
                # append if there is a match
                if len(datasetNames) == 0 or gzSupport.nameTrimmer(name) in datasetNames:
                    retVal = doAppend(sFullNames[s],tFullNames[t])
                    gzSupport.logDatasetProcess(name,"appendAlltoGDB",retVal)
                    if retVal == False:
                        success = False
                else:
                    gzSupport.addMessage("Skipping "  + gzSupport.nameTrimmer(name))

            s = s + 1
    except:
        gzSupport.showTraceback()
        gzSupport.addError("Unable to append datasets")
        success = False
        gzSupport.logDatasetProcess(name,"appendAlltoGDB",success)
    finally:
        arcpy.SetParameter(SUCCESS, success)
        arcpy.ResetProgressor()
        gzSupport.closeLog()
        arcpy.ClearWorkspaceCache_management(targetGDB)
Beispiel #9
0
def main(argv=None):
    # main function - list the source and target datasets, then append where there is a match on non-prefixed name
    success = True
    arcpy.ClearWorkspaceCache_management(gzSupport.workspace)
    try:
        sources = gzSupport.listDatasets(sourceGDB)
        sNames = sources[0]
        sFullNames = sources[1]
        targets = gzSupport.listDatasets(targetGDB)
        tNames = targets[0]
        tFullNames = targets[1]
        s = 0
        arcpy.SetProgressor("Step", "Appending rows...", 0, len(sFullNames), 1)
        for name in sNames:
            arcpy.SetProgressorPosition(s)
            arcpy.SetProgressorLabel(" Deleting rows in " + name + "...")
            # for each source name
            if debug:
                gzSupport.addMessage(name)
            try:
                # look for the matching name in target names
                t = tNames.index(name)
            except:
                # will get here if no match
                t = -1
            if t > -1:
                # append if there is a match
                if len(datasetNames) == 0 or name.upper() in datasetNames:
                    retVal = doAppend(sFullNames[s], tFullNames[t])
                    gzSupport.logDatasetProcess(name, "appendAlltoGDB", retVal)
                    if retVal == False:
                        success = False
                else:
                    gzSupport.addMessage("Skipping " + name)

            s = s + 1
    except:
        gzSupport.showTraceback()
        gzSupport.addError(pymsg)
        success = False
        gzSupport.logDatasetProcess(name, "appendAlltoGDB", success)
    finally:
        arcpy.SetParameter(SUCCESS, success)
        arcpy.ResetProgressor()
        gzSupport.closeLog()
        arcpy.ClearWorkspaceCache_management(targetGDB)
Beispiel #10
0
def main(argv = None):
    success = True
    gzSupport.compressGDB(gzSupport.workspace)
    arcpy.ClearWorkspaceCache_management(gzSupport.workspace)
    tables = gzSupport.listDatasets(gzSupport.workspace)
    tNames = tables[0]
    tFullNames = tables[1]
    name = ''
    
    for dataset in datasets:
        arcpy.env.Workspace = gzSupport.workspace
        name = dataset.getAttributeNode("name").nodeValue
        table = gzSupport.getFullName(name,tNames,tFullNames)
        gzSupport.sourceIDField = dataset.getAttributeNode("sourceIDField").nodeValue
        gzSupport.sourceNameField = dataset.getAttributeNode("sourceNameField").nodeValue
        if not arcpy.Exists(table):
            gzSupport.addError("Feature Class " + table + " does not exist, exiting")
            arcpy.SetParameter(SUCCESS, False)
            return
        if not arcpy.TestSchemaLock(table):
            gzSupport.addError("Unable to obtain a schema lock for " + table + ", exiting")
            arcpy.SetParameter(SUCCESS, False)
            return -1
        desc = arcpy.Describe(table)
        fields = dataset.getElementsByTagName("Field")
        try:
            attrs = [f.name for f in arcpy.ListFields(table)]
            for field in fields:
                arcpy.env.Workspace = gzSupport.workspace
                targetName = gzSupport.getNodeValue(field,"TargetName")
                gzSupport.addGizintaField(table,targetName,field,attrs)

            retVal = setFieldValues(table,fields)
            if retVal == False:
                success = False
            gzSupport.logDatasetProcess(name,"Fields",retVal)
            arcpy.ClearWorkspaceCache_management(gzSupport.workspace)
            gzSupport.cleanupGarbage()

        except:
            gzSupport.showTraceback()
            success = False
            gzSupport.logDatasetProcess("fieldCalculator",name,False)
        finally:
            arcpy.RefreshCatalog(table)
            arcpy.ClearWorkspaceCache_management(gzSupport.workspace)
    if success == False:
        gzSupport.addError("Errors occurred during process, look in log file tools\\log\\fieldCalculator.log for more information")
    if gzSupport.ignoreErrors == True:
        success = True
    arcpy.SetParameter(SUCCESS, success)
    arcpy.ResetProgressor()
    gzSupport.closeLog()
    return
def main(argv=None):
    global targetWorkspace
    hasVersion = False
    desc = arcpy.Describe(gzSupport.workspace)
    if desc.workspaceType != "RemoteDatabase" and versionName == None:
        targetWorkspace = defaultWorkspace
    success = True
    arcpy.ResetProgressor()
    arcpy.env.Workspace = gzSupport.workspace
    uniqueValues = gzSupport.getFieldValues("Unique", fieldNames, datasets)[0]
    sources = gzSupport.listDatasets(gzSupport.workspace)
    sNames = sources[0]
    sFullNames = sources[1]
    arcpy.SetProgressor("Step", "Load by " + str(fieldNames) + "...", 0, len(uniqueValues) * len(datasets), 1)
    for value in uniqueValues:
        try:
            hasVersion = False
            gzSupport.addMessage(value)
            if desc.workspaceType == "RemoteDatabase" and versionName != None:
                arcpy.SetProgressorLabel("Creating Version " + versionName)
                hasVersion = gzSupport.createVersion(defaultWorkspace, defaultVersionName, versionName)
            if hasVersion == True or versionName == None or desc.workspaceType == "LocalDatabase":
                arcpy.env.Workspace = targetWorkspace
                targets = gzSupport.listDatasets(targetWorkspace)
                tNames = targets[0]
                tFullNames = targets[1]
                for dataset in datasets:
                    name = dataset.getAttributeNode("name").nodeValue
                    arcpy.SetProgressorLabel("Loading Dataset " + name)
                    targetTable = gzSupport.getFullName(name, tNames, tFullNames)
                    sourceTable = gzSupport.getFullName(name, sNames, sFullNames)
                    attrs = [f.name for f in arcpy.ListFields(targetTable)]
                    expr = getExpression(attrs, fieldNames, value)
                    arcpy.SetProgressorLabel("Loading Dataset " + name + " Where " + expr)
                    tName = targetTable[targetTable.rfind("\\") + 1 :]
                    tLocation = targetTable[0 : targetTable.rfind("\\")]
                    if gzSupport.deleteRows(tLocation, tName, expr) == True:
                        retVal = gzSupport.appendRows(sourceTable, targetTable, expr)
                        if retVal == False:
                            success == False
                    else:
                        success == False
                    arcpy.SetProgressorPosition()
                if success == True:
                    if desc.workspaceType == "RemoteDatabase":
                        arcpy.SetProgressorLabel("Reconcile and Post")
                        retVal = gzSupport.reconcilePost(defaultWorkspace, versionName, defaultVersionName)
                        if retVal == False:
                            success = False
                            gzSupport.deleteVersion(defaultWorkspace, versionName)
                    elif desc.workspaceType == "LocalDatabase":
                        arcpy.SetProgressorLabel("Completed Update for " + str(value))
                    gzSupport.logDatasetProcess(targetTable, sys.argv[0], retVal)
                else:
                    gzSupport.logDatasetProcess(targetTable, sys.argv[0], retVal)
                gzSupport.cleanupGarbage()

        except:
            gzSupport.showTraceback()
            success = False
            gzSupport.logDatasetProcess("Serious error", sys.argv[0], False)
        finally:
            arcpy.SetProgressorPosition()
            arcpy.ClearWorkspaceCache_management(defaultWorkspace)
    if success == False:
        gzSupport.addError("Errors occurred during process, look in log files for more information")
    if gzSupport.ignoreErrors == True:
        success = True
    if desc.workspaceType == "RemoteDatabase" and success == True:
        analyze(defaultWorkspace, datasets, tNames, tFullNames)
    arcpy.SetParameter(SUCCESS, success)

    arcpy.ClearWorkspaceCache_management(defaultWorkspace)
    gzSupport.compressGDB(gzSupport.workspace)
    gzSupport.compressGDB(defaultWorkspace)
    gzSupport.closeLog()
    return
Beispiel #12
0
def main(argv=None):
    success = True
    gzSupport.compressGDB(gzSupport.workspace)
    tables = gzSupport.listDatasets(gzSupport.workspace)
    tNames = tables[0]
    tFullNames = tables[1]

    if len(datasets) > 0:
        progBar = len(datasets)
        arcpy.SetProgressor("step", "Running QA...", 0, progBar, 1)
    for dataset in datasets:
        arcpy.env.Workspace = gzSupport.workspace
        name = dataset.getAttributeNode("name").nodeValue
        gzSupport.sourceIDField = dataset.getAttributeNode(
            "sourceIDField").nodeValue
        table = gzSupport.getFullName(name, tNames, tFullNames)
        #table = os.path.join(gzSupport.workspace,name)
        fields = dataset.getElementsByTagName("Field")
        name = ''
        try:
            # run qa for dataset
            qaRulesDataset = dataset.getAttributeNode("qa").nodeValue
            gzSupport.addMessage("\nRunning QA (" + qaRulesDataset + ") for " +
                                 name)
            retVal = runDatasetChecks(dataset, table, qaRulesDataset)
            if retVal == False:
                success = False

            for field in fields:
                sourceQA = False
                targetQA = False
                fieldName = gzSupport.getNodeValue(field, "TargetName")
                if sourceFieldQA.lower(
                ) == "true" and qaRulesDataset.find("CheckFields") > -1:
                    sourceQA = True
                    fieldName = gzSupport.getNodeValue(field, "SourceName")
                if targetFieldQA.lower(
                ) == "true" and qaRulesDataset.find("CheckFields") > -1:
                    targetQA = True
                    fieldName = gzSupport.getNodeValue(field, "TargetName")
                retVal = runFieldCheck(dataset, table, field, sourceQA,
                                       targetQA)
                if retVal == False:
                    success = False
                try:
                    gzSupport.logDatasetProcess(name, fieldName, retVal)
                except:
                    gzSupport.addMessage("Process not logged for field")
            arcpy.SetProgressorPosition()
        except:
            gzSupport.showTraceback()
            gzSupport.addError("Field Check Error")
            success = False
            gzSupport.logDatasetProcess("sourceTargetQA", name, False)
        finally:
            arcpy.ResetProgressor()
            arcpy.RefreshCatalog(table)
            arcpy.ClearWorkspaceCache_management(gzSupport.workspace)
    if success == False:
        gzSupport.addError(
            "Errors occurred during process, look in log file tools\\log\\sourceTargetQA.log for more information"
        )
    if gzSupport.ignoreErrors == True:
        success = True
    arcpy.SetParameter(SUCCESS, success)
    gzSupport.closeLog()
    return
Beispiel #13
0
def main(argv=None):
    # main function - list the source and target datasets, then delete rows/append where there is a match on non-prefixed name
    dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
    logname = os.path.join(outputFolder, 'gzCreateProjectFiles.log')
    gzSupport.startLog()

    success = True
    try:

        gzSupport.addMessage("Getting list of datasets for Target " +
                             targetGDB)
        targets = gzSupport.listDatasets(targetGDB)
        tNames = targets[0]
        tFullNames = targets[1]

        gzSupport.addMessage("Getting list of datasets for Source " +
                             sourceGDB)
        sources = gzSupport.listDatasets(sourceGDB)
        sNames = sources[0]
        sFullNames = sources[1]

        t = 0
        arcpy.SetProgressor("Step", "Creating Files...", 0, len(tNames), 1)

        for name in tNames:
            arcpy.SetProgressorPosition(t)
            arcpy.SetProgressorLabel("Creating file for " + name + "...")
            # for each source name
            if debug:
                gzSupport.addMessage(name)
            try:
                # look for the matching name in target names
                s = sNames.index(name)
            except:
                # will get here if no match
                s = -1
            if s > -1:
                # create file if there is a match
                fileName = outputFolder + os.sep + prefixStr + name.title(
                ) + ".xml"
                if os.path.exists(fileName):
                    os.remove(fileName)
                try:
                    #arcpy.AddToolbox(os.path.join(dir,"Gizinta.tbx"))
                    #arcpy.gzCreateProject_gizinta(sFullNames[s],tFullNames[t],fileName) # this doesn't always work...
                    gzCreateProject.createGzFile(sFullNames[s], tFullNames[t],
                                                 fileName)
                    retVal = True
                    gzSupport.addMessage("Created " + fileName)
                except:
                    retVal = False
                if retVal == False:
                    gzSupport.addMessage("Failed to create file for " + name)
                    gzSupport.showTraceback()
                    success = False
            else:
                gzSupport.addMessage("Skipping " + name)
            t = t + 1
    except:
        gzSupport.showTraceback()
        arcpy.AddError("Error creating project files")
        success = False

    finally:
        arcpy.ResetProgressor()
        arcpy.SetParameter(gzSupport.successParameterNumber, success)
        arcpy.env.workspace = targetGDB
        arcpy.RefreshCatalog(outputFolder)
        gzSupport.closeLog()
Beispiel #14
0
def main(argv = None):
    global targetWorkspace
    hasVersion = False
    desc = arcpy.Describe(gzSupport.workspace)
    if desc.workspaceType != "RemoteDatabase" and versionName == None:
        targetWorkspace = defaultWorkspace
    success = True
    arcpy.ResetProgressor()
    arcpy.env.Workspace = gzSupport.workspace
    uniqueValues = gzSupport.getFieldValues("Unique",fieldNames,datasets)[0]
    sources = gzSupport.listDatasets(gzSupport.workspace)
    sNames = sources[0]
    sFullNames = sources[1]
    arcpy.SetProgressor("Step","Load by " + str(fieldNames) + "...",0,len(uniqueValues)*len(datasets),1)
    for value in uniqueValues:
        try:
            hasVersion = False
            gzSupport.addMessage(value)
            if desc.workspaceType == "RemoteDatabase" and versionName != None:
                arcpy.SetProgressorLabel("Creating Version " + versionName)
                hasVersion = gzSupport.createVersion(defaultWorkspace,defaultVersionName,versionName)
            if hasVersion == True  or versionName == None or desc.workspaceType == "LocalDatabase":
                arcpy.env.Workspace = targetWorkspace
                targets = gzSupport.listDatasets(targetWorkspace)
                tNames = targets[0]
                tFullNames = targets[1]
                for dataset in datasets:
                    name = dataset.getAttributeNode("name").nodeValue
                    arcpy.SetProgressorLabel("Loading Dataset " + name)
                    targetTable = gzSupport.getFullName(name,tNames,tFullNames)
                    sourceTable = gzSupport.getFullName(name,sNames,sFullNames)
                    attrs = [f.name for f in arcpy.ListFields(targetTable)]
                    expr = getExpression(attrs,fieldNames,value)
                    arcpy.SetProgressorLabel("Loading Dataset " + name + " Where " + expr)
                    tName = targetTable[targetTable.rfind("\\")+1:]
                    tLocation = targetTable[0:targetTable.rfind("\\")]
                    if gzSupport.deleteRows(tLocation,tName,expr) == True:
                        retVal = gzSupport.appendRows(sourceTable,targetTable,expr)
                        if retVal == False:
                            success == False
                    else:
                        success == False
                    arcpy.SetProgressorPosition()
                if success == True:
                    if desc.workspaceType == "RemoteDatabase":
                        arcpy.SetProgressorLabel("Reconcile and Post")
                        retVal = gzSupport.reconcilePost(defaultWorkspace,versionName,defaultVersionName)
                        if retVal == False:
                            success = False
                            gzSupport.deleteVersion(defaultWorkspace,versionName)
                    elif desc.workspaceType == "LocalDatabase":
                        arcpy.SetProgressorLabel("Completed Update for " + str(value))
                    gzSupport.logDatasetProcess(targetTable,sys.argv[0],retVal)
                else:
                    gzSupport.logDatasetProcess(targetTable,sys.argv[0],retVal)

        except:
            gzSupport.showTraceback()
            success = False
            gzSupport.logDatasetProcess("Serious error",sys.argv[0],False)
        finally:
            arcpy.SetProgressorPosition()
            arcpy.ClearWorkspaceCache_management(defaultWorkspace)
    if success == False:
        gzSupport.addError("Errors occurred during process, look in log files for more information")        
    if gzSupport.ignoreErrors == True:
        success = True
    if desc.workspaceType == "RemoteDatabase" and success == True:
        analyze(defaultWorkspace,datasets,tNames,tFullNames)
    arcpy.SetParameter(SUCCESS, success)

    arcpy.ClearWorkspaceCache_management(defaultWorkspace)
    gzSupport.compressGDB(gzSupport.workspace)
    gzSupport.compressGDB(defaultWorkspace)
    gzSupport.closeLog()
    return