def build_new_paths(map_dict, num_layers): """Given current source paths, builds new source paths to reflect modified directory structure :type map_dict: Dict :type num_layers: str :rtype: None """ # Instantiate new PathBuilder object that will consume getter.source_paths list builder = PathBuilder() # Grab stored dict of filepaths builder.get_mapped_sources() # For each map for mxd_path, lyr_sources_list in map_dict.items(): # Grab the map object to be modified mxd = lyr_sources_list[0][0] # Split the map filepath into list of directories and filename split_target = builder.split_path(mxd_path) # for each (map object, layer object, old layer source filepath) tuple for lyr in lyr_sources_list: # Grab the filename source_fname = builder.split_path(lyr[2])[-1] # Drop the .shp, .tif extenson source_fname_wo_ext = str(source_fname.split('.')[0]) # Get old workspace path try: old_workspace = lyr[1].workspacePath # Create dict for building new path except: print ("Layer doesn't have workspace path", lyr, type(lyr)) print ("Service layer?", lyr[1].isServiceLayer) print ("Group layer?", lyr[1].isGroupLayer) print("Supports DataSource?", lyr[1].supports("DATASOURCE")) print lyr[1].longName break path_dict = builder.get_path_variables(split_target[split_target.index('Y:'): ]) # Move shared data sources from Z: into special Data Library folder if old_workspace.startswith('Z') or old_workspace.startswith('Y:\_Data_Library'): source_path = builder.split_path(old_workspace)[2:] source_path = '\\'.join(source_path) new_workspace = 'Y:\_DataLibrary' + '\\' + source_path else: # All other sources go into their respective project folders new_workspace = builder.match_new_src(path_dict['Project'], source_fname) if not new_workspace: print "Couldn't make source match: " + source_fname else: builder.build(lyr[1], old_workspace, new_workspace) print 'Saving the mxd...' # If you get an error, make sure all other instances of mxd are closed print '-------------------------------------------------------' try: mxd.save() del mxd except (IOError, AttributeError), e: log_error(mxd.filePath) print "Unable to save mxd " + mxd.title
def processDiffs(self, proj, path): #self.got_some = {'java':True, 'cxx':True, 'hxx':True} self.got_some = {'java': False, 'cxx': True, 'hxx': False} self.pb = PathBuilder(self.tmpPath, force_clean=True) if os.path.isdir(path) is True: self.filterDiffProj(proj) elif os.path.isfile(path) is True: self.filterDiffFile(proj) else: return ('Invalid path : ' + path, False) # Second, change each diff into ccFinder input format converter = CCFXInputConverter() progress = (self.operations_so_far.incr() / float(self.num_operations)) * 100 callback = lambda: self.progress('Converting to ccfx input format') converter.convert(proj, self.pb, callback) self.num_operations = 3 * 2 self.operations_so_far = IntegerWrapper(0) return ("Converting diffs to ccFinder compatible format is done", True)