def main(options, args): hn = HeaderNormalizer() candidates = hn.find_files_containing_headers(args.searchdir) matches = [] # Copy the list because you are removing bad candidates and if # you modify the list while it is driving the loop you'll get # unexpected results due to python's internal indexer. for file in candidates[:]: matches = hn.find_header_in_file(args.header_filename, file) if( len(matches) > 1): print("Found %d matches in %s" % (len(matches),file)) elif( len(matches) == 1): print("Found %d match in %s" % (len(matches),file)) else: candidates.remove(file) for m in matches: print( "\tLine %d Start %d End %d\t\t Data %s" %(m.line, m.col, m.col+m.length, m.string)) print() if options.do_rename: for file in candidates: print( "Renaming to use %s in %s" %(args.header_filename, file)) hn.rename_headers_in_file(args.header_filename, file)
def test_finds_header_files(self): hn = HeaderNormalizer() candidate_files = hn.find_files_containing_headers("scenarios") rootdir = join("scenarios","fakeproject") self.assertTrue(join(rootdir, "rootInclude.h") in candidate_files) self.assertTrue(join(rootdir, "rootInclude.hpp") in candidate_files) self.assertTrue(join(rootdir, "test.c") in candidate_files) self.assertTrue(join(rootdir, "Fake.txt") not in candidate_files) rootdir = join(rootdir, "capsheads") self.assertTrue(join(rootdir, "rootInclude.H") in candidate_files) self.assertTrue(join(rootdir, "rootInclude.HPP") in candidate_files) self.assertTrue(join(rootdir, "test.CPP") in candidate_files) self.assertTrue(join(rootdir, "dummy.txt") not in candidate_files)