Exemplo n.º 1
0
def getCountNullBlank(table,field,extraExpr):

    whereClause = "\"" + field + "\" is Null " + extraExpr
    success = True
    desc = arcpy.Describe(os.path.join(gzSupport.workspace,table))
    viewName = gzSupport.makeView(desc.dataElementType,gzSupport.workspace,table,"temp_"+field,whereClause,[])
    count = int(arcpy.GetCount_management(viewName).getOutput(0))
    if count > 0:
        gzSupport.addError(str(count) + " Null field values found")
        success = False
    else:
        gzSupport.addMessage("No Null field values found")

    return success
Exemplo n.º 2
0
def getCountNullBlank(table, field, extraExpr):

    whereClause = "\"" + field + "\" is Null " + extraExpr
    success = True
    desc = arcpy.Describe(os.path.join(gzSupport.workspace, table))
    viewName = gzSupport.makeView(desc.dataElementType, gzSupport.workspace,
                                  table, "temp_" + field, whereClause, [])
    count = int(arcpy.GetCount_management(viewName).getOutput(0))
    if count > 0:
        gzSupport.addError(str(count) + " Null field values found")
        success = False
    else:
        gzSupport.addMessage("No Null field values found")

    return success
Exemplo n.º 3
0
def sync(inputDrawing,playlists,GISStagingDefault_sde,GISProdDefault_sde,logfile):
    
    # sync from the staging database to prod. The staging database should have rows for the current drawing
    # This process will replace rows in the production database for the floor/drawing, it uses change detection if it is set up in the Gizinta Xml files
    global log
    log = logfile
    plists = playlists.split(" ")
    arcpy.AddMessage(playlists)
    datasets = []
    for playlist in plists:
        #xmlFile = os.path.join(gse.configFolder,playlist + ".xml")
        datasets = datasets + gzSupport.getXmlElements(playlist,"Dataset")
    gzSupport.workspace = GISProdDefault_sde
    retVal = True
    if inputDrawing == '*':
        dwg = '*'
        drawingID = 'all'
    else:
        dwg = inputDrawing[inputDrawing.rfind(os.sep)+1:]
        drawingID = gseDrawing.getDrawingFromName(dwg)
    processed = []
    for dataset in datasets:
        name = dataset.getAttributeNode("name").nodeValue
        try:
            name = dataset.getAttributeNode("targetName").nodeValue # special case to handle multi sources to one target.
        except:
            pass
        if name not in processed:
            sourceDataset = os.path.join(GISStagingDefault_sde,name)
            targetDataset = os.path.join(GISProdDefault_sde,name)
            changeNode = dataset.getElementsByTagName("ChangeDetection")[0]
            if changeNode != None and changeNode != []:
                try:
                    processed.index(name)
                except:
                    processed.append(name)
                # if there is a change node then do change detection using views
                arcpy.env.workspace = GISStagingDefault_sde
                desc = arcpy.Describe(os.path.join(GISProdDefault_sde,name))

                idField = changeNode.getAttributeNode("idField").nodeValue
                try:
                    viewIdField = changeNode.getAttributeNode("viewIdField").nodeValue
                    if debug == True:
                        msg("Using Change detection id field " + viewIdField)
                except:
                    viewIdField = "floorid" # the default
                    if inputDrawing != '*':
                        if debug == True:
                            msg("Using default id field " + viewIdField)
                whereClause = buildViewWhereClause(viewIdField,inputDrawing)
                adds = getChanges(changeNode,"exceptProductionView",GISStagingDefault_sde,whereClause,idField)
                deletes = getChanges(changeNode,"exceptStagingView",GISStagingDefault_sde,whereClause,idField)

                if len(deletes) > 0:
                    deleteExpr = getDeltaWhereClause(desc,idField,deletes)
                    arcpy.env.workspace = GISProdDefault_sde
                    retcode = gzSupport.deleteRows(GISProdDefault_sde,name,deleteExpr)
                    if retcode == True:
                        msg(str(len(deletes)) + " Rows deleted in prod for " + name)
                    else:
                        msg("Failed to delete rows")
                        retVal = False
                #else:
                #    msg("No changed rows found to delete")

                if len(adds) > 0:
                    addExpr = getDeltaWhereClause(desc,idField,adds)
                    arcpy.env.workspace = GISProdDefault_sde
                    gzSupport.workspace = GISProdDefault_sde
                    retcode = gzSupport.appendRows(sourceDataset,targetDataset,addExpr)
                    if retcode == True:
                        msg(str(len(adds)) + " Rows appended in prod for " + name)
                    else:
                        msg("Failed to append rows for " + name)
                        retVal = False
                #else:
                #    msg("No changed rows found to add for " + name)
                del adds
                del deletes

            else:
                # if there is no change node then replace everything for a floor
                if inputDrawing == '*':
                    idField = ''
                else:
                    idField = "FLOORID"
                whereClause = buildViewWhereClause(idField,inputDrawing)
                desc = arcpy.Describe(sourceDataset)
                view = "tempCount"
                gzSupport.workspace = GISStagingDefault_sde
                arcpy.env.workspace = GISStagingDefault_sde
                gzSupport.makeView(desc.DataElementType,GISStagingDefault_sde,name,view,whereClause,[])
                res = arcpy.GetCount_management(view)
                count = int(res.getOutput(0))
                if(count > 0):
                    msg("Replacing rows for " + name + ", " + str(count) + " rows")
                    retcode = gzSupport.deleteRows(GISProdDefault_sde,name,whereClause)
                    retcode = gzSupport.appendRows(sourceDataset,targetDataset,whereClause)
                else:
                    msg("No rows in source database to update for " + name)
                del view
    #msg(processed)
    return retVal