Last active
January 18, 2016 07:21
-
-
Save jossef/f2db8ca008e191c32fc7 to your computer and use it in GitHub Desktop.
removes intellij created by comments from sources
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
| #!/usr/bin/env python | |
| import os | |
| import re | |
| import multiprocessing | |
| import sys | |
| def patch_file(file_path, patch_callback): | |
| with open(file_path, "r+") as f: | |
| content = f.read() | |
| new_content = patch_callback(content) | |
| f.seek(0) | |
| f.write(new_content) | |
| f.truncate() | |
| def patch_java_file(file_path): | |
| patch_file(file_path, lambda x: re.sub('\/\*((?:.|[\r\n])*?)*(Created by (.*) on)(?:.|[\r\n])*?\*\/', '', x)) | |
| def patch_python_file(file_path): | |
| patch_file(file_path, lambda x: re.sub(r'__author__ = (.*)', '', x).lstrip()) | |
| def main(): | |
| for root, subFolders, files in os.walk('.'): | |
| for file_name in files: | |
| if file_name.lower().endswith('.java'): | |
| handler = patch_java_file | |
| elif file_name.lower().endswith('.py'): | |
| handler = patch_python_file | |
| else: | |
| continue | |
| file_path = os.path.join(root, file_name) | |
| p = multiprocessing.Process(target=handler, args=(file_path,)) | |
| p.start() | |
| p.join(1) # Should not take more than 1 second | |
| if p.is_alive(): | |
| print 'failed to patch', file_name, '(took to long)' | |
| if __name__ == '__main__': | |
| main() | |
| print 'finished patching files' | |
| sys.exit() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
🎱
I've refactored a large scale project and wanted to get rid of existing
Created by ...comments (many files)place this script in
and it will be available globally