Created
February 1, 2017 19:22
-
-
Save onewhaleid/563e8fd3178004bb0b5ea8c24fc293a1 to your computer and use it in GitHub Desktop.
Python script for fixing deprecations in Atom packages.
This file contains 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 os | |
import sys | |
# Usage: | |
# > python atom_rename_deprecations path_to_package path_to_deprecations | |
def main(path_to_package, path_to_deprecations): | |
""" | |
Fixes deprecated function calls in atom package. | |
Args: | |
path_to_package: path to package directory | |
path_to_deprecations: path to deprecations (text file) | |
""" | |
with open(path_to_deprecations) as d: | |
dep_str = d.read() | |
dep_list = dep_str.split('\n') | |
dep_dict = {} | |
for line in dep_list: | |
d = line.split(' => ') | |
if len(d) > 1: | |
dep_dict[d[0]] = d[1] | |
for dname, dirs, files in os.walk(path_to_package): | |
# Skip hidden files | |
files = [f for f in files if not f[0] == '.'] | |
# Skip hidden folders, including .git | |
dirs[:] = [d for d in dirs if not d[0] == '.'] | |
for fname in files: | |
fpath = os.path.join(dname, fname) | |
try: | |
with open(fpath) as f: | |
s = f.read() | |
base_path_length = len(path_to_package) | |
print(fpath[base_path_length:]) | |
for old, new in dep_dict.items(): | |
if old in s: | |
print(' ' + old + ' => ' + new) | |
s = s.replace(old, new) | |
if '::shadow' in s: | |
print(':host') | |
with open(fpath, 'w') as f: | |
f.write(s) | |
except UnicodeDecodeError: | |
pass | |
# print("Skipping {}".format(fpath)) | |
if __name__ == '__main__': | |
path_to_package = sys.argv[1] | |
path_to_deprecations = sys.argv[2] | |
main(path_to_package, path_to_deprecations) |
This file contains 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 os | |
import sys | |
# Usage: | |
# > python atom_rename_deprecations path_to_package path_to_deprecations | |
def main(path_to_package, path_to_deprecations): | |
""" | |
Fixes deprecated function calls in atom package. | |
Args: | |
path_to_package: path to package directory | |
path_to_deprecations: path to deprecations (text file) | |
""" | |
with open(path_to_deprecations) as d: | |
dep_str = d.read() | |
dep_list = dep_str.split('\n') | |
dep_dict = {} | |
for line in dep_list: | |
d = line.split(' => ') | |
if len(d) > 1: | |
dep_dict[d[0]] = d[1] | |
for dname, dirs, files in os.walk(path_to_package): | |
# Skip hidden files | |
files = [f for f in files if not f[0] == '.'] | |
# Skip hidden folders, including .git | |
dirs[:] = [d for d in dirs if not d[0] == '.'] | |
for fname in files: | |
fpath = os.path.join(dname, fname) | |
try: | |
with open(fpath) as f: | |
s = f.read() | |
base_path_length = len(path_to_package) | |
print(fpath[base_path_length:]) | |
for old, new in dep_dict.items(): | |
if old in s: | |
print(' ' + old + ' => ' + new) | |
s = s.replace(old, new) | |
if '::shadow' in s: | |
print(':host') | |
with open(fpath, 'w') as f: | |
f.write(s) | |
except UnicodeDecodeError: | |
pass | |
# print("Skipping {}".format(fpath)) | |
if __name__ == '__main__': | |
path_to_package = sys.argv[1] | |
path_to_deprecations = sys.argv[2] | |
main(path_to_package, path_to_deprecations) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment