8 parser = argparse.ArgumentParser(description=
'Find includes only used in one non-interface directory.')
9 parser.add_argument(
'packageName',
10 help=
'name of package to check interface usage')
11 parser.add_argument(
'--fix', dest=
'shouldFix', action=
'store_true',
12 help=
'move file and fix includes if only used in 1 directory')
13 parser.add_argument(
'--remove', dest=
'removeUnused', action=
'store_true',
14 help=
'remove interface files that are not included anywhere')
16 args = parser.parse_args()
18 packageName = args.packageName
19 shouldFix = args.shouldFix
20 removeUnused = args.removeUnused
22 interfaceDir = packageName+
"/interface"
23 from os.path
import isfile, join
24 onlyfiles = [
join(interfaceDir,f)
for f
in os.listdir(interfaceDir)
if isfile(
join(interfaceDir, f))]
28 result = os.popen(
'git grep \'#include [",<]{filename}[",>]\' | awk -F\':\' \'{{print $1}}\' | sort -u'.
format(filename=f))
30 filesUsing = [l[:-1]
for l
in result]
32 if 0 == len(filesUsing):
33 print(
" "+f+
" is unused")
35 os.system(
'git rm {filename}'.
format(filename=f))
36 print(
" "+f+
" was removed")
40 dirs = set( (
"/".
join(name.split(
"/")[0:3])
for name
in filesUsing) )
43 if onlyDir.split(
"/")[2] !=
"interface":
44 print(
" "+f+
" is only used in "+onlyDir)
46 newFileName = onlyDir+
"/"+f.split(
"/")[3]
47 mvCommand =
"git mv {oldName} {newName}".
format(oldName=f, newName=newFileName)
50 sedCommand =
"sed --in-place 's/{oldName}/{newName}/' {filesToChange}".
format(oldName=
"\/".
join(f.split(
"/")),newName=
"\/".
join(newFileName.split(
"/")), filesToChange=
" ".
join( (n
for n
in filesUsing)) )
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
static std::string join(char **cmd)