def main(workspace): env.workspace = workspace dsList = [] datasetlist = arcpy.ListDatasets("*", "Feature") for dataset in datasetlist: dsList.append(dataset) fcList = arcpy.ListFeatureClasses() for fc in fcList: dsList.append(fc) tableList = arcpy.ListTables() for table in tableList: dsList.append(table) #message(dsList) for ds in dsList: desc = arcpy.Describe(ds) if desc.isVersioned: try: message(("unregistering as versioned: " + "\"" + ds + "\""),0) arcpy.UnregisterAsVersioned_management(ds, "NO_KEEP_EDIT", "COMPRESS_DEFAULT") except: message(("problem with unregistering: " + "\"" + ds + "\"" + '\n' + arcpy.GetMessages(2)),2) else: message(("--- already unregistered as versioned: " + "\"" + ds + "\""),0)
def VersionManagement(DbItem): ''' Takes a database table and unregisters it as versioned and then re-registers it as versioned without the option to move edits to base. This compresses edits to base. Note: workspace must be specified prior to running this function. ''' arcpy.UnregisterAsVersioned_management(DbItem, "NO_KEEP_EDIT", "COMPRESS_DEFAULT") arcpy.RegisterAsVersioned_management(DbItem, "NO_EDITS_TO_BASE") print "Edits from" + DbItem + " have been compressed to base"
def TruncateTable(Table): ''' Takes a single ESRI table stored in SQL server and removes all of its rows (truncating the table). Table schema and metadata are left intact. ''' DatasetVersioned = arcpy.Describe(Table).isVersioned if DatasetVersioned == True: arcpy.UnregisterAsVersioned_management(Table) arcpy.TruncateTable_management(Table) else: arcpy.TruncateTable_management(Table)
def TruncateProductionTables(Tables): ''' Remove all entries from the production tables but keep the schema intact. ''' env.workspace = r"Database Connections/IAMUW-FS_CEO.sde" for Table in Tables: # Tables must be unregistered as versioned before they can be truncated arcpy.UnregisterAsVersioned_management(Table, "NO_KEEP_EDIT", "COMPRESS_DEFAULT") arcpy.TruncateTable_management(Table) # Re-register as versioned after successfully truncating table arcpy.RegisterAsVersioned_management(Table, "NO_EDITS_TO_BASE")
# verify that the keyValue is in the Dictionary if keyValue in valueDict: # transfer the value stored under the keyValue from the dictionary to the updated field. updateRow[1] = valueDict[keyValue][0] updateRows.updateRow(updateRow) del valueDict print("Finished data transfer: " + strftime("%Y-%m-%d %H:%M:%S")) # start an edit session to apply changes to Parcel Master edit = arcpy.da.Editor(sdeCollectSDE) print("edit created") try: # unregister feature dataset as versioned using SDE credentials arcpy.UnregisterAsVersioned_management(featureDataset, "NO_KEEP_EDIT", "COMPRESS_DEFAULT") print("feature dataset unregistered") # start an edit session edit.startEditing() print("edit started") edit.startOperation() print("operation started") # Perform edits ## transfer bmp land use values to parcel collect fieldJoinCalc(parcelCollect, ['APN', 'TRPA_LANDUSE_DESCRIPTION'], bmpLU, ['APN', 'LANDUSE'], "BMPStatus = 'BMP'") print( "The 'TRPA_LANDUSE_DESCRIPTION' field in the parcel collection data has been updated" ) # stop edits edit.stopOperation()
#NARZEDZIE DO ODREJESTROWANIA(UNREGISTER AS VERSIONED) TABEL W BAZIE SDE DLA GNIEWKOWO_KAN_V_5_0 POTRZEBNE DO UPDATU BAZY # -*- coding: utf-8 -*- import sys, arcpy reload(sys) sys.setdefaultencoding('utf-8') it = arcpy.env.workspace = r"Database Connections\s4.asc-polska.pl.gniewkowo_kan_v_5_0.GNIEWKOWO_KAN_V_5_0_OWNER.sde" ptd = arcpy.ListDatasets() ptl = arcpy.ListTables() for i in ptd and ptl: unre = arcpy.UnregisterAsVersioned_management(i)