I need to be able to find the data source of all referenced map services within Portal. I have written a script to do this, however it feels unnecessarily clunky, does anyone know whether there is a better, simpler way to achieve this? For image services, this path information is easily located within the service properties, I cannot seem to find this equivelant information for map services (just the .msd is there which isn't helpful).
In an ideal world I would update all the source data paths as we've had a DFS change, but editing the manifest.json seems wrought with danger. A less hacky way would be hugely helpful!
from pathlib import Path
import json
gis = GIS("URL")
servers = gis.admin.servers
for server in servers.list():
serviceManager = server.services
folders = serviceManager.folders
for folder in folders:
services = serviceManager.list(folder=folder)
for service in services:
properties_dict = service.properties["properties"]
if service.properties.portalProperties.portalItems[0].type == 'MapServer':
# create new path string to the manifest.json
filepath = properties_dict['filePath']
parts = Path(filepath).parts
new_path = str(Path(*parts[:parts.index('extracted')+1 / 'manifest.json')
with open(new_path, 'r') as f:
data = json.load(f)
path = []
for db in data['databases']:
path.append(db['onServerConnectionString'])