Cider Isn't Darwin Emulation, Really
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041#!/usr/bin/env python3import argparseimport osimport reparser = argparse.ArgumentParser(description="Renames the starts of lines in every file")parser.add_argument("old", help="old start of line", type=str)parser.add_argument("new", help="new start of line", type=str)args = parser.parse_args()lineCount = 0fileCount = 0def editfile(f, old, new): global lineCount, fileCount contents = f.readlines() newContents = "" f.seek(0) edited = False for line in contents: if line.startswith(old): edited = True lineCount += 1 line = new + line[len(old):] newContents += line if edited: fileCount += 1 f.write(newContents) f.truncate()for dirpath, dirname, filenames in os.walk("."): for filename in filenames: if filename.endswith("CMakeLists.txt"): with open(dirpath +"/" + filename, "r+") as f: editfile(f, args.old, args.new)print("Edited " + str(lineCount) + " lines in " + str(fileCount) + " files.")