This script removes unused header comments.
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
#!/usr/bin/python | |
# This script removes unused header comments. Notice that the file locations are hard coded, | |
# so change that. | |
import subprocess as sp | |
import re | |
import os | |
def main(): | |
args = ['find', '../gporca', '-name', '*.cpp'] | |
findcmd = sp.Popen(args, stderr=sp.STDOUT, stdout=sp.PIPE) | |
fout = findcmd.communicate() | |
cpp_files = fout[0].split() | |
args = ['find', '../gporca', '-name', '*.h'] | |
findcmd = sp.Popen(args, stderr=sp.STDOUT, stdout=sp.PIPE) | |
fout = findcmd.communicate() | |
h_files = fout[0].split() | |
all_files = h_files + cpp_files | |
pattern = re.compile(ur'(?P<block>(\/\/\s+){2}@owner:(\s*\n\/\/)*\s+@test:(\s*\n\/\/){3})', re.MULTILINE) | |
f_contains = [] | |
for f in all_files: | |
if len(f_contains) % 100 == 0: | |
print "on file {}".format(len(f_contains)) | |
file_contents = "" | |
with open(f, 'r') as codefile: | |
file_contents = codefile.read() | |
matches = re.findall(pattern, file_contents) | |
if matches: | |
file_contents = re.sub(pattern, "//", file_contents) | |
f_contains.append(f) | |
if file_contents != "": | |
os.remove(f) | |
with open(f, 'w') as codefile: | |
codefile.write(file_contents) | |
print "replaced {}".format(len(f_contains)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment