예제 #1
0
def DisconnectHarshly_SDEPROD():
    admin_workspace = r"Database Connections\SDEPROD_SDE.sde"
    env.workspace = admin_workspace
    users = ListUsers(admin_workspace)  #
    print users
    DisconnectUser(admin_workspace, "All")
    AcceptConnections(admin_workspace, False)
예제 #2
0
def Unlock(admin_workspace):
    #unlock the database so we can really overwrite the tables, and prevent non-administrative users from connecting while operating
    env.workspace = admin_workspace
    #users = ListUsers(admin_workspace) #
    #print users
    AcceptConnections(admin_workspace, False)
    DisconnectUser(admin_workspace, "All")
예제 #3
0
def PostProcAnnum():
    Unlock(admin_workspace)

    AADT = "Database Connections/SQL61_GIS_CANSYS.sde/GIS_CANSYS.DBO.ACCS"
    Unlock(admin_workspace)
    Dissolve_management(
        "Database Connections/SQL61_GIS_CANSYS.sde/GIS_CANSYS.DBO.V_ACCS_SDO_V",
        AADT,
        "CRND_RTE;LRS_KEY;STATE_LRS;ROUTE_NO;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;ACS_CTRL_ID;ACS_CTRL_ID_DESC",
        "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES")
    ChangePrivileges_management(AADT, "readonly", "GRANT", "AS_IS")

    AcceptConnections(admin_workspace, True)
예제 #4
0
def main():
    def log():
        ToolLogging.critical_info()
        error_logging = logging.getLogger('ARGADD_errors.main.main')
        return error_logging

    log = log()

    try:
        # config_check = CheckConfig()
        # config_check.complete()
        # del config_check
        # Set params
        dashboard_db = config["dashboard_database"]
        usar_data = config["in_data"]

        # Prepare database for editing
        # AcceptConnections(dashboard_db, False)
        # KickUsers.kick(dashboard_db)

        # Do analysis
        # TODO turned off for debugging other modules
        # f_qual = CheckFieldQuality.FieldAnalysis(usar_data)
        # del f_qual
        #
        needs_check = CheckForNeeds.HQIIS(usar_data)
        needs_check.curse()
        del needs_check

    except Exit:
        log.exception(
            "Critical Error occurred. Tools did not complete. Check log!")
    except Exception as e:
        log.exception(e)
    else:
        if ToolLogging.complete_run():
            complete_logger = logging.getLogger('ARGADD_complete.main.main')
            complete_logger.info('All tasks finished successfully.')
    finally:
        # noinspection PyBroadException
        try:
            AcceptConnections(dashboard_db, True)
        except:
            log.info("SDE Connection may not accept connections.")
예제 #5
0
def ExportNUSYS(admin_workspace):
    print "exporting initialized at " + str(datetime.datetime.now())
    #set the output database, this could be changed to admin workspace
    destConnection = admin_workspace
    #copy the map extract table to the destination commented 5/8/2014
    #TableToTable_conversion("MAP_EXTRACT",destConnection,"Map_Extract","#","#","#")
    #start the loop for layers in the mxd
    for lyr in mapping.ListLayers(nusys_mxd):
        #continue the loop operations for layers in the NUSYS MXD (unlisted)
        try:
            #manipulate the layer name a little bit
            lyrname = lyr.name
            print lyrname + " exporting..."
            outlyrname = lyrname
            outlyrobj = destConnection + "\\GIS_CANSYS.SHARED." + outlyrname
            #this should prevent ERROR 000258: Layer already exists, even though OverwriteOutput is true
            if Exists(outlyrobj):
                Delete_management(outlyrobj)
            #export the layer to SQL server
            FeatureClassToFeatureClass_conversion(lyr, destConnection,
                                                  outlyrname, "#", "#", "#")
            #this is a total replacement, so grant the necessary administrative privileges
            ChangePrivileges_management(outlyrobj, "readonly", "GRANT",
                                        "AS_IS")
            #tell me what happened
            print lyrname + " exported to " + outlyrname + " " + str(
                datetime.datetime.now())
        except ExecuteError:
            msgs = GetMessages(2)
            AddError(msgs)
            #tell me what went wrong if there was an execute error
            print msgs
            AcceptConnections(admin_workspace, True)
            endingTime = datetime.datetime.now()
            ScriptStatusLogging('CANP_LRS_EXPORT.py', 'ExportNUSYS Function',
                                scriptFailure, startingTime, endingTime,
                                GetMessages(2))

            pass
        except (RuntimeError, TypeError, NameError):
            #tell me if there is a problem with one of the layers
            print "TypeError on item" + lyr.name
            AcceptConnections(admin_workspace, True)
            endingTime = datetime.datetime.now()
            ScriptStatusLogging('CANP_LRS_EXPORT.py', 'ExportNUSYS Function',
                                scriptFailure, startingTime, endingTime,
                                GetMessages(2))

            pass
        except:
            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])
            msgs = "ArcPy ERRORS:\n" + GetMessages(2) + "\n"
            print pymsg + "\n"
            print msgs
            AcceptConnections(admin_workspace, True)
            endingTime = datetime.datetime.now()
            ScriptStatusLogging('CANP_LRS_EXPORT.py', 'ExportNUSYS Function',
                                scriptFailure, startingTime, endingTime,
                                GetMessages(2))
예제 #6
0
    ExportCANPLyrs(owner_workspace, admin_workspace, CANPlist)

    #Export the NUSYS Rootes and layers
    #ExportNUSYS(admin_workspace)

    #update and process data that changes annually or less, or is time consuming to run
    #ExportCANPLyrs(owner_workspace, admin_workspace, CANPlistAADT)
    #PostProcAnnum(owner_workspace, admin_workspace)

    #Export the listed GISPROD layers
    ExportGISProdLyrs(owner_workspace, admin_workspace)

    #Update the Routes
    PostProcLRS()

    #Post process and dissolve the CANP layers for basic, efficient GIS use
    PostProcDissolve()

    #Don't run PostProcCalibPts every day, as needed
    #PostProcCalibPts()

    AcceptConnections(admin_workspace, True)
    print "done"

    endingTime = datetime.datetime.now()
    try:
        ScriptStatusLogging('CANP_LRS_EXPORT.py', 'CANSYS.SHARED.V_*',
                            scriptSuccess, startingTime, endingTime,
                            'Completed Successfully')
    except:
        print "script completed, but no logging was written"
예제 #7
0
@author: kyleg
'''

if __name__ == '__main__':
    pass

from arcpy import env, Compress_management, RebuildIndexes_management, CreateVersion_management, DisconnectUser, AcceptConnections, ListVersions, ReconcileVersions_management, AnalyzeDatasets_management
#import datetime

connection = r'D:\SCHED\SDEPROD_SDE.sde'
shared_schema = r'D:/SCHED/SDEPROD_SHARED.sde'

env.workspace = connection
env.overwriteOutput = True
try:
    AcceptConnections(connection, False)
    print "connections blocked"
    DisconnectUser(connection, "ALL")
    print "users disconnected"
    versionList = ListVersions(connection)
    print "versions identified:"
    for version in versionList:
        if version == "SDE.DEFAULT":
            print "no child versions from Default version"
        else:
            print version
            ReconcileVersions_management(connection, "ALL_VERSIONS",
                                         "sde.DEFAULT", versionList,
                                         "LOCK_ACQUIRED", "NO_ABORT",
                                         "BY_OBJECT", "FAVOR_TARGET_VERSION",
                                         "POST", "DELETE_VERSION",
예제 #8
0
def DissolveNonDirectionalItems(OpEnvironmentMode):

    OpRunIn = OpEnvironment.OpRunInSum  # @UndefinedVariable
    OpRunOut = OpEnvironment.OpRunOut  # @UndefinedVariable
    adm = OpEnvironment.adm  # @UndefinedVariable
    Owner = OpEnvironment.Owner  # @UndefinedVariable
    DB = OpEnvironment.DB  # @UndefinedVariable

    env.workspace = OpRunIn
    env.overwriteOutput = True
    print OpRunIn

    #combine the connection, db, and owner to the destination path for enterprise geodatabase output
    OpRunFullOut = OpRunOut + "/" + DB + "." + Owner + "."

    print OpRunFullOut
    FCList = ListFeatureClasses()

    print "dissolving items in the primary direction"
    FCGlobalFieldsDissolve = [
        "LRS_KEY", "COUNTY_CD", "COUNTY_NAME", "DISTRICT"
    ]
    FCGlobalFieldsSummarize = "BSMP MIN;ESMP MAX;BCMP MIN;ECMP MAX"
    FCFieldsIgnore = [
        "OBJECTID", "CRND_RTE", "LANE_DIRECTION", "DIV_UNDIV", "SHAPE",
        "SHAPE.STLength()", "BSMP", "ESMP", "BCMP", "ECMP", "OLD_FUN_CLASS",
        "FUN_DT"
    ]
    for Item in FCList:
        ItemOut = Item[2:]
        ItemDissolveFields = []
        print ItemOut
        fields = ListFields(Item)
        for field in fields:
            if field.name not in FCFieldsIgnore:
                #print " "+field.name
                ItemDissolveFields.append(field.name)
        dissolvelist = ItemDissolveFields + FCGlobalFieldsDissolve
        DissolveFields = ';'.join(dissolvelist)
        if Exists(OpRunFullOut + ItemOut):
            try:
                print "feature class " + str(
                    ItemOut) + " exists and will be updated"
                Dissolve_management(Item, "in_memory/" + ItemOut,
                                    DissolveFields, FCGlobalFieldsSummarize,
                                    "MULTI_PART", "DISSOLVE_LINES")
                TruncateTable_management(OpRunFullOut + ItemOut)
                Append_management("in_memory/" + ItemOut,
                                  OpRunFullOut + ItemOut, "NO_TEST", "#")
                Delete_management("in_memory/" + ItemOut)
                print "feature class " + str(
                    ItemOut) + " was successfully updated"
            except ExecuteError:
                print "update failed because the schema has changed from what existed"
                #need to add locking
                DisconnectUser(adm, "readonly")
                AcceptConnections(adm, True)
                Delete_management(OpRunFullOut + ItemOut)
                print "recreating the dissolved feature class for " + str(
                    ItemOut)
                Dissolve_management(Item, OpRunFullOut + ItemOut,
                                    DissolveFields, FCGlobalFieldsSummarize,
                                    "MULTI_PART", "DISSOLVE_LINES")
                ChangePrivileges_management(OpRunFullOut + ItemOut, "readonly",
                                            "GRANT", "AS_IS")
            except:
                print "another error happened on updating the feature class"
        else:
            print "feature class " + str(
                ItemOut) + " will be created or overwritten"
            DisconnectUser(adm, "readonly")
            AcceptConnections(adm, True)
            Dissolve_management(Item, OpRunFullOut + ItemOut, DissolveFields,
                                FCGlobalFieldsSummarize, "MULTI_PART",
                                "DISSOLVE_LINES")
            ChangePrivileges_management(OpRunFullOut + ItemOut, "readonly",
                                        "GRANT", "AS_IS")
        try:
            Delete_management("in_memory/" + Item)
        except:
            pass
예제 #9
0
def PostProcDissolve():
    Unlock(admin_workspace)

    ACCS = "Database Connections/SQL61_GIS_CANSYS.sde/GIS_CANSYS.DBO.ACCS"
    Unlock(admin_workspace)
    Dissolve_management(
        "Database Connections/SQL61_GIS_CANSYS.sde/GIS_CANSYS.DBO.V_ACCS_SDO_V",
        ACCS,
        "CRND_RTE;LRS_KEY;STATE_LRS;ROUTE_NO;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;ACS_CTRL_ID;ACS_CTRL_ID_DESC",
        "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES")
    ChangePrivileges_management(ACCS, "readonly", "GRANT", "AS_IS")

    SMAP = "Database Connections/SQL61_GIS_CANSYS.sde/GIS_CANSYS.DBO.SMAP"
    Unlock(admin_workspace)
    Dissolve_management(
        "Database Connections/SQL61_GIS_CANSYS.sde/GIS_CANSYS.DBO.V_SMAP_SDO_V",
        SMAP,
        "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;STATIONING_TYPE;STATIONING_TYPE_DESC;BEGIN_STATIONING;BEGIN_STATIONING_DECIMAL;END_STATIONING;END_STATIONING_DECIMAL;PROJECT_YEAR;PROJECT_NUMBER;PROJECT_TYPE;PROJECT_TYPE_DESC;HOST_PROJECT_NUMBER;PW_URL",
        "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES")
    ChangePrivileges_management(SMAP, "readonly", "GRANT", "AS_IS")
    print "SMAP dissolved for viewing"

    LYRS = "Database Connections/SQL61_GIS_CANSYS.sde/GIS_CANSYS.DBO.LYRS"
    Dissolve_management(
        "Database Connections/SQL61_GIS_CANSYS.sde/GIS_CANSYS.DBO.V_LYRS_SDO_V",
        LYRS,
        "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;LAYER_TYPE;LAYER_TYPE_DESC;MATERIAL_TYPE;MATERIAL_TYPE_DESC;DEPTHS_MILLIMETERS;LAYER_DATE;MATERIAL_WIDTH_METERS;MATERIAL_WIDTH_FEET;SOURCE_TYPE;SOURCE_TYPE_DESC;PROJECT_ID;PW_URL",
        "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES")
    ChangePrivileges_management(LYRS, "readonly", "GRANT", "AS_IS")
    print "LYRS dissolved for viewing"

    LNCL = "Database Connections/SQL61_GIS_CANSYS.sde/GIS_CANSYS.DBO.LNCL"
    MakeFeatureLayer_management(
        "Database Connections/SQL61_GIS_CANSYS.sde/GIS_CANSYS.DBO.V_LNCL_SDO_V",
        "LNCL_PRIMARY", "CRND_RTE LIKE '%EB' OR CRND_RTE LIKE '%NB'", "#",
        "OBJECTID OBJECTID VISIBLE NONE;CRND_RTE CRND_RTE VISIBLE NONE;LRS_KEY LRS_KEY VISIBLE NONE;BCMP BCMP VISIBLE NONE;ECMP ECMP VISIBLE NONE;BSMP BSMP VISIBLE NONE;ESMP ESMP VISIBLE NONE;COUNTY_CD COUNTY_CD VISIBLE NONE;COUNTY_NAME COUNTY_NAME VISIBLE NONE;LANE_DIRECTION LANE_DIRECTION VISIBLE NONE;DISTRICT DISTRICT VISIBLE NONE;DIV_UNDIV DIV_UNDIV VISIBLE NONE;LNCL_CLS_ID LNCL_CLS_ID VISIBLE NONE;LNCL_CLS_ID_DESC LNCL_CLS_ID_DESC VISIBLE NONE;LNCL_DT LNCL_DT VISIBLE NONE;Shape Shape VISIBLE NONE;Shape.STLength() Shape.STLength() VISIBLE NONE"
    )
    Dissolve_management(
        "LNCL_PRIMARY", LNCL,
        "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;LNCL_CLS_ID;LNCL_CLS_ID_DESC",
        "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES")
    ChangePrivileges_management(LNCL, "readonly", "GRANT", "AS_IS")
    print "LYRS dissolved for viewing"

    CPMS = "Database Connections/SQL61_GIS_CANSYS.sde/GIS_CANSYS.DBO.CPMS"
    Dissolve_management(
        "Database Connections/SQL61_GIS_CANSYS.sde/GIS_CANSYS.DBO.V_CPMS_SDO_V",
        CPMS,
        "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;SCHEME_ID;PROJECT_ID;TECH_NAME;WORK_TYPE_DESC;DESIGN_CRITERIA;LEG_MAP_ID;CATEGORY_CODE;SUBCAT_CODE;PROJECT_DESC_FRND;PROJ_DISTRICT;PROJ_AREA;PROJ_SUB_AREA;PROJ_LENGTH;HOST_PROJ_NUM;FISCAL_YEAR_PRGM;LETTING_DATE;PW_URL",
        "BCMP MIN;BSMP MIN;ECMP MAX;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES")
    ChangePrivileges_management(CPMS, "readonly", "GRANT", "AS_IS")
    print "CPMS dissolved for viewing"

    POEQ = "Database Connections/SQL61_GIS_CANSYS.sde/GIS_CANSYS.DBO.POEQ"
    Dissolve_management(
        "Database Connections/SQL61_GIS_CANSYS.sde/GIS_CANSYS.DBO.V_POEQ_SDO_V",
        POEQ,
        "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;IRIR;RLIFE;RLIFE_DEFAULT;RLIFE_DEFAULT_DESC;EQFAULT;EQJD;EQTCR;RUTVAL;PVMTGRP;PVMTGRP_DESC;DEF_FLAG;DEF_FLAG_DESC;POEQ_DT;MEAN_IRIR;YEAR_LAST_IMP;YEAR_LAST_CONST;LAST_OVERLAY_THIC;IRIR_DATE;IRIR_DATE_DEFAULT;IRIR_DATE_DEFAULT_DESC",
        "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES")
    ChangePrivileges_management(POEQ, "readonly", "GRANT", "AS_IS")
    print "POEQ dissolved for viewing"

    HPPA = "Database Connections/SQL61_GIS_CANSYS.sde/GIS_CANSYS.DBO.HPPA"
    Dissolve_management(
        "GIS_CANSYS.DBO.V_HPPA_SDO_V", HPPA,
        "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;HPMS_SURFACE_TYPE;HPMS_SURFACE_TYPE_DESC;HPMS_YEAR_LAST_IMPROV;HPMS_YEAR_LAST_CONST;HPMS_LAST_OVERLAY_THICK;HPMS_THICKNESS_RIGID;HPMS_THICKNESS_FLEXIBLE;HPMS_BASE_TYPE;HPMS_BASE_TYPE_DESC;HPMS_BASE_THICKNESS",
        "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES")
    ChangePrivileges_management(HPPA, "readonly", "GRANT", "AS_IS")
    print "HPPA dissolved for viewing"

    SPED = "Database Connections/SQL61_GIS_CANSYS.sde/GIS_CANSYS.DBO.SPED"
    Dissolve_management(
        "GIS_CANSYS.DBO.V_SPED_SDO_V", SPED,
        "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;SPD_LMT;SPD_LMT_DESC;SPED_RESOL",
        "#", "MULTI_PART", "DISSOLVE_LINES")
    ChangePrivileges_management(SPED, "readonly", "GRANT", "AS_IS")
    print "SPED dissolved for viewing"

    FUN = "Database Connections/SQL61_GIS_CANSYS.sde/GIS_CANSYS.DBO.FUN"
    Dissolve_management(
        "GIS_CANSYS.DBO.V_FUN_SDO_V", FUN,
        "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;FUN_CLASS;FUN_CLASS_DESC;DONUT_SMPL;DONUT_SMPL_DESC;FUN_DT;OLD_FUN_CLASS",
        "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES")
    ChangePrivileges_management(FUN, "readonly", "GRANT", "AS_IS")
    print "FUN dissolved for viewing"

    AcceptConnections(admin_workspace, True)
예제 #10
0
def Unlock(admin_workspace):
    env.workspace = admin_workspace
    users = ListUsers(admin_workspace)  #
    print users
    AcceptConnections(admin_workspace, False)
    DisconnectUser(admin_workspace, "All")
예제 #11
0
def AllowConnections_SDEPROD():
    admin_workspace = r"Database Connections\SDEPROD_SDE.sde"
    env.workspace = admin_workspace
    AcceptConnections(admin_workspace, True)