Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Replaces the pairs in androidx-class-mapping.csv (get it here: https://developer.android.com/jetpack/androidx/migrate) to migrate Android support to AndroidX
import glob
import csv
dictCSV = "C:/path/to/androidx-class-mapping.csv"
projectPath = "C:/path/to/project/src/"
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 ...")
@oO0oO0oO0o0o00

This comment has been minimized.

Copy link

oO0oO0oO0o0o00 commented Mar 3, 2019

good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.