Example #1
0
    def _reconcileStaging(self):
        func = 'WarehouseToSde.reconcile_staging'
        logging.info("Begin " + func)
        try:
            logging.debug(
                "Reconciling data from staging BG-BASE to staging DEFAULT")
            arcpy.ReconcileVersions_management(
                self._stagingWorkspace(), "ALL_VERSIONS", "dbo.DEFAULT",
                self._bgbaseEditVersion(), "NO_LOCK_ACQUIRED", "NO_ABORT",
                "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST", "KEEP_VERSION")
            logging.debug(
                "Finished reconciling data from staging GIS to staging DEFAULT"
            )

            logging.debug("Compressing data in Staging SDE")
            arcpy.Compress_management(self._stagingWorkspace())
            logging.debug("Finished compressing data in Staging SDE")
            return True
        except arcpy.ExecuteError:
            msgs = arcpy.GetMessages(2)
            arcpy.AddError(msgs)
            logging.error("ArcGIS error: %s", msgs)
        except:
            tb = sys.exc_info()[2]
            tbinfo = traceback.format_tb(tb)[0]
            msg = "Error in " + func + ":\n" + tbinfo + "\nError Info:\n" + str(
                sys.exc_info()[1])
            arcpy.AddError(msg)
            logging.error(msg)
        logging.info("End " + func)
        return False
Example #2
0
    def _reconcileStaging(self, replica):
        func = 'SqlServerImporter.reconcile_staging'
        logging.info("Begin " + func)
        try:
            logging.debug("Reconciling data in " + replica.stagingWorkspace +
                          ", from " + replica.sqlserverEditVersion + " to " +
                          replica.stagingDefaultVersion)
            arcpy.ReconcileVersions_management(
                replica.stagingWorkspace, "ALL_VERSIONS",
                replica.stagingDefaultVersion, replica.sqlserverEditVersion,
                "NO_LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT",
                "FAVOR_TARGET_VERSION", "POST", "KEEP_VERSION")
            logging.debug("Finished reconciling data.")

            logging.debug("Compressing data in Staging SDE")
            arcpy.Compress_management(replica.stagingWorkspace)
            logging.debug("Finished compressing data in Staging SDE")
            return True
        except arcpy.ExecuteError:
            msgs = arcpy.GetMessages(2)
            arcpy.AddError(msgs)
            logging.error("ArcGIS error: %s", msgs)
        except:
            tb = sys.exc_info()[2]
            tbinfo = traceback.format_tb(tb)[0]
            msg = "Error in " + func + ":\n" + tbinfo + "\nError Info:\n" + str(
                sys.exc_info()[1])
            arcpy.AddError(msg)
            logging.error(msg)
        logging.info("End " + func)
        return False
Example #3
0
    def _reconcileStaging(self):
        func = '_reconcileStaging'
        logging.info("Begin " + func)

        try:
            logging.debug('Getting edits versions')
            versions = self._stagingEditVersions().split(',')
            if len(versions) > 0:
                logging.debug('Found ' + str(len(versions)) +
                              ' edit versions to reconcile.')
                logging.debug("Reconciling data with Staging DEFAULT")
                arcpy.ReconcileVersions_management(
                    self._stagingWorkspace(), "ALL_VERSIONS", "dbo.DEFAULT",
                    ";".join(versions), "NO_LOCK_ACQUIRED", "NO_ABORT",
                    "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST",
                    "KEEP_VERSION")
                logging.debug("Finished reconciling data with Staging DEFAULT")

            logging.debug("Compressing data in Staging SDE")
            arcpy.Compress_management(self._stagingWorkspace())
            logging.debug("Finished compressing data in Staging SDE")
        except arcpy.ExecuteError:
            msgs = arcpy.GetMessages(2)
            arcpy.AddError(msgs)
            logging.error("ArcGIS error: %s", msgs)
        except:
            tb = sys.exc_info()[2]
            tbinfo = traceback.format_tb(tb)[0]
            msg = "Error in " + func + ":\n" + tbinfo + "\nError Info:\n" + str(
                sys.exc_info()[1])
            arcpy.AddError(msg)
            logging.error(msg)
        logging.info("End " + func)
        return
Example #4
0
def RecPost():
    #set workspace, copied this from Carls code and not sure why we need sdeadmin as workspace
    sde = "Database Connections/sdeadmin.sde"
    RPUDwkspace = "Database Connections/RPUD.sde"
    arcpy.env.workspace = sde

    # get time for naming log file
    ReconcileTime = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M")
    filePath = "" # somewhere to store the log file

    #reconcile, post, detect conflict by attribute(column)
    arcpy.ReconcileVersions_management(RPUDwkspace, "ALL_VERSIONS", "SDE.DEFAULT", "RPUD.MOBILE_EDIT_VERSION", "LOCK_ACQUIRED", "NO_ABORT", "BY_ATTRIBUTE", "FAVOR_TARGET_VERSION", "POST")
    print "Rec&Post MOBILE_VERSION is Completed"
Example #5
0
def stopEditReconcileVersion():
    edit.stopOperation()
    edit.stopEditing(True)
    for i in fcLSTglob:
        arcpy.ChangeVersion_management(
            i.split(".")[1], "TRANSACTIONAL", "SDE.DEFAULT")
    arcpy.ReconcileVersions_management(workspace, "", "SDE.DEFAULT",
                                       userglob + "." + version,
                                       "LOCK_ACQUIRED", "NO_ABORT",
                                       "BY_OBJECT", "FAVOR_EDIT_VERSION",
                                       "POST", "DELETE_VERSION")
    os.remove(workspace)
    print("versioned editing ended")
    arcpy.AddMessage("versioned editing ended")
def Cleanup():
    LogMessage( " Start the module Cleanup")
    ## Switch back to DEFAULT version.  This is so we can delete the version.
    LogMessage("Switching back to parent version...")
    arcpy.ChangeVersion_management("BoundaryLayer", "TRANSACTIONAL", "sde.DEFAULT", "")
    arcpy.ChangeVersion_management("FiberLayer", "TRANSACTIONAL", "sde.DEFAULT", "")
    arcpy.ChangeVersion_management("StructureLayer", "TRANSACTIONAL", "sde.DEFAULT", "")
    

    ## Reconcile and post version.
    LogMessage("Reconciling/Posting version " + versionName)
    ##logFileName = "C:/TEMP/Google/GoogleLog-" + todayhhmm + ".txt"
    arcpy.ReconcileVersions_management(inWorkspace, "ALL_VERSIONS", parentVersion, "PW." + versionName,  "LOCK_ACQUIRED", "ABORT_CONFLICTS", "BY_OBJECT", "FAVOR_EDIT_VERSION", "POST", "DELETE_VERSION")
    LogMessage( "Finished")
    return
    def reconcile(self):
        self.current_item += 1

        self.itemPrint()  # ↓
        try:
            arcpy.ReconcileVersions_management(
                self.sde_connection, "ALL_VERSIONS", "dbo.DEFAULT",
                self.versionList, "LOCK_ACQUIRED", "ABORT_CONFLICTS",
                "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST", "DELETE_VERSION",
                self.reconcile_log)
            self.itemPrint()  # ↑

            maintenance_log.appendToFile([
                self.maintenance_item[self.current_item],
                self.maintenance_status[1]
            ])

        except Exception as e:
            self.handleException(e)
Example #8
0
def post_to_portedit():
    global PORTEDIT_USERS
    versionList = [
        version.name for version in arcpy.da.ListVersions(WORKSPACE_SA)
        if version.parentVersionName == "PORTGIS.Edit"
    ]
    #PORTEDIT_USERS = versionList

    try:
        log.write(datetime.datetime.now().strftime("%H:%M:%S %m/%d/%Y ") +
                  "Starting post and reconcile to PortGIS.Edit.\n")

        ReconcileLog = "C:\\MaintenanceScripts\\Logs\\FullReconcileLog_PortEdit_{0}.txt"
        arcpy.ReconcileVersions_management(
            WORKSPACE_SA, "ALL_VERSIONS", "PORTGIS.Edit", versionList,
            "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_EDIT_VERSION",
            "POST", "KEEP_VERSION",
            ReconcileLog.format(str(time.strftime("%Y%m%d"))))

        log.write(datetime.datetime.now().strftime("%H:%M:%S %m/%d/%Y ") +
                  "Post and reconcile to PortGIS.Edit complete.\n")
    except Exception:
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]
        pymsg = datetime.datetime.now().strftime(
            "%H:%M:%S %m/%d/%Y "
        ) + "An error has occured.\nTraceback info:\n" + tbinfo + "Error Info:\n" + "  " + str(
            sys.exc_info()[1])
        if arcpy.GetMessages(2) != "":
            msgs = "\n\n-ARCPY ERRORS-\n" + arcpy.GetMessages(
                2) + "\n\nScript finished with errors."
        else:
            msgs = "\n\nScript finished with errors."
            log.write(pymsg)
            log.write(msgs)
            log.write(datetime.datetime.now().strftime("%H:%M:%S %m/%d/%Y ") +
                      "Script failed. Reaccepting connections...\n")

            clean_up()
Example #9
0
    def reconcileandpost(self):

        # https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/reconcile-versions.htm
        # in our little universe it is always like so
        # we care hardly at all about automated reconcile
        # mostly postin
        
        try:
            resobject = arcpy.ReconcileVersions_management(self.gdb.sdeconn
                                                          ,'ALL_VERSIONS'
                                                          ,self.parent
                                                          ,self.versionname
                                                          ,'LOCK_ACQUIRED'
                                                          ,'ABORT_CONFLICTS'
                                                          ,'BY_OBJECT'
                                                          ,'FAVOR_EDIT_VERSION'
                                                          ,'POST'
                                                          ,'KEEP_VERSION'
                                                          ,None) #"c:\RecLog.txt")

        except: # Exception, inst:
            raise ValueError("reconcileandpost of {0} totally bombed".format(self.versionname))
        
        output = resobject.getMessages()

        if resobject.status != 4 \
        or 'warning' in output.lower()  \
        or 'error' in output.lower(): 
            raise ValueError("reconcileandpost of {0} failed, see {1}".format(self.versionname
                                                                             ,output))

        #Start Time: Wednesday, December 30, 2020 2:35:36 PM
        #Starting reconcile.
        #Reconciling version BLDG.TEST_VERSION with SDE.DEFAULT.
        #Posting version BLDG.TEST_VERSION to SDE.DEFAULT.
        #1 of 1 versions finished.
        #Finished reconcile.
        #Succeeded at Wednesday, December 30, 2020 2:35:41 PM (Elapsed Time: 4.93 seconds)
        return output
Example #10
0
def service_reconcile_versions(schema, parent):
    """
    Obtiene todos los petitorios por el numero RUC del titular
    :param ruc: Numero de RUC del titular
    :return: lista de derechos mineros como una cadena
    """
    if schema == "": schema = 'DATA_EDIT'
    if parent == "": parent = 'collector'

    _PARENT = schema + "." + parent

    USERS = _get_users_from_edit(_PARENT)
    arcpy.ReconcileVersions_management(
        input_database=CONN,
        reconcile_mode="ALL_VERSIONS",
        target_version=_PARENT,
        edit_versions=USERS,
        acquire_locks="LOCK_ACQUIRED",
        abort_if_conflicts="ABORT_CONFLICTS",
        conflict_definition="BY_OBJECT",
        conflict_resolution="FAVOR_TARGET_VERSION",
        with_post="POST",
        with_delete="DELETE_VERSION",
        out_log="")
Example #11
0
    def append_to_esri_source(self, input_fc, esri_output_fc,
                              input_where_clause):
        """
        Append to the esri source FC, including projecting to output coord system, creating a versioned FC of the
        output in SDE, deleting from that versioned FC based on a where_clause, appending the new data, and then
        posting that version
        :param input_fc: the input source data
        :param esri_output_fc: the output in SDE
        :param input_where_clause: where clause used to add to/delete from the output esri FC
        :return:
        """

        logging.info(
            'Starting vector_layer.append_to_esri_source for {0}'.format(
                self.name))

        fc_to_append = self.project_to_output_srs(input_fc, esri_output_fc)

        logging.debug('Creating a versioned FL from esri_service_output')
        arcpy.MakeFeatureLayer_management(esri_output_fc,
                                          "esri_service_output_fl")

        version_name = self.name + "_" + str(int(time.time()))

        sde_workspace = os.path.dirname(esri_output_fc)
        desc = arcpy.Describe(sde_workspace)
        if hasattr(desc,
                   "datasetType") and desc.datasetType == 'FeatureDataset':
            sde_workspace = os.path.dirname(sde_workspace)

        del desc

        if os.path.splitext(sde_workspace)[1] != '.sde':
            logging.error('Could not find proper SDE workspace. Exiting.')
            sys.exit(1)

        arcpy.CreateVersion_management(sde_workspace, "sde.DEFAULT",
                                       version_name, "PRIVATE")
        arcpy.ChangeVersion_management("esri_service_output_fl",
                                       'TRANSACTIONAL', 'gfw.' + version_name,
                                       '')

        if input_where_clause:
            logging.debug(
                'Deleting features from esri_service_output feature layer based on input_where_clause. '
                'SQL statement: {0}'.format(input_where_clause))

            arcpy.SelectLayerByAttribute_management("esri_service_output_fl",
                                                    "NEW_SELECTION",
                                                    input_where_clause)

            # Delete the features selected by the input where_clause
            arcpy.DeleteRows_management("esri_service_output_fl")

        else:
            logging.debug(
                'No where clause for esri_service_output found; deleting all features before '
                'appending from source')

            # commented out at this already happens below with wc
            # arcpy.MakeFeatureLayer_management("esri_service_output_fl", "fl_to_delete")
            # arcpy.DeleteRows_management("fl_to_delete")
            # arcpy.Delete_management("fl_to_delete")

            sde_sql_conn = arcpy.ArcSDESQLExecute(sde_workspace)
            esri_fc_name = os.path.basename(esri_output_fc) + '_evw'

            # Find the min and max OID values
            to_delete_oid_field = [
                f.name for f in arcpy.ListFields(esri_output_fc)
                if f.type == 'OID'
            ][0]

            sql = 'SELECT min({0}), max({0}) from {1}'.format(
                to_delete_oid_field, esri_fc_name)
            to_delete_min_oid, to_delete_max_oid = sde_sql_conn.execute(sql)[0]

            # If there are features to delete, do it
            if to_delete_min_oid and to_delete_max_oid:

                for wc in util.generate_where_clause(to_delete_min_oid,
                                                     to_delete_max_oid,
                                                     to_delete_oid_field,
                                                     1000):

                    logging.debug('Deleting features with {0}'.format(wc))
                    arcpy.MakeFeatureLayer_management("esri_service_output_fl",
                                                      "fl_to_delete", wc)

                    arcpy.DeleteRows_management("fl_to_delete")
                    arcpy.Delete_management("fl_to_delete")

            else:
                pass

        esri_output_pre_append_count = int(
            arcpy.GetCount_management("esri_service_output_fl").getOutput(0))
        input_feature_count = int(
            arcpy.GetCount_management(fc_to_append).getOutput(0))

        logging.debug('Starting to append to esri_service_output')

        # Find the min and max OID values
        to_append_oid_field = [
            f.name for f in arcpy.ListFields(fc_to_append) if f.type == 'OID'
        ][0]
        to_append_min_oid, to_append_max_oid = cartodb.ogrinfo_min_max(
            fc_to_append, to_append_oid_field)

        for wc in util.generate_where_clause(to_append_min_oid,
                                             to_append_max_oid,
                                             to_append_oid_field, 1000):

            logging.debug('Appending features with {0}'.format(wc))
            arcpy.MakeFeatureLayer_management(fc_to_append, "fl_to_append", wc)

            arcpy.Append_management("fl_to_append", "esri_service_output_fl",
                                    "NO_TEST")
            arcpy.Delete_management("fl_to_append")

        logging.debug('Append finished, starting to reconcile versions')

        arcpy.ReconcileVersions_management(
            input_database=sde_workspace,
            reconcile_mode="ALL_VERSIONS",
            target_version="sde.DEFAULT",
            edit_versions='gfw.' + version_name,
            acquire_locks="LOCK_ACQUIRED",
            abort_if_conflicts="NO_ABORT",
            conflict_definition="BY_OBJECT",
            conflict_resolution="FAVOR_TARGET_VERSION",
            with_post="POST",
            with_delete="KEEP_VERSION",
            out_log="")

        logging.debug('Deleting temporary FL and temporary version')

        # For some reason need to run DeleteVersion_management here, will have errors if with_delete is used above
        arcpy.Delete_management("esri_service_output_fl")
        arcpy.DeleteVersion_management(sde_workspace, 'gfw.' + version_name)

        post_append_count = int(
            arcpy.GetCount_management(esri_output_fc).getOutput(0))

        if esri_output_pre_append_count + input_feature_count == post_append_count:
            logging.debug('Append successful based on sum of input features')
        else:
            logging.debug(
                'esri_output_pre_append_count: {0}\input_feature_count: {1}\npost_append_count{2}\n'
                'Append failed, sum of input features does not match. '
                'Exiting'.format(esri_output_pre_append_count,
                                 input_feature_count, post_append_count))
            sys.exit(1)

        return
#block new connections to the database.
arcpy.AcceptConnections('Database Connections/admin.sde', False)

# wait 15 minutes
time.sleep(900)

#disconnect all users from the database.
arcpy.DisconnectUser('Database Connections/admin.sde', "ALL")

# Get a list of versions to pass into the ReconcileVersions tool.
versionList = arcpy.ListVersions('Database Connections/admin.sde')

# Execute the ReconcileVersions tool.
arcpy.ReconcileVersions_management('Database Connections/admin.sde',
                                   "ALL_VERSIONS", "sde.DEFAULT", versionList,
                                   "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT",
                                   "FAVOR_TARGET_VERSION", "POST",
                                   "DELETE_VERSION",
                                   "c:/temp/reconcilelog.txt")

# Run the compress tool.
arcpy.Compress_management('Database Connections/admin.sde')

#Allow the database to begin accepting connections again
arcpy.AcceptConnections('Database Connections/admin.sde', True)

#Get a list of datasets owned by the admin user

# Get the user name for the workspace
# this assumes you are using database authentication.
# OS authentication connection files do not have a 'user' property.
userName = arcpy.Describe(arcpy.env.workspace).connectionProperties.user
Example #13
0
import time
from arcpy import env

env.overwriteOutput = True
versionPROD = "SDE.ProduccionGEO"
versionGEO = "SDE.GEOTEC"
versionDEF = "SDE.DEFAULT"

dia = (time.strftime("%Y_%m_%d"))
t1 = (time.strftime("%I:%M:%S"))
sde = r'Database Connections\SIRI_PRODUCCION.sde'

arcpy.AddMessage("  ")
arcpy.AddMessage("Conciliando... " + str(dia) + " " + str(t1))

try:

    arcpy.ReconcileVersions_management(sde, "ALL_VERSIONS", versionDEF,
                                       versionGEO, "LOCK_ACQUIRED", "NO_ABORT",
                                       "BY_OBJECT", "FAVOR_EDIT_VERSION",
                                       "POST", "KEEP_VERSION")
    t2 = (time.strftime("%I:%M:%S"))
    arcpy.AddMessage("  ")
    arcpy.AddMessage(u"Se concilió de la versión: " + versionGEO + " hacia " +
                     versionDEF + " " + str(dia) + " " + str(t2))
    arcpy.AddMessage("EJECUTADO")

except:
    print "Se ha detectado un error que impide ejecutar el script"
    print(arcpy.GetMessage(2))
    logging.debug('Disconnecting users')
    # Stop connections
    arcpy.AcceptConnections(SDE, False)
    # Disconnect users
    arcpy.DisconnectUser(SDE, "ALL")

    # Get version list
    version_list = arcpy.ListVersions(SDE)
    logging.info('Reconciling versions...')
    # Reconcile edits
    arcpy.ReconcileVersions_management(
        SDE,
        reconcile_mode="ALL_VERSIONS",
        target_version="dbo.DEFAULT",
        edit_versions=version_list,
        acquire_locks="LOCK_AQUIRED",
        abort_if_conflicts="NO_ABORT",
        conflict_definition="BY_OBJECT",
        conflict_resolution="FAVOR_TARGET_VERSION",
        with_post="POST",
        with_delete="KEEP_VERSION",
        out_log=os.path.join(file_loc, 'reconcile_log'))
    # Compress database and reopen to outside connections
    logging.info('Compressing database...')
    arcpy.Compress_management(SDE)
    arcpy.AcceptConnections(SDE, True)
    logging.debug('Open to connections')
except:
    print("There was an error!")
    logging.error(
        "An error has occured while reconciling and compressing versions",
        exc_info=True)
#SDE default version
defaultVersion = "SDE.DEFAULT"
editVersion = "arcdbcity.bloom"

#send the email or not
needsToSendEmail = False

# Get a list of versions to pass into the ReconcileVersions tool
main_log.write("Rec and Post Edit version to Default\n")
versionList = arcpy.ListVersions(config['arcgis']['sdeFile'])

# Process: Reconcile and Post MasterEdit to Default
arcpy.ReconcileVersions_management(config['arcgis']['sdeFile'], "ALL_VERSIONS",
                                   defaultVersion, editVersion,
                                   "LOCK_ACQUIRED", "ABORT_CONFLICTS",
                                   "BY_OBJECT", "FAVOR_EDIT_VERSION", "POST",
                                   "KEEP_VERSION")
main_log.write(arcpy.GetMessages() + "\n")

# Process: Compress
main_log.write("Compress DB\n")
arcpy.Compress_management(config['arcgis']['sdeFile'])
main_log.write(arcpy.GetMessages() + "\n")

# Process: Reconcile All Versions
main_log.write("Reconcile all the versions\n")
arcpy.ReconcileVersions_management(config['arcgis']['sdeFile'], "ALL_VERSIONS",
                                   defaultVersion, versionList,
                                   "LOCK_ACQUIRED", "ABORT_CONFLICTS",
                                   "BY_OBJECT", "FAVOR_TARGET_VERSION",
import datetime

db = r'X:\\GIS\\GIS\\ReferenceDocs\\SDEMaintenance\\Pro_ProjectFolder\\cc-gis-sql.sde'

versionList   = arcpy.ListVersions(db)
parentVersion = 'DBO.QC'
versionName   = 'DBO.BRyan'

today = datetime.datetime.now()
todayString = str(today.year) + "-" + str(today.month) + "-" + str(today.day) + "_" + str(today.hour) + str(today.minute) + str(int(today.second))

currentFolderPath = r'X:\GIS\GIS\ReferenceDocs\SDEMaintenance\Individual_Rec_and_Post_Logs' 
reconcileFileName = currentFolderPath + "//" + todayString + "_Rec_Post.txt"

arcpy.ReconcileVersions_management(db, "ALL_VERSIONS", parentVersion, versionName, "LOCK_ACQUIRED", 
                                   "ABORT_CONFLICTS", "BY_OBJECT", "FAVOR_EDIT_VERSION","POST", 
                                   "KEEP_VERSION", reconcileFileName)

#=========================================================================================================================================================
# QC to DEFAULT
import arcpy
import datetime

db = r'X:\\GIS\\GIS\\ReferenceDocs\\SDEMaintenance\\Pro_ProjectFolder\\cc-gis-sql.sde'

parentVersion = 'dbo.DEFAULT'
versionName = "DBO.QC"

today = datetime.datetime.now()
todayString = str(today.year) + "-" + str(today.month) + "-" + str(today.day) + "_" + str(today.hour) + str(today.minute) + str(int(today.second))
Example #17
0
    # if these names are found append them to the verReconcileList.
    for user in userList:
        for version in versions:
            if (version.name.lower().find(user.lower()) != -1):
                if version.parentVersionName.lower() == TItargetVersion.lower(
                ):
                    verReconcileList.append(version.name)

    # Perform maintenance if versions are found, otherwise there is no maintenance to perform.
    if len(verReconcileList) > 0:

        # Execute the ReconcileVersions tool.
        # Put log in a better place in the future
        arcpy.ReconcileVersions_management(TIworkspace, "ALL_VERSIONS",
                                           TItargetVersion, verReconcileList,
                                           "LOCK_ACQUIRED", "NO_ABORT",
                                           "BY_OBJECT", "FAVOR_EDIT_VERSION",
                                           "POST", "KEEP_VERSION",
                                           "c:/temp/reconcilelog.txt")

        # Run the compress tool.
        arcpy.Compress_management(TIworkspace)

        # Rebuild indexes and analyze the states and states_lineages system tables
        arcpy.RebuildIndexes_management(TIworkspace, "SYSTEM", "", "ALL")

        arcpy.AnalyzeDatasets_management(TIworkspace, "SYSTEM", "",
                                         "ANALYZE_BASE", "ANALYZE_DELTA",
                                         "ANALYZE_ARCHIVE")
        '''
        *********************
        Data Owner(s) Section
# method to close the file which saves the file and also prevents the file object from persisting in system memory
file.close()

print("...done writing list of versions to .txt file!\n ")

#################################################################################################################################

#                                                   RECONCILE & POST VERSIONS:

print("Reconciling, Posting, && Deleting versions....")

# method to Reconcile && Post && Delete all child versions up to DEFAULT
arcpy.ReconcileVersions_management(db, "ALL_VERSIONS", "dbo.DEFAULT",
                                   versionList, "LOCK_ACQUIRED",
                                   "ABORT_CONFLICTS", "BY_OBJECT",
                                   "FAVOR_TARGET_VERSION", "POST",
                                   "DELETE_VERSION", reconcileFileName)

# NOTE: this method will also DELETE all child versions

print("...ALL VERSIONS RECONCILED, POSTED & ALL CHILD VERSIONS DELETED!!\n ")

################################################################################################################################

#                                                         DB COMPRESS:

print("Compressing database....")

# Run the compress tool.
arcpy.Compress_management(db)
		logFile.write("Unable to delete version {0}.\n".format(version.name))
"""

#disconnect all users to improve compress
try:
	arcpy.DisconnectUser(dbConnection,"ALL")
	logFile.write('{0}\n\n'.format(arcpy.GetMessages()))
except:
	logFile.write("Failed to disconnect users.\n\n")
	messageText = arcpy.GetMessages()
	logFile.write('%s\n\n'%messageText)
	

try:
	#reconcile blocking versions (it seems to help to specify a specific version)
	arcpy.ReconcileVersions_management(dbConnection,"BLOCKING_VERSIONS","dbo.DEFAULT",
	"\"DOMAIN\\USERNAME\".VERSION_NAME","LOCK_ACQUIRED","ABORT_CONFLICTS")
	logFile.write('{0}\n\n'.format(arcpy.GetMessages()))
except:
	logFile.write("Reconcile Failed.\n\n")
	messageText = arcpy.GetMessages()
	logFile.write('%s\n\n'%messageText)
try:
	arcpy.AnalyzeDatasets_management(workspace, "SYSTEM", dataList, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE")
	logFile.write('{0}\n\n'.format(arcpy.GetMessages()))
except:
	logFile.write("Pre compress statistics failed.\n\n")
	messageText = arcpy.GetMessages()
	logFile.write('%s\n\n'%messageText)

try:
	#compress sde database
Example #20
0
	def reconcile(self, version_name):
		"""Given the name of the child version, will reconcile and post to the parent, dbo.DEFAULT."""
	
		arcpy.ReconcileVersions_management(self.workspace, "ALL_VERSIONS", "dbo.DEFAULT", version_name, "LOCK_ACQUIRED", "ABORT_CONFLICTS", "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST", "DELETE_VERSION")
		
		arcpy.AddMessage("Successfully posted changes to parent.")
Example #21
0
        # Disconnect all users from the database.
        arcpy.DisconnectUser(SDEconnection, "ALL")

        # Get a list of versions to pass into the ReconcileVersions tool.
        versionList = arcpy.ListVersions(SDEconnection)

        # Execute the ReconcileVersions tool.
        write_log(
            "-----------------------------------------------------------", log)
        write_log("RECONCILE", log)
        write_log(
            "-----------------------------------------------------------", log)
        reconcileLog = r"C:\Scripts_2016\Dans_Scripts\Log\ReconcileLog" + Date + ".txt"
        arcpy.ReconcileVersions_management(SDEconnection, "ALL_VERSIONS",
                                           "sde.QA", versionList,
                                           "LOCK_ACQUIRED", "NO_ABORT",
                                           "BY_OBJECT", "FAVOR_TARGET_VERSION",
                                           "POST", "KEEP_VERSION", log)
    except:
        recMsg = 'Reconcile & post failed. Error message below.\n\r' + arcpy.GetMessages(
        )
        write_log(recMsg, log)
# ===================   ========  =======================================================================================  ==========
##COMPRESS##
# ===================   ========  =======================================================================================  ==========

    try:
        #identify the log file
        log = 'C:\Scripts_2016\Dans_Scripts\Log\CompressLog.txt'
        write_log(
            "-----------------------------------------------------------", log)
'''
Created on Mar 12, 2013

@author: kyleg
'''

import arcpy, os
from arcpy import env

# set workspace
workspace = r'Database Connections\SDEPROD_GIS.sde\GIS.KDOT_RAIL'

# set the workspace environment
env.workspace = workspace

# Use a list comprehension to get a list of version names where the owner
# is the current user and make sure sde.default is not selected.
verList = [
    ver.name for ver in arcpy.da.ListVersions()
    if ver.isOwner == True and ver.name.lower() != 'sde.default'
]

arcpy.ReconcileVersions_management(workspace, "ALL_VERSIONS", "SDE.Default",
                                   verList, "LOCK_AQUIRED", "NO_ABORT",
                                   "BY_OBJECT", "FAVOR_TARGET_VERSION",
                                   "NO_POST", "KEEP_VERSION", "c:\RecLog.txt")
print 'Reconciling Complete'
arcpy.DisconnectUser(adminConn, 'ALL')

# Get a list of versions to pass into the ReconcileVersions tool.
# Only reconcile versions that are children of Default
LogMessage("Compiling a list of versions to reconcile")
verList = arcpy.da.ListVersions(adminConn)
versionList = [
    ver.name for ver in verList if ver.parentVersionName == 'sde.DEFAULT'
]

# Execute the ReconcileVersions tool.
try:
    LogMessage("Reconciling versions")
    arcpy.ReconcileVersions_management(adminConn, "ALL_VERSIONS",
                                       "sde.DEFAULT", versionList,
                                       "LOCK_ACQUIRED", "NO_ABORT",
                                       "BY_OBJECT", "FAVOR_TARGET_VERSION",
                                       "POST", "KEEP_VERSION",
                                       sys.path[0] + "/reclog.txt")
    LogMessage('Reconcile and post executed successfully.')
    LogMessage('Reconcile Log is below.')  #warning this can be very long.
    LogMessage(open(sys.path[0] + "/reclog.txt", 'r').read())
except:
    LogMessage('Reconcile & post failed. Error message below.' +
               arcpy.GetMessages())

# Run the compress tool.
try:
    LogMessage("Running compress")
    arcpy.Compress_management(adminConn)
    #if the compress is successful add a message.
    LogMessage('Compress was successful.')
Example #24
0
					urow[9] != srow[9] or
					urow[5] != srow[5]
				):
					urow[10] = datetime.date.today()
				urow[5] = srow[5]
				urow[9] = srow[9]
				ucursor.updateRow(urow)
				counter += 1
			edit.stopOperation()
	
	print(\n"Editing loops complete for CIP layers.")
	print(f"Editing environment active: {edit.isEditing}")
	edit.stopEditing(True)
	print("Edits saved.")
	print(f"Editing environment active: {edit.isEditing}")
	arcpy.ReconcileVersions_management(EditSDE, "ALL_VERSIONS", "sde.DEFAULT", r'"MCKINNEY\JCARMONA".CARMONA', "LOCK_ACQUIRED", 
								"NO_ABORT", "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST", "KEEP_VERSION", None, "PROCEED")
	print("Version has reconciled and posted to Default.")
	write_to_log("Script ran successfully")

	#setting index to false in the CSV will make it exactly match an unaltered dataframe
	#this allows us to check the dataframe against the CSV at next runtime
	df_checkcurrent.to_csv(r"C:\Users\jcarmona\Desktop\__Production_Scripts\CIP_GoogleSheet.csv", index=False)
	print("CIP Google Sheet updates have been written to CSV for future checks.")
	write_to_log("CIP Google Sheet updates have been written to CSV for future checks.")

except Exception as e:
	print(f"\n{'-'*60}\n")
	print("Things did not go as planned...\n") 
	print(traceback.format_exc())
	write_to_log(traceback.format_exc())
	print("Error logged.")
Example #25
0
# Wait 15 minutes
#time.sleep(900)

# Disconnect all users from the database.
#arcpy.DisconnectUser('Database Connections/admin.sde', "ALL")

# Get a list of versions to pass into the ReconcileVersions tool.
versionList = arcpy.ListVersions(
    'C:\Users\daniel.scott\Desktop\SDE\SDE@SRV-SQLHA02@CL_DVC.sde')
print versionList
# Execute the ReconcileVersions tool.
print "Reconciling"
arcpy.ReconcileVersions_management(
    'C:\Users\daniel.scott\Desktop\SDE\SDE@SRV-SQLHA02@CL_DVC.sde',
    "ALL_VERSIONS", "sde.DEFAULT", versionList, "LOCK_ACQUIRED", "NO_ABORT",
    "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST", "KEEP_VERSION",
    "c:/temp/reconcilelog.txt")
# Run the compress tool.
print "compressing"
arcpy.Compress_management(
    'C:\Users\daniel.scott\Desktop\SDE\SDE@SRV-SQLHA02@CL_DVC.sde')
# Allow the database to begin accepting connections again
arcpy.AcceptConnections(
    'C:\Users\daniel.scott\Desktop\SDE\SDE@SRV-SQLHA02@CL_DVC.sde', True)

# Get a list of datasets owned by the admin user
print "rebuilding indexes"
# Rebuild indexes and analyze the states and states_lineages system tables
arcpy.RebuildIndexes_management(workspace, "SYSTEM", "ALL")
print "analysing datasets"
        edit.stopEditing(True)


        # Reconcile and post changes to sde.DEFAULT, delete temporary version
        in_db = sde_path
        mode = "ALL_VERSIONS"
        target_version = v_parent
        edit_version = version
        locks = "LOCK_ACQUIRED"
        abort = "NO_ABORT"
        conflicts = "BY_ATTRIBUTE"
        conflict_res = "FAVOR_EDIT_VERSION"
        post = "POST"
        delete = "DELETE_VERSION"
        arcpy.ReconcileVersions_management(in_db, mode, target_version,
                                            edit_version, locks, abort,
                                            conflicts, conflict_res, post,
                                            delete)

        # Delete temporary version SDE connection file
        if os.path.exists(connection):
            os.remove(connection)

    else:
        raise ValueError("New attachment table must be in a file GDB or a versioned SDE: " + dest_att_table)

    arcpy.AddMessage(arcpy.GetMessages())

except arcpy.ExecuteError:
    arcpy.AddError(arcpy.GetMessages(2))

except Exception as err:
Example #27
0
            shape = geometries[PARCELID]
            newCounterLots.append(str(lots[PARCELID]))
            newCustomer.insertRow(
                (PARCELID, Block, AddressNo, Address, Zip, City, State,
                 GDistID, GZone, Garb, Garb2, Rec, Rec2, Yard, Yard2,
                 Symbology, GNotes, ActStatus, LotStatus, GTaxStatus,
                 GTaxUnits, GTaxDate, Multiple_Units, DISABLED_SRVC,
                 AddressPre, AddressRoad, AddressSuf, GCollection, YW,
                 GDistName, shape))
logs.info('Inserting New Customers - Complete')

logs.info("Update Finished. Reconciling and Posting.")

arcpy.ReconcileVersions_management(engSDE, "ALL_VERSIONS", "dbo.DEFAULT",
                                   database_user, "LOCK_ACQUIRED", "NO_ABORT",
                                   "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST",
                                   "KEEP_VERSION",
                                   r"c:\Customer_Geo_Update.txt")

logs.info("Posting Complete. Sending Email.")

# These are for testing purposes.
if testing:
    newCounter = [
        '0-00-00000-00-0000', '0-00-00000-00-0000', '0-00-00000-00-0000',
        '0-00-00000-00-0000', '0-00-00000-00-0000'
    ]
    newCounterLots = ['11', '24', '124', '223', '14']
    existingCounter = [
        '1-11-11111-11-1111', '1-11-11111-11-1111', '1-11-11111-11-1111'
    ]
Example #28
0
arcpy.env.workspace = workspace

# No more users to connect to database
arcpy.AcceptConnections(workspace, False)

# Disconnect Users
arcpy.DisconnectUser(workspace, "ALL")

# Disconnect all users from the database.
arcpy.DisconnectUser('Database Connections/[email protected]_EGDB_20170105A.sde', "ALL")

# Get a list of versions to pass into the ReconcileVersions tool.
versionList = arcpy.ListVersions('Database Connections/[email protected]_EGDB_20170105A.sde')

# Execute the ReconcileVersions tool.
arcpy.ReconcileVersions_management('Database Connections/[email protected]_EGDB_20170105A.sde', "ALL_VERSIONS", "sde.DEFAULT", versionList, "LOCK_ACQUIRED", "ABORT_CONFLICTS", "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST", "KEEP_VERSION", r"C:/Users/daniel.scott/Desktop/log.txt")

# Compress database
arcpy.Compress_management(workspace)
print 'Compression Complete'

# Get a list of stand alone feature classes
dataList = arcpy.ListFeatureClasses()

# Add Feature classes in datasets
for dataset in arcpy.ListDatasets("", "Feature"):
    arcpy.env.workspace = os.path.join(workspace, dataset)
    dataList += arcpy.ListFeatureClasses()

# reset the workspace
arcpy.env.workspace = workspace
Example #29
0
    #Esri will create when the script is run.
    out_log = esriLog

    #-------------------------------------------------------------------------------
    #                               Run Tool

    print 'Starting to Reconcile: ' + target_version + ' to ' + edit_versions
    logging.info('Starting to Reconcile: ' + target_version + ' to ' +
                 edit_versions)
    print 'And then Post: ' + edit_versions + ' to ' + target_version
    logging.info('And then Post: ' + edit_versions + ' to ' + target_version)

    #Process
    arcpy.ReconcileVersions_management(input_database, reconcile_mode,
                                       target_version, edit_versions,
                                       acquire_locks, abort_if_conflicts,
                                       conflict_definition,
                                       conflict_resolution, with_post,
                                       with_delete, out_log)

except Exception as e:
    print '\nERROR!!!'
    logging.info('ERROR!!!')
    print str(e)
    logging.info(str(e))
    success = False

#-------------------------------------------------------------------------------
#******************************  END MAIN  *************************************
#-------------------------------------------------------------------------------
#              Print final message based on if successful or not
Example #30
0
        print "Disconnecting all users"
        arcpy.DisconnectUser(sde,
                             "ALL")  #disconnect all users from the database
    except:
        print ""
        raw_input(
            "Insufficient privileges to disconnect users.  Press ENTER to exit."
        )
        quit()
    print "Compiling a list of versions to reconcile"
    versionList = arcpy.ListVersions(
        sde)  #list of versions to pass into the ReconcileVersions tool
    print "Reconciling all versions"
    arcpy.ReconcileVersions_management(sde, "ALL_VERSIONS", "sde.DEFAULT",
                                       versionList, "LOCK_ACQUIRED",
                                       "NO_ABORT", "BY_OBJECT",
                                       "FAVOR_TARGET_VERSION", "POST",
                                       "DELETE_VERSION", "")

    print "Running compress"
    con = pyodbc.connect(
        "DRIVER={SQL Server};Server=GIS3;DATABASE=water_test;Trusted_Connection = Yes"
    )
    cur = con.cursor()
    row_count = len(
        cur.execute("select * from sde.sde_state_lineages").fetchall())
    #print cur.execute("select * from sde.sde_state_lineages").fetchall()
    print "SDE is at State " + str(row_count - 1)
    while row_count <> 1:  #compress the database until State 0 is achieved (i.e. one record exists in the lineage table)
        arcpy.Compress_management(sde)
        row_count = len(