forked from wbhart/mpir
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_empty_props_files.py
More file actions
98 lines (82 loc) · 2.59 KB
/
Copy pathremove_empty_props_files.py
File metadata and controls
98 lines (82 loc) · 2.59 KB
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
# Utility for cleaning source tree from unused *.props files
# It scans directory tree and remove empty *.props files from project directories
# It doesn't remove empty *.props from props_templates directory
import sys
import os
g_EmptyPropsFileContent=[
r"""<?xml version="1.0" encoding="utf-8"?>""",
r"""<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">""",
r""" <ImportGroup Label="PropertySheets" />""",
r""" <PropertyGroup Label="UserMacros" />""",
r""" <PropertyGroup />""",
r""" <ItemDefinitionGroup />""",
r""" <ItemGroup />""",
r"""</Project>"""
]
def CompressString(s):
sRes=""
for ch in s:
i=ord(ch)
if ord(ch)<=0x20:
continue
if ord(ch)==0xFEFF:
continue
if ord(ch)==0xFFFE:
continue
sRes+=ch.lower()
return sRes
def CompressText(t):
sRes=""
for s in t:
sRes+=CompressString(s)
return sRes;
def RoughlyCompareStringAndTest(s, t):
return CompressString(s)==CompressText(t)
def IsProjectFile(sFile):
(_,sExt)=os.path.splitext(sFile)
if (sExt.lower()!=".vcxproj"):
return False
return True;
def IsPropsFile(sFile):
(_,sExt)=os.path.splitext(sFile)
if (sExt.lower()!=".props"):
return False
return True;
# Not a good implementation !!!
def IsEmptyPropsFile(sFile):
statinfo = os.stat(sFile)
if not statinfo:
return False
if statinfo.st_size<290:
return False
if statinfo.st_size>292:
return False
with open(sFile, encoding='utf-8', mode='r') as f:
sText=" "
sText=f.read(300)
if (RoughlyCompareStringAndTest(sText, g_EmptyPropsFileContent)):
return True
with open(sFile, encoding='utf-16', mode='r') as f:
sText=""
sText=f.read(300)
if (RoughlyCompareStringAndTest(sText, g_EmptyPropsFileContent)):
return True
return False;
sRootDir=os.path.dirname(os.getcwd())
FilesToDelete=[]
for root, dirs, files in os.walk(sRootDir):
if root.lower().find('templates')>=0:
continue
# print ("Directory: ", root)
bProjectDir=False;
for sFile in files:
sFullFile=os.path.join(root, sFile)
if IsProjectFile(sFullFile):
bProjectDir=True
if IsPropsFile(sFullFile):
# print ("Property file: ", sFullFile)
if IsEmptyPropsFile(sFullFile):
FilesToDelete.append(sFullFile)
with open("delete_empty_props_files.bat", mode='w') as f:
for sFile in FilesToDelete:
print ("del ", sFile, file=f)