Select to view content in your preferred language

suppress data source password dialog

3201
10
05-13-2016 04:35 PM
forestknutsen1
MVP Alum

I need to re-point all sde raster layers in mxds to a new sde instance (we are moving from sde 9.3.1 to 10.1). Many people have also have ODBC connections within their mxds for tabular data from non-spatial databases. The problem is when I run the script it is constantly prompting me for credentials. I could care less about them for this exercise as I do not need to update the ODBC connection. I would like to just suppress them. Can this be done?   

import arcpy
import os
import time


path_layer = r"***"
osa_sde_path = r"***"
sde_user = "***"
log = open("log.txt", "w")


for dir_path, dir_names, file_names in os.walk(path_layer):
    for file_name in file_names:
        if file_name[-3:] == "mxd":
            ts = os.path.getmtime(os.path.join(dir_path, file_name))
            mod_date = time.strftime('%m/%Y', time.gmtime(ts))
            mod_date_list = mod_date.split("/")
            if int(mod_date_list[1]) > 2012 and int(mod_date_list[0]) > 4:
                mxd = arcpy.mapping.MapDocument(os.path.join(dir_path, file_name))
                layers_list = arcpy.mapping.ListLayers(mxd)
                print "Updating:\t" + os.path.join(dir_path, file_name)


                for layer in layers_list:
                    if layer.supports("DATASOURCE"):
                        data_source = layer.dataSource
                        if data_source.find(sde_user) != -1 and layer.isRasterLayer:
                            print "\tUpdating:\t" + layer.name
                            dot_index = data_source.rfind(".")
                            dataset_name = data_source[dot_index + 1:]
                            print "\t\tNew Path:\t" + os.path.join(osa_sde_path, sde_user + "." + 
                                                                   dataset_name)
                            layer.replaceDataSource(osa_sde_path, "SDE_WORKSPACE", sde_user + "." + 
                                                    dataset_name, False)
                            if layer.isBroken:
                                log.write(os.path.join(dir_path, file_name))
                                print "Data Source Broken"
                mxd.save()
log.close()

Suggestions?

Tags (2)
0 Kudos
10 Replies
DanPatterson_Retired
MVP Emeritus

do you mean like ListRasters ListRasters—Help | ArcGIS for Desktop no mapping, pure arcpy, throw it a path and away you go