this repo has no description
1
fork

Configure Feed

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

Create tool to rename lines recursively

+40
+40
tools/rename-line
··· 1 + #!/usr/bin/env python3 2 + 3 + import argparse 4 + import os 5 + import re 6 + 7 + parser = argparse.ArgumentParser(description="Renames the starts of lines in every file") 8 + 9 + parser.add_argument("old", help="old start of line", type=str) 10 + parser.add_argument("new", help="new start of line", type=str) 11 + 12 + args = parser.parse_args() 13 + 14 + lineCount = 0 15 + fileCount = 0 16 + def editfile(f, old, new): 17 + global lineCount, fileCount 18 + contents = f.readlines() 19 + newContents = "" 20 + f.seek(0) 21 + edited = False 22 + for line in contents: 23 + if line.startswith(old): 24 + edited = True 25 + lineCount += 1 26 + line = new + line[len(old):] 27 + 28 + newContents += line 29 + if edited: 30 + fileCount += 1 31 + f.write(newContents) 32 + 33 + f.truncate() 34 + 35 + for dirpath, dirname, filenames in os.walk("."): 36 + for filename in filenames: 37 + if filename.endswith("CMakeLists.txt"): 38 + with open(dirpath +"/" + filename, "r+") as f: 39 + editfile(f, args.old, args.new) 40 + print("Edited " + str(lineCount) + " lines in " + str(fileCount) + " files.")