def TestOSTools(): path1 = "C://basin_data//Chile//lat26p0//" path2 = "M:/Yo/ma/yoyo.ma" path3 = "/home/smudd/devel_projects/LSDTopoTools/branches/LSDModel" path4 = "C:\\basin_data\\Chile\\lat26p0\\heyJude_DEM.flt" newpath1 = LSDost.ReformatSeperators(path1) print "Old path: " + path1 print "New path: " + newpath1 newpath2 = LSDost.ReformatSeperators(path2) print "Old path: " + path2 print "New path: " + newpath2 newpath3 = LSDost.ReformatSeperators(path3) print "Old path: " + path3 print "New path: " + newpath3 newpath4 = LSDost.ReformatSeperators(path4) print "Old path: " + path4 print "New path: " + newpath4 # test the directory adder # test the directory adder print "\n\n" newpath = LSDost.AppendSepToDirectoryPath(path1) print "Sep appended path is: " + newpath print "\n\n" newpath = LSDost.AppendSepToDirectoryPath(path3) print "Sep appended path is: " + newpath # Test the file prefix grabber fprefix = LSDost.GetFilePrefix(path4) print "\n\n" print "File prefix is: " + fprefix # Test the remove path level print "\n\n" print "Removing a directory level from: " + newpath newnewpath = LSDost.RemoveDirectoryLevel(newpath) print "The new directory is: " + newnewpath # Test the last directory name function print "\n\n" print "The last directory name in: " + newnewpath name = LSDost.GetLastDirectoryLevel(newnewpath) print "is: " + name
def GetRequiredFilesFromFolder(DataDirectory): #print "Current directory is: " + os.getcwd() #Append a closing slash to the data directory if one is not already there NewDataDirectory = LSDost.ReformatSeperators(DataDirectory) DataDirectory = LSDost.AppendSepToDirectoryPath(NewDataDirectory) #print "DataDirectory is (2): " + DataDirectory # Start with a master list of required files required_files = [] # find all the makefiles in the directory for FileName in glob(DataDirectory+"*.make"): #print "FileName is: " + FileName # Now you need to find all the sources in the makefile f = open(FileName,'r') # open file lines = f.readlines() # read in the data f.close() # Initiate an empty list that will contain the filenames cppfiles = [] # add the makefile to the files to be copied required_files.append(FileName) # loop through the lines, flag a start where SOURCES line starts start_flag = 0 for line in lines: if "SOURCE" in line: start_flag = 1 # If there is OBJECTS in the line, stop looking for ".cpp" if "OBJECTS" in line: start_flag = 0 # Look for .cpp between SOURCES and OBJECTS if start_flag == 1: if ".cpp" in line: # seperate the line using spaces split_line = line.split(' ') this_item = "" # Go through the split line looking for .cpp for item in split_line: if ".cpp" in item: this_item = item # get rid of the SOURCES new_this_item = this_item.replace("SOURCES=","") #print "This cpp file is: " + new_this_item # get rid of stupid escape characters this_file = LSDost.RemoveEscapeCharacters(new_this_item) cppfiles.append(this_file) # now print to screen the files required for this makefile #print "The files required for this makefile are: " #print cppfiles # now append to directory...this requires some logic because of the ../ seperators for filename in cppfiles: #print "Filename is: " + filename # special logic for the ../ seperator if "../" in filename: #print "There is a lower level in this filename, this means it is an object" thisfile = filename.replace("../","") thisdirectory = LSDost.RemoveDirectoryLevel(DataDirectory) fullfile = thisdirectory+thisfile fullfile2 = fullfile.replace(".cpp",".hpp") required_files.append(fullfile2) else: fullfile = DataDirectory+filename # append to the required files list required_files.append(fullfile) # now thin out the required files to remove duplicates nd = set(required_files) required_files_noduplicates = list(nd) #print "/n/n=================================" #print "Required files are: " #print required_files #print "--------" #print "And removing duplicates:" #print required_files_noduplicates #print "=====================================" return required_files_noduplicates