-
-
Save samueljarosinski/671464646313481570431709446889c9 to your computer and use it in GitHub Desktop.
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 csv | |
| import glob | |
| import os | |
| import shutil | |
| import sys | |
| import urllib.request | |
| if len(sys.argv) != 2: | |
| print('Usage: ' + sys.argv[0] + ' [path to project]') | |
| sys.exit() | |
| projectPath = sys.argv[1] | |
| mappingUrl = 'https://developer.android.com/topic/libraries/support-library/downloads/androidx-class-mapping.csv' | |
| mappingFile = 'androidx-class-mapping.csv' | |
| def replace_all(text, dict): | |
| for i, j in dict.items(): | |
| text = text.replace(i, j) | |
| return text | |
| for path in glob.iglob(projectPath + '/**/build', recursive=True): | |
| if os.path.isdir(path): | |
| print("Removing " + path) | |
| shutil.rmtree(path) | |
| if not os.path.isfile(mappingFile): | |
| print('Downloading mapping file...') | |
| urllib.request.urlretrieve(mappingUrl, mappingFile) | |
| with open(mappingFile, mode='r') as mapping: | |
| reader = csv.reader(mapping) | |
| replaceDict = {row[0]: row[1] for row in reader} | |
| files = [] | |
| for ext in ('/**/*.xml', '/**/*.kt', '/**/*.java', '/**/*.groovy'): | |
| files.extend(glob.iglob(projectPath + ext, recursive=True)) | |
| for filename in files: | |
| print(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. Exception: " + str(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment