-
Notifications
You must be signed in to change notification settings - Fork 0
/
sddraft_modifiers.py
450 lines (418 loc) · 18.4 KB
/
sddraft_modifiers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
# A small python library to modify SDdraft files created during publishing.
""" SDdraft files contain the service configuration. Modifying this allows customizing
the service being published. This library is not complete and is just a sample to
showcase the possibility"""
import xml.dom.minidom as DOM
import os
import codecs
class HostedFeatureServiceProperties(object):
sddraft_path = ""
def __init__(self, sddraft_path):
self.sddraft_path = sddraft_path
if not os.path.exists(self.sddraft_path):
print("File not found. Check the path")
def change_to_feature_service(self):
"""Change service type from one to another. Valid values include
soe: FeatureServer"""
xml = self.sddraft_path
doc = DOM.parse(xml)
featureServiceExt = doc.getElementsByTagName('TypeName')[0]
if featureServiceExt.parentNode.tagName == 'SVCConfiguration':
if featureServiceExt.hasChildNodes():
featureServiceExt.firstChild.data = "FeatureServer"
configProps = doc.getElementsByTagName('ConfigurationProperties')[0]
propArray = configProps.firstChild
propSets = propArray.childNodes
for propSet in propSets:
keyValues = propSet.childNodes
for keyValue in keyValues:
if keyValue.tagName == 'Key':
if keyValue.firstChild.data == "isCached":
keyValue.nextSibling.firstChild.data = "false"
outXml = xml
f = open(outXml, 'w')
doc.writexml(f)
f.close()
def modify_web_capabilities(self, newCapabilities):
"""
Method to update service capabilities
:param newCapabilities: 'Create,Delete,Query,Update,Uploads,Editing'
:return:
"""
xml = self.sddraft_path
doc = DOM.parse(xml)
stagingSettings = doc.getElementsByTagName('Info')[0]
propArray = stagingSettings.firstChild
propSets = propArray.childNodes
for propSet in propSets:
keyValues = propSet.childNodes
for keyValue in keyValues:
if keyValue.tagName == 'Key':
if keyValue.firstChild.data == "WebCapabilities":
keyValue.nextSibling.firstChild.data = newCapabilities
outXml = xml
f = open(outXml, 'w')
doc.writexml(f)
f.close()
def modify_for_overwriting(self):
"""
Method to create a SD file to overwrite an existing service
:return:
"""
xml = self.sddraft_path
doc = DOM.parse(xml)
descriptions = doc.getElementsByTagName('Type')
for desc in descriptions:
if desc.parentNode.tagName == 'SVCManifest':
if desc.hasChildNodes():
desc.firstChild.data = 'esriServiceDefinitionType_Replacement'
outXml = xml
f = open(outXml, 'w')
doc.writexml(f)
f.close()
def modify_max_record_count(self, maxRecords):
xml = self.sddraft_path
doc = DOM.parse(xml)
stagingSettings = doc.getElementsByTagName('ConfigurationProperties')[0]
propArray = stagingSettings.firstChild
propSets = propArray.childNodes
for propSet in propSets:
keyValues = propSet.childNodes
for keyValue in keyValues:
if keyValue.tagName == 'Key':
if keyValue.firstChild.data == "maxRecordCount":
keyValue.nextSibling.firstChild.data = maxRecords
stagingSettings = doc.getElementsByTagName('Props')[1]
propArray = stagingSettings.firstChild
propSets = propArray.childNodes
for propSet in propSets:
keyValues = propSet.childNodes
for keyValue in keyValues:
if keyValue.tagName == 'Key':
if keyValue.firstChild.data == "maxRecordCount":
keyValue.nextSibling.firstChild.data = maxRecords
outXml = xml
f = open(outXml, 'w')
doc.writexml(f)
f.close()
def modify_allow_geometry_updates(self, allowGeometryUpdates):
"""
Turn on geometry updates during service editing.
:param allowGeometryUpdates: true, false
:return:
"""
xml = self.sddraft_path
doc = DOM.parse(xml)
stagingSettings = doc.getElementsByTagName('ConfigurationProperties')[0]
propArray = stagingSettings.firstChild
propSets = propArray.childNodes
for propSet in propSets:
keyValues = propSet.childNodes
for keyValue in keyValues:
if keyValue.tagName == 'Key':
if keyValue.firstChild.data == "allowGeometryUpdates":
keyValue.nextSibling.firstChild.data = allowGeometryUpdates
outXml = xml
f = open(outXml, 'w')
doc.writexml(f)
f.close()
class HostedTileServiceProperties(object):
sddraft_path = ""
def __init__(self, sddraft_path):
self.sddraft_path = sddraft_path
if not os.path.exists(self.sddraft_path):
print("File not found. Check the path")
def modify_initial_cache_LOD(self, level, levelID):
xml = self.sddraft_path
doc = DOM.parse(xml)
configProps = doc.getElementsByTagName('InitialCacheInfos')[0]
propArray = configProps.childNodes[level]
propSets = propArray.childNodes
for propSet in propSets:
if propSet.tagName == 'LevelID':
if propSet.hasChildNodes():
propSet.firstChild.data = levelID
outXml = xml
f = open(outXml, 'w')
doc.writexml(f)
f.close()
def modify_tile_image_type(self, imageType):
"""
Modify the tile image format in cache
:imageType: 'JPEG' , 'PNG8'
:return:
"""
xml = self.sddraft_path
doc = DOM.parse(xml)
descriptions = doc.getElementsByTagName('CacheTileFormat')
for desc in descriptions:
if desc.parentNode.tagName == 'TileImageInfo':
if desc.hasChildNodes():
desc.firstChild.data = imageType
outXml = xml
f = open(outXml, 'w')
doc.writexml(f)
f.close()
def modify_tile_image_compression(self, imageComp):
"""
Modify the compression factor of tiles in cache
:param imageComp: 100, 75 etc
:return:
"""
xml = self.sddraft_path
doc = DOM.parse(xml)
descriptions = doc.getElementsByTagName('CompressionQuality')
for desc in descriptions:
if desc.parentNode.tagName == 'TileImageInfo':
if desc.hasChildNodes():
desc.firstChild.data = imageComp
outXml = xml
f = open(outXml, 'w')
doc.writexml(f)
f.close()
def modify_DPI(self, dpi):
"""
Modify the DPI factor of tiles in cache
:param dpi: 96, 72 etc
:return:
"""
xml = self.sddraft_path
doc = DOM.parse(xml)
descriptions = doc.getElementsByTagName('DPI')
for desc in descriptions:
if desc.parentNode.tagName == 'TileCacheInfo':
if desc.hasChildNodes():
desc.firstChild.data = dpi
descriptions = doc.getElementsByTagName('PreciseDPI')
for desc in descriptions:
if desc.parentNode.tagName == 'TileCacheInfo':
if desc.hasChildNodes():
desc.firstChild.data = dpi
outXml = xml
f = open(outXml, 'w')
doc.writexml(f)
f.close()
def enable_caching(self):
"""
Enable caching when publishing a map service to arcgis server
:return:
"""
xml = self.sddraft_path
doc = DOM.parse(xml)
stagingSettings = doc.getElementsByTagName('ConfigurationProperties')[0]
propArray = stagingSettings.firstChild
propSets = propArray.childNodes
for propSet in propSets:
keyValues = propSet.childNodes
for keyValue in keyValues:
if keyValue.tagName == 'Key':
if keyValue.firstChild.data == "isCached":
keyValue.nextSibling.firstChild.data = "true"
outXml = xml
f = codecs.open(outXml, 'w', 'utf-8')
doc.writexml(f)
f.close()
def modify_for_overwriting(self):
"""
Method to create a SD file to overwrite an existing service
:return:
"""
xml = self.sddraft_path
doc = DOM.parse(xml)
descriptions = doc.getElementsByTagName('Type')
for desc in descriptions:
if desc.parentNode.tagName == 'SVCManifest':
if desc.hasChildNodes():
desc.firstChild.data = 'esriServiceDefinitionType_Replacement'
outXml = xml
f = open(outXml, 'w')
doc.writexml(f)
f.close()
class MapServiceProperties(object):
sddraft_path = ""
def __init__(self, sddraft_path):
self.sddraft_path = sddraft_path
if not os.path.exists(self.sddraft_path):
print("File not found. Check the path")
def modify_for_overwriting(self):
"""
Method to create a SD file to overwrite an existing service
:return:
"""
xml = self.sddraft_path
doc = DOM.parse(xml)
descriptions = doc.getElementsByTagName('Type')
for desc in descriptions:
if desc.parentNode.tagName == 'SVCManifest':
if desc.hasChildNodes():
desc.firstChild.data = 'esriServiceDefinitionType_Replacement'
outXml = xml
f = open(outXml, 'w')
doc.writexml(f)
f.close()
def enable_SOE(self, soe):
xml = self.sddraft_path
doc = DOM.parse(xml)
typeNames = doc.getElementsByTagName('TypeName')
for typeName in typeNames:
if typeName.firstChild.data == soe:
extention = typeName.parentNode
for extElement in extention.childNodes:
# enable soe
if extElement.tagName == 'Enabled':
extElement.firstChild.data = 'true'
outXml = xml
f = codecs.open(outXml, 'w', 'utf-8')
doc.writexml(f)
f.close()
def modify_SOE(self, soe, soeProperty, soePropertyValue):
xml = self.sddraft_path
doc = DOM.parse(xml)
typeNames = doc.getElementsByTagName('TypeName')
for typeName in typeNames:
# Get the TypeName whose properties we want to modify.
if typeName.firstChild.data == soe:
extention = typeName.parentNode
for extElement in extention.childNodes:
if extElement.tagName == 'Props':
for propArray in extElement.childNodes:
for propSet in propArray.childNodes:
for prop in propSet.childNodes:
if prop.tagName == "Key":
if prop.firstChild.data == soeProperty:
if prop.nextSibling.hasChildNodes():
prop.nextSibling.firstChild.data = soePropertyValue
else:
txt = doc.createTextNode(soePropertyValue)
prop.nextSibling.appendChild(txt)
outXml = xml
f = codecs.open(outXml, 'w', 'utf-8')
doc.writexml(f)
f.close()
def enable_caching(self):
xml = self.sddraft_path
doc = DOM.parse(xml)
stagingSettings = doc.getElementsByTagName('ConfigurationProperties')[0]
propArray = stagingSettings.firstChild
propSets = propArray.childNodes
for propSet in propSets:
keyValues = propSet.childNodes
for keyValue in keyValues:
if keyValue.tagName == 'Key':
if keyValue.firstChild.data == "isCached":
keyValue.nextSibling.firstChild.data = "true"
outXml = xml
f = codecs.open(outXml, 'w', 'utf-8')
doc.writexml(f)
f.close()
def modify_cache_properties(self, xOrigin, yOrigin, cols, rows, dpi, imageType, compression, storageFormat):
xml = self.sddraft_path
doc = DOM.parse(xml)
descriptions = doc.getElementsByTagName('X')
for desc in descriptions:
if desc.hasChildNodes():
desc.firstChild.data = xOrigin
descriptions = doc.getElementsByTagName('Y')
for desc in descriptions:
if desc.hasChildNodes():
desc.firstChild.data = yOrigin
descriptions = doc.getElementsByTagName('TileCols')
for desc in descriptions:
if desc.hasChildNodes():
desc.firstChild.data = cols
descriptions = doc.getElementsByTagName('TileRows')
for desc in descriptions:
if desc.hasChildNodes():
desc.firstChild.data = rows
descriptions = doc.getElementsByTagName('DPI')
for desc in descriptions:
if desc.hasChildNodes():
desc.firstChild.data = dpi
descriptions = doc.getElementsByTagName('CacheTileFormat')
for desc in descriptions:
if desc.hasChildNodes():
desc.firstChild.data = imageType
descriptions = doc.getElementsByTagName('CompressionQuality')
for desc in descriptions:
if desc.hasChildNodes():
desc.firstChild.data = compression
descriptions = doc.getElementsByTagName('StorageFormat')
for desc in descriptions:
if desc.hasChildNodes():
desc.firstChild.data = storageFormat
outXml = xml
f = codecs.open(outXml, 'w', 'utf-8')
doc.writexml(f)
f.close()
def modify_antialias(self, newTextAntialiasingMode, newAntiAliasingMode):
xml = self.sddraft_path
doc = DOM.parse(xml)
stagingSettings = doc.getElementsByTagName('ConfigurationProperties')[0]
propArray = stagingSettings.firstChild
propSets = propArray.childNodes
for propSet in propSets:
keyValues = propSet.childNodes
for keyValue in keyValues:
if keyValue.tagName == 'Key':
if keyValue.firstChild.data == "antialiasingMode":
keyValue.nextSibling.firstChild.data = newAntiAliasingMode
elif keyValue.firstChild.data == "textAntialiasingMode":
keyValue.nextSibling.firstChild.data = newTextAntialiasingMode
outXml = xml
f = codecs.open(outXml, 'w', 'utf-8')
doc.writexml(f)
f.close()
def modify_service_properties(self, maxRecords, minInstances, maxInstances, maxClientUse, maxClientWait, maxIdle, isolation,
instancesPerProcess, recycleInterval, recycleStart, configState, cleanTime):
xml = self.sddraft_path
doc = DOM.parse(xml)
stagingSettings = doc.getElementsByTagName('ConfigurationProperties')[0]
propArray = stagingSettings.firstChild
propSets = propArray.childNodes
for propSet in propSets:
keyValues = propSet.childNodes
for keyValue in keyValues:
if keyValue.tagName == 'Key':
if keyValue.firstChild.data == "maxRecordCount":
keyValue.nextSibling.firstChild.data = maxRecords
stagingSettings = doc.getElementsByTagName('Props')[0]
propArray = stagingSettings.firstChild
propSets = propArray.childNodes
for propSet in propSets:
keyValues = propSet.childNodes
for keyValue in keyValues:
if keyValue.tagName == 'Key':
if keyValue.firstChild.data == "MinInstances":
keyValue.nextSibling.firstChild.data = minInstances
elif keyValue.firstChild.data == "MaxInstances":
keyValue.nextSibling.firstChild.data = maxInstances
elif keyValue.firstChild.data == "UsageTimeout":
keyValue.nextSibling.firstChild.data = maxClientUse
elif keyValue.firstChild.data == "WaitTimeout":
keyValue.nextSibling.firstChild.data = maxClientWait
elif keyValue.firstChild.data == "IdleTimeout":
keyValue.nextSibling.firstChild.data = maxIdle
elif keyValue.firstChild.data == "Isolation":
keyValue.nextSibling.firstChild.data = isolation
elif keyValue.firstChild.data == "InstancesPerContainer":
keyValue.nextSibling.firstChild.data = instancesPerProcess
elif keyValue.firstChild.data == "configuredState":
keyValue.nextSibling.firstChild.data = configState
elif keyValue.firstChild.data == "CleanupTimeout":
keyValue.nextSibling.firstChild.data = cleanTime
elif keyValue.firstChild.data == "recycleInterval":
if keyValue.nextSibling.hasChildNodes():
keyValue.nextSibling.firstChild.data = recycleInterval
else:
txt = doc.createTextNode(recycleInterval)
keyValue.nextSibling.appendChild(txt)
elif keyValue.firstChild.data == "recycleStartTime":
if keyValue.nextSibling.hasChildNodes():
keyValue.nextSibling.firstChild.data = recycleStart
else:
txt = doc.createTextNode(recycleStart)
keyValue.nextSibling.appendChild(txt)
outXml = xml
f = codecs.open(outXml, 'w', 'utf-8')
doc.writexml(f)
f.close()