Created
February 8, 2019 02:16
-
-
Save AndiMiko/58ecc04a64ac4f89eb5262176ab3fc9e to your computer and use it in GitHub Desktop.
Replaces the pairs in androidx-class-mapping.csv (get it here: https://developer.android.com/jetpack/androidx/migrate) to migrate Android support to AndroidX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ...") |
Amazing! Thank you!
there are some problem when then replace ocurr , ex :
com.support.car : com.androidx.car
com.support.carABC.com.androidx.carBCD
when i need migrate com.support.carABC, it will be change to com.androidx.carABC
becouse of , the order of csv and python in
pyhase
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good!