I've posted you script, as is (after the unzip), and it looks like your indentation is off onmany of the likes. 36, 37, and 55 have an extra space in front. And some of the if and elif: statements don't seem to be indented at all, so thinks wouldn't execute....which may be why the program doesn't end for some mxd's. If these are correct on you side, then it may be something happened in the zip file. Use Posting Code blocks in the new GeoNet to post the corrected copy of your code.
I've gone a completely different route for updating my broken links, since the .sde and .ags connections needed special handling. So I'll be interested if you code (once fixed) handles all those. My process reads from an excel/ (actually csv) file and can change paths, and feature class types, if needed. Seems to be working now, but running a test this weekend. Then I need to clean up the code a bit. You code is much shorted than mine, but not sure if I understand what it does complete (I'm not familiar with the OptionParser or glob for that matter).
import glob
import os
import sys
import arcpy
import arcpy.mapping as mapping
from optparse import OptionParser
# Previous invocations of this script were used to effect the following conversions
# from Program Files (x86)/ArcGIS/Desktop10.0/Business Analyst/US/Data/
# to Business Analyst/2011Data/
# from RLIS_201402 to RLIS
# from RLIS_201402 to RLIS_WebMercator
parser = OptionParser()
parser.add_option("-f", "--fix", action="store_true", dest="f",
default=False,help="fix the source name")
parser.add_option("-o", "--old-src", action="store", dest="o",
default="RLIS-201402",
help="the old source file name, or part of a name")
parser.add_option("-n", "--new-src", action="store", dest="n",
default="RLIS",
help="the new source file name, or part of a name")
(options, args) = parser.parse_args()
old_src = options.o
new_src = options.n
def fixLayer(lyr):
lyrModified = False
if lyr.isFeatureLayer:
print lyr.name
if old_src in lyr.dataSource:
print "\t\t" + lyr.dataSource
if options.f:
lyrModified = True
lyr.findAndReplaceWorkspacePath(old_src,new_src,False)
return lyrModified
def fixMap(mxd):
mxdModified = False
# loop thru all data frames in the map
dataFrames = mapping.ListDataFrames(mxd, '')
for frame in dataFrames:
print "\tframe " + frame.name
# get all layers in this data frame
layers = mapping.ListLayers(mxd, '', frame)
# loop thru all layers in the data frame
print layers
for lyr in layers:
lyrModified = fixLayer(lyr)
if lyrModified:
mxdModified = True
if mxdModified:
mxd.save()
def fixit(fullPath,fileName):
desc = arcpy.Describe(fullPath)
if desc.datatype == "MapDocument":
print fileName
mxd = mapping.MapDocument(fullPath)
fixMap(mxd)
del mxd
elif desc.datatype == "Layer":
print fileName
lyr = mapping.Layer(fullPath)
if fixLayer(lyr):
lyr.save()
del lyr
for arg in args:
if os.path.isdir(arg):
for fileName in os.listdir(arg):
fullPath = os.path.join(arg, fileName)
fixit(fullPath,fileName)
elif os.path.isfile(arg):
fixit(arg,arg)
else:
print arg + " is not a map, nor a layer, nor a directory"