
Hi all, I am working on a script to migrate content from one site to another. I have run into an issue with correctly publishing the workbooks that rely on published data sources. My script publishes the data sources first, then the workbooks. However I have not figured out how to update the data server settings. So the publish does not complete successfully unless I remove the connection check. Which obviously just allows it to publish the workbook with the data server pointing to the old site/server
Does anyone know how to use python/TSC to update the data server info for the data sources in the workbook?
OK, retracting my statement having had another look @Phillip Overpeck .
So the way I do this is with both TSC and the Document API.
I use TSC to download the content as well as find the new datasource of interest. These are the key functions I run after opening the workbook item with the document API and looping through the datasources:
def _get_obj(endpoint, name):
req = TSC.RequestOptions()
req.filter.add(
TSC.Filter(
TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, name
)
)
objs, _ = endpoint.get(req)
return objs
def _get_ds(server, datasource_name, project_name=None):
datasources = _get_obj(server.datasources, datasource_name)
if datasources and project_name:
datasources = [ds for ds in datasources if ds.project_name == project_name]
if len(datasources) == 0:
_logger.warning("No datasources found with name %s", datasource_name)
return None
return datasources
# Function that updates connection of published datasource
def update_connection(datasource, server, datasource_name, project_name):
new_datasource = _get_ds(server, datasource_name, project_name)
if new_datasource:
new_datasource = new_datasource[0]
datasource.caption = new_datasource.name
connection = datasource.connections[0]
_logger.info("Updated dbname from %s", connection.dbname)
connection.dbname = new_datasource.content_url
_logger.info("Updated to %s", new_datasource.content_url)
else:
_logger.error("Could not find matching datasource. Exiting. . .")
sys.exit(1)
So I update the Datasource caption and the content_url in the xml, and then I save the workbook and re-publish with TSC.
Hopefully this helps and apologies for incorrect initial comment!
Best,
Bryce