this repo has no description
1#!/usr/bin/env python3
2
3import argparse
4import os
5import re
6
7parser = argparse.ArgumentParser(description="Rename a CMake target. Operates on the current directory.")
8
9parser.add_argument("old", help="the target to rename", type=str)
10parser.add_argument("new", help="the new target name", type=str)
11
12args = parser.parse_args()
13
14print(args.old)
15print(args.new)
16
17def editfile(f, old, new):
18 contents = f.read()
19
20 f.seek(0)
21
22 contents = re.sub("([^\w.])" + old + "([^\w.])", r"\1" + new + r"\2", contents)
23
24 f.write(contents)
25
26 f.truncate()
27
28for 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)