Skip to content

Instantly share code, notes, and snippets.

@onewhaleid
Created February 1, 2017 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onewhaleid/563e8fd3178004bb0b5ea8c24fc293a1 to your computer and use it in GitHub Desktop.
Save onewhaleid/563e8fd3178004bb0b5ea8c24fc293a1 to your computer and use it in GitHub Desktop.
Python script for fixing deprecations in Atom packages.
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)
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