Skip to content

Instantly share code, notes, and snippets.

@jossef
Last active January 18, 2016 07:21
Show Gist options
  • Select an option

  • Save jossef/f2db8ca008e191c32fc7 to your computer and use it in GitHub Desktop.

Select an option

Save jossef/f2db8ca008e191c32fc7 to your computer and use it in GitHub Desktop.
removes intellij created by comments from sources
#!/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()
@jossef

jossef commented Dec 9, 2015

Copy link
Copy Markdown
Author

🎱

I've refactored a large scale project and wanted to get rid of existing Created by ... comments (many files)
place this script in

/usr/local/bin/remove-ide-comments

and it will be available globally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment