-
Notifications
You must be signed in to change notification settings - Fork 0
/
vs-verify-paths.py
49 lines (39 loc) · 1.42 KB
/
vs-verify-paths.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
import errno
import os
import sys
import urllib.parse
import xml.etree.ElementTree
xmlns = "{http://schemas.microsoft.com/developer/msbuild/2003}"
elements = {"ClInclude", "ProjectReference", "Page", "Compile", "Resource", "EmbeddedResource", "None"}
def verify_path(dirname, relpath):
if not relpath:
return
path = os.path.join(dirname, urllib.parse.unquote(relpath))
if not os.path.exists(path):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), path)
def verify_project(project):
print(project)
root = None
try:
tree = xml.etree.ElementTree.parse(project)
root = tree.getroot()
if not root:
raise RuntimeError(f"[{project}] empty root")
if root.tag != f"{xmlns}Project":
raise RuntimeError(f"[{project}] unexpected root tag: {root.tag}")
except Exception as e:
print(e)
return
dirname = os.path.dirname(project)
for group in root.findall(f"{xmlns}ItemGroup"):
for element in elements:
for ref in group.findall(f"{xmlns}{element}"):
try:
verify_path(dirname, ref.get("Include"))
except Exception as e:
print(e)
def verify_projects(projects):
for project in projects:
verify_project(project)
if __name__ == "__main__":
verify_projects(sys.argv[1:])