Created
May 3, 2014 11:41
-
-
Save nguyentruongtho/11496387 to your computer and use it in GitHub Desktop.
Purge all credit signatures which are automatically created by IntelliJ
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 | |
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