this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Implement rename-target

+16 -8
+16 -8
tools/rename-target
··· 2 2 3 3 import argparse 4 4 import os 5 + import re 5 6 6 - parser = argparse.ArgumentParser(description="Rename a CMake target.") 7 + parser = argparse.ArgumentParser(description="Rename a CMake target. Opperates on the current directory.") 7 8 8 9 parser.add_argument("old", help="the target to rename", type=str) 9 10 parser.add_argument("new", help="the new target name", type=str) ··· 13 14 print(args.old) 14 15 print(args.new) 15 16 16 - for root, subdirs, files in os.walk("."): 17 - with open(list_file_path, 'wb') as list_file: 18 - for filename in files: 19 - file_path = os.path.join(root, filename) 17 + def editfile(f, old, new): 18 + contents = f.read() 20 19 20 + f.seek(0) 21 21 22 - with open(file_path, 'rb') as f: 23 - print("Parsing " + file_path) 24 - f_content = f.read() 22 + contents = re.sub(old, new, contents) 23 + 24 + f.write(contents) 25 + 26 + f.truncate() 27 + 28 + for dirpath, dirname, filenames in os.walk("."): 29 + for filename in filenames: 30 + if filename.endswith("CMakeLists.txt"): 31 + with open(dirpath +"/" + filename, "r+") as f: 32 + editfile(f, args.old, args.new)