-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathget_tagnames.py
More file actions
53 lines (41 loc) · 1.19 KB
/
get_tagnames.py
File metadata and controls
53 lines (41 loc) · 1.19 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
""" Print out tag information contained in given DD XML
"""
import sys
import xml.etree.ElementTree as ET
from pathlib import Path
from pprint import pprint
from functools import reduce
def parse_element(element: ET.Element):
if element.tag == "field":
dtype = element.attrib.get("data_type", None)
summary.setdefault(dtype, set()).add(frozenset(element.attrib))
else:
ignored_tags.add(element.tag)
for child in element:
parse_element(child)
if __name__ == "__main__":
# Parse user arguments
if len(sys.argv) > 1:
xml_path = Path(sys.argv[1])
else:
xml_path = Path("IDSDef.xml")
tree = ET.parse(xml_path)
root = tree.getroot()
summary = {}
ignored_tags = set()
# Parse tree
parse_element(root)
# Always print pretty, overwrites build-ins, I know
print = pprint
print("Ignored tags:")
print(ignored_tags)
print("Summary:")
for dtype in summary:
print(f"Data type: {dtype}")
print(reduce(set.union, summary[dtype], set()))
print("All:")
print(
reduce(
set.union, (reduce(set.union, value, set()) for value in summary.values())
)
)