-
Notifications
You must be signed in to change notification settings - Fork 0
/
rename.py
executable file
·35 lines (31 loc) · 1.13 KB
/
rename.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#! /usr/bin/env python
import os
import sys
import shutil
import subprocess
from glob import glob
import argparse as ap
absexpanduser = lambda x: os.path.abspath(os.path.expanduser(x))
def main():
description = ("This script renames all instances of stub, Stub, and STUB "
"to the value given on the command line.")
parser = ap.ArgumentParser(description=description)
parser.add_argument('name', help="replacement for stub", default='name')
ns = parser.parse_args()
low, cap, upp = ns.name.lower(), ns.name.capitalize(), ns.name.upper()
stublow, stubcap, stubupp = 'stub', 'Stub', 'STUB'
files = ['CMakeLists.txt', 'input/example.xml'] + glob('src/*')
for f in files:
with open(f, 'r') as inp:
s = inp.read()
s = s.replace('stubs', low)
s = s.replace(stublow, low)
s = s.replace(stubcap, cap)
s = s.replace(stubupp, upp)
os.remove(f)
d = os.path.dirname(f)
name = os.path.basename(f)
with open(os.path.join(d, name.replace('stub', low)), 'w') as out:
out.write(s)
if __name__ == "__main__":
main()