Created
March 14, 2018 10:46
-
-
Save yamaguchi1024/d95843a5e549fcc6ba0e6e23da5c132a to your computer and use it in GitHub Desktop.
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
import os | |
import sys | |
import subprocess | |
import re | |
args = sys.argv | |
directory = args[1] | |
if not directory.endswith("/"): | |
directory += "/" | |
files = os.listdir(directory) | |
for file in files: | |
e = "include-what-you-use " + directory + file | |
res = subprocess.Popen(e, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
stdout, stderror = res.communicate() | |
e_array = stderror.decode('utf-8').split("\n") | |
# Make list of lines which has to be removed | |
pattern = r"[0-9]+\.?[0-9]*" | |
rm_number = [] | |
for r_line in e_array: | |
if ("// lines") in r_line: | |
rm_number.append(int(re.search(pattern, r_line).group())) | |
print(rm_number) | |
# Open, readlines, close | |
f = open(directory + file, "r") | |
lines = f.readlines() | |
f.close() | |
# Reopen and rewrite | |
f = open(directory + file, "w") | |
for number, line in enumerate(lines): | |
if (number in rm_number) and (("#include <") in line): | |
continue | |
else: | |
f.write(line) | |
f.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment