-
Notifications
You must be signed in to change notification settings - Fork 1
/
find_unused_files.py
182 lines (146 loc) · 5.69 KB
/
find_unused_files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env python3
from pathlib import Path
import os
import argparse
from fnmatch import fnmatch
import re
import sys
# ex = re.compile(r"(\b(?<!std::)size_t)\b")
#
# github = "GITHUB_ACTIONS" in os.environ
def main():
# p = argparse.ArgumentParser()
# p.add_argument("input")
# p.add_argument(
# "--fix", action="store_true", help="Attempt to fix any license issues found."
# )
# p.add_argument("--exclude", "-e", action="append", default=[])
#
# args = p.parse_args()
# walk over all files
exit = 0
# Collect all suffix for investigation
suffix_dict = {}
for root, _, files in os.walk("."):
root = Path(root)
# Skip "Scripts"-folder
if str(root).find("Scripts") != -1:
continue
# Skip "thirdparty"-folder
if str(root).find("thirdparty") != -1:
continue
# Skip "CI"-folder
if str(root).find("CI") != -1:
continue
# Skip "git"-folders
if str(root).find("git") != -1:
continue
# Skip "cmake"-folders
if str(root).find("cmake") != -1:
continue
# Skip base-directory
if str(root) == ".":
continue
# Skip ".idea"-folders
# TODO remove after testing
if str(root).find(".idea") != -1:
continue
for filename in files:
if str(filename) == ".gitignore":
continue
# get the full path of the file
filepath = root / filename
suffix_dict[filepath.suffix] = ""
# Check header files and remove
if filepath.suffix in (".hpp", ".h", ".cuh"):
# continue
cmd = 'grep -IR "' + filename + '" Alignment Core Examples Fatras Plugins Tests > unused_files_tmp'
os.system(cmd)
output = os.popen('cat unused_files_tmp').read()
if output.count('\n') == 0:
print(f"Remove file\n{filename}\n{filepath}\n")
remove_cmd = 'rm ' + str(filepath)
os.system(remove_cmd)
# Check source files and remove
if filepath.suffix in (".cpp", ".c", ".C", ".cu", ".ipp"):
# continue
cmd = 'grep -IR "' + filename + '" Alignment Core Examples Fatras Plugins Tests > unused_files_tmp'
os.system(cmd)
output = os.popen('cat unused_files_tmp').read()
if output.count('\n') == 0:
print(f"Remove file\n{filename}\n{filepath}\n")
remove_cmd = 'rm ' + str(filepath)
os.system(remove_cmd)
# Check images and remove
# TODO make jpeg unnecessary
if filepath.suffix in (".png", ".jpg", ".svg", ".jpeg", ".gif"):
# continue
# Skip "acts_logo"
if str(filename).find("acts_logo") != -1:
continue
# Skip "white-paper-figures"
if str(root).find("white_papers/figures") != -1:
continue
cmd = 'grep -IR "' + filename + '" Alignment Core Examples Fatras Plugins Tests docs > unused_files_tmp'
os.system(cmd)
output = os.popen('cat unused_files_tmp').read()
if output.count('\n') == 0:
print(f"Remove file\n{filename}\n{filepath}\n")
remove_cmd = 'rm ' + str(filepath)
os.system(remove_cmd)
# Check and print other files
if filepath.suffix in (
'.yml',
'.txt',
'.ini',
'',
'.toml',
'.cff',
'.json',
'.in',
'.patch',
'.sh',
'.xsl',
'.lock',
'.imp',
'.yaml',
'.root',
'.ipynb',
'.csv',
'.j2',
'.css',
'.gdml',
'.hepmc3',
'.onnx',
'.idx',
'.pack',
'.sample',
'.xml',
'.iml',
):
# Skip "vertexing_event_mu20" because they don't appear in full-text
if str(filename).find("vertexing_event_mu20_") != -1:
continue
cmd = 'grep -IR "' + filename + '" Alignment Core Examples Fatras Plugins Tests docs > unused_files_tmp'
os.system(cmd)
output = os.popen('cat unused_files_tmp').read()
if output.count('\n') == 0:
print(f"Remove file\n{filename}\n{filepath}\n")
# remove_cmd = 'rm ' + str(filepath)
# os.system(remove_cmd)
# Not implemented tests
if filepath.suffix in (".py"):
continue
# Check documentation files (weak tests)
if filepath.suffix in (".md", ".rst"):
cmd = 'grep -IR "' + filepath.stem + '" Alignment Core Examples Fatras Plugins Tests docs > unused_files_tmp'
os.system(cmd)
output = os.popen('cat unused_files_tmp').read()
if output.count('\n') == 0:
print(f"Remove file\n{filename}\n{filepath}\n")
# remove_cmd = 'rm ' + str(filepath)
# os.system(remove_cmd)
print(suffix_dict)
return exit
if "__main__" == __name__:
sys.exit(main())