Skip to content

Instantly share code, notes, and snippets.

@nguyentruongtho
Created May 3, 2014 11:41
Show Gist options
  • Save nguyentruongtho/11496387 to your computer and use it in GitHub Desktop.
Save nguyentruongtho/11496387 to your computer and use it in GitHub Desktop.
Purge all credit signatures which are automatically created by IntelliJ
#!/usr/bin/env python
import os
import re
LIST_SUBMODULE_COMMAND = "awk /path\ =\ / .gitmodules|awk '{print $3}'"
SIGNATURE_INSET = "Created "
SIGNATURE_BEGIN = "/**"
SIGNATURE_END = " */"
REs = [
r'''\s+\*\s*Created [^\n]*''', # multiple lines credit
r'''\*\*\s*Created ''' # one line credit
]
def submodules():
(stdin, stdout, stderr) = os.popen3(LIST_SUBMODULE_COMMAND)
return stdout.read().replace('\n', ',')
def authors():
command = '\grep -lrsI ' + SIGNATURE_INSET + ' --exclude-dir={' + submodules() + '}'
(stdin, stdout, stderr) = os.popen3(command)
return stdout.read().split()
def is_credit_text(credit_text):
for line in credit_text.split('\n'):
line = line.lstrip(' \t')
if line.startswith('/**') or line.startswith('*'):
continue
else:
return False
return True
for RE in REs:
for f in authors():
with open(f) as infile:
incontent = infile.read()
markers = [m.span() for m in re.finditer(RE, incontent)]
for marker in markers:
begin = incontent.rfind(SIGNATURE_BEGIN, 0, marker[1])
end = incontent.find(SIGNATURE_END, marker[1]) + len(SIGNATURE_END)
credit_text = incontent[begin:end]
if is_credit_text(credit_text):
outcontent = incontent.replace(credit_text, '')
if (incontent != outcontent):
with open(f, 'w') as outfile:
outfile.write(outcontent)
remain = authors()
print(str(len(remain)) + " holdouts...")
if len(remain) > 0:
print("Next victim: " + remain[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment