Last active
March 19, 2018 20:19
-
-
Save theRobinator/7dd5d37b99e03a0be01faa6d8df09709 to your computer and use it in GitHub Desktop.
Refactor script bases
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
""" | |
This program takes a list of file names as arguments and applies a single Python function to them, in place. | |
An easy way to apply this to all files in a directory is: | |
find someDir -name '*.ts' | xargs python refactor.py | |
I recommend that you run this script in a clean git repository so that you can easily undo its changes using | |
the `git reset --hard` command. | |
""" | |
from sys import argv | |
def main(): | |
for filename in argv[1:]: | |
with open(filename, 'r') as fp: | |
contents = fp.read() | |
new_contents = do_refactor(contents) | |
if new_contents != contents: | |
with open(filename, 'w') as fp: | |
fp.write(new_contents) | |
def do_refactor(file_contents): | |
# Do your stuff here | |
pass | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment