Hi,
Here is a simple script based on your to update all your layers featuresource from one to another (e.g. : all your layers feature source from dev environnement to production environnement) .
It only change the source, you have to use the same schema in your environnements.
It check if the layer featuresource match "oldF" then replace it with "newF"
<pre>
"""
replace_connexion_utils.py
Contains utility functions for batch updating featuresources of one or more Layer Definitions in a given folder
"""
def UpdateLayersFeatureSource(conn, folder, oldF, newF):
"""
Modifies the featuresource of layerdefinition matching the old featuresource name
"""
resList = conn.ResourceService.GetRepositoryResources(folder, "LayerDefinition")
for child in resList.Children:
ldf = conn.ResourceService.GetResource(child.ResourceId)
# get actual source
currentF = ldf.SubLayer.ResourceId
print "Replacing: %s,%s" % (child.ResourceId,currentF)
if (currentF == oldF):
ldf.SubLayer.ResourceId = newF
# Save the changes back
conn.ResourceService.SaveResource(ldf)
print "FeatureSource set to %s" % (currentF)
print "Saved: %s" % (child.ResourceId)
else :
print "Keeping source : %s" % (currentF)
</pre>
Usage :
<pre>
conn = app.GetConnection('http://yourserver/mapserver2012 (v2.3.0.4202)')
UpdateLayersFeatureSource(conn,'Library://map/Layers/','Library://map/data/cnx_DEV.FeatureSource','Library://map/cnx_PROD.FeatureSource')
</pre>
<br/><hr align="left" width="300" />
View this message in context: <a href="http://osgeo-org.1560.x6.nabble.com/Python-user-scripts-for-MapGuide-Maestro-5-0-tp5067941p5071324.html">Re: Python user scripts for MapGuide Maestro 5.0</a><br/>
Sent from the <a href="http://osgeo-org.1560.x6.nabble.com/MapGuide-Users-f4182607.html">MapGuide Users mailing list archive</a> at Nabble.com.<br/>