I have imported the OverwriteFS module and wish to overwrite a feature service using the Feature layer View that alternates pointing to an A and a B version.
The tool's documentation does not provide an example code for this approach. It's difficult to fully understand without an example.
Is anybody able to share how they applied python commands for this overwriting approach ?
Here is a link to download the OverwriteFS module if needed.
https://www.arcgis.com/home/item.html?id=d45f80eb53c748e7aa3d938a46b48836
Solved! Go to Solution.
I worked it out and have uploaded my code here. I hope it helps somebody.
import sys
sys.path.insert(0, r'C:\myscripts\OverwriteFS')
import os
import OverwriteFS
# Import ArcGIS Python API and make a connection to Portal
from arcgis.gis import GIS
gis = GIS(username="johndoe", password="johnspwd")
# Get View item from Portal
itemId = "84a62b29fff5477f814ac7db77fb223c" # ID for feature layer view
parcelview = gis.content.get(itemId)
# set up the relationship of the view to A and B feature service items (I only had to run this once and the relationships held)
#relitems = ["6bbd1f51215f459796c8f026344e13a4","bf5680ef5e294d7t507810b3e448a735"] # related feature layers A & B versions. The view will point only to one of these alternating.
#OverwriteFS.updateRelationships( parcelview, relateIds=relitems, unRelate=False, verbose=True, outcome=None, dryRun=False)
# Determine which layer is Current and which layer is Target at the moment
outcome = OverwriteFS.getFeatureServiceTarget(parcelview, verbose=None, outcome=None, ignoreDataItemCheck=False)
# will check for error here and action it
# Set correct path-filename for source service definition
sdpath = r'C:\service_definitions' # In this folder, I have 2 service definition files, one named after the A version and one after the B
sd_fname = outcome["filename"] # name of target service definition.
print ('sdfname = ', sd_fname)
sourcefile = os.path.join(sdpath, sd_fname)
# Run the swapFeatureViewLayers function that updates target (idle) service and then Points the view to newly updated service.
# This also backs up the service's properties (eg. Summary, Tag etc) and restores it back to the service after overwrite
dry_run = False # Set it to true to run it in test mode where it just veries everything without making an overwrite or swapping
Service_Prop_Backup_Folder = r'C:\property_service_backup'
outcome = OverwriteFS.swapFeatureViewLayers(parcelview, updateFile=sourcefile, touchItems=True, verbose=True, touchTimeSeries=False, outcome=None, noIndexes=False, preserveProps=True, noWait=False, noProps=False, converter=None, outPath=Service_Prop_Backup_Folder, dryRun=dry_run, noSwap=False, ignoreAge=False)
# Check results
if outcome["success"]:
print( "Service Overwrite was a Success!")
elif outcome["success"] == False:
print( "Service Overwrite Failed!")
I worked it out and have uploaded my code here. I hope it helps somebody.
import sys
sys.path.insert(0, r'C:\myscripts\OverwriteFS')
import os
import OverwriteFS
# Import ArcGIS Python API and make a connection to Portal
from arcgis.gis import GIS
gis = GIS(username="johndoe", password="johnspwd")
# Get View item from Portal
itemId = "84a62b29fff5477f814ac7db77fb223c" # ID for feature layer view
parcelview = gis.content.get(itemId)
# set up the relationship of the view to A and B feature service items (I only had to run this once and the relationships held)
#relitems = ["6bbd1f51215f459796c8f026344e13a4","bf5680ef5e294d7t507810b3e448a735"] # related feature layers A & B versions. The view will point only to one of these alternating.
#OverwriteFS.updateRelationships( parcelview, relateIds=relitems, unRelate=False, verbose=True, outcome=None, dryRun=False)
# Determine which layer is Current and which layer is Target at the moment
outcome = OverwriteFS.getFeatureServiceTarget(parcelview, verbose=None, outcome=None, ignoreDataItemCheck=False)
# will check for error here and action it
# Set correct path-filename for source service definition
sdpath = r'C:\service_definitions' # In this folder, I have 2 service definition files, one named after the A version and one after the B
sd_fname = outcome["filename"] # name of target service definition.
print ('sdfname = ', sd_fname)
sourcefile = os.path.join(sdpath, sd_fname)
# Run the swapFeatureViewLayers function that updates target (idle) service and then Points the view to newly updated service.
# This also backs up the service's properties (eg. Summary, Tag etc) and restores it back to the service after overwrite
dry_run = False # Set it to true to run it in test mode where it just veries everything without making an overwrite or swapping
Service_Prop_Backup_Folder = r'C:\property_service_backup'
outcome = OverwriteFS.swapFeatureViewLayers(parcelview, updateFile=sourcefile, touchItems=True, verbose=True, touchTimeSeries=False, outcome=None, noIndexes=False, preserveProps=True, noWait=False, noProps=False, converter=None, outPath=Service_Prop_Backup_Folder, dryRun=dry_run, noSwap=False, ignoreAge=False)
# Check results
if outcome["success"]:
print( "Service Overwrite was a Success!")
elif outcome["success"] == False:
print( "Service Overwrite Failed!")