forked from protolambda/blocktopograph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mig.py
31 lines (24 loc) · 825 Bytes
/
mig.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
import glob
import csv
dictCSV = ".\\androidx-class-mapping.csv"
projectPath = "."
def replace_all(text, dic):
for i, j in dic.items():
text = text.replace(i, j)
return text
with open(dictCSV, mode='r') as infile:
reader = csv.reader(infile)
replaceDict = {rows[0]:rows[1] for rows in reader}
files = []
for ext in ('/**/*.xml', '/**/*.kt', '/**/*.java'):
files.extend(glob.iglob(projectPath + ext, recursive=True))
for filename in files:
print("Replacing in file: " + filename)
try:
with open(filename, 'r') as file :
filedata = file.read()
filedata = replace_all(filedata, replaceDict)
with open(filename, 'w') as file:
file.write(filedata)
except Exception as e:
print("Error reading/writing file. Skipping ...")