Skip to content

Commit 225e8fc

Browse files
Add developer tool to print out IDS metadata types
Thanks @sebregm
1 parent 996876f commit 225e8fc

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tools/get_tagnames.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
""" Print out tag information contained in given DD XML
2+
"""
3+
import sys
4+
import xml.etree.ElementTree as ET
5+
from pathlib import Path
6+
from pprint import pprint
7+
from functools import reduce
8+
9+
10+
def parse_element(element: ET.Element):
11+
if element.tag == "field":
12+
dtype = element.attrib.get("data_type", None)
13+
summary.setdefault(dtype, set()).add(frozenset(element.attrib))
14+
else:
15+
ignored_tags.add(element.tag)
16+
for child in element:
17+
parse_element(child)
18+
19+
20+
if __name__ == "__main__":
21+
# Parse user arguments
22+
if len(sys.argv) > 1:
23+
xml_path = Path(sys.argv[1])
24+
else:
25+
xml_path = Path("IDSDef.xml")
26+
27+
tree = ET.parse(xml_path)
28+
root = tree.getroot()
29+
30+
summary = {}
31+
ignored_tags = set()
32+
33+
# Parse tree
34+
parse_element(root)
35+
36+
# Always print pretty, overwrites build-ins, I know
37+
print = pprint
38+
39+
print("Ignored tags:")
40+
print(ignored_tags)
41+
42+
print("Summary:")
43+
44+
for dtype in summary:
45+
print(f"Data type: {dtype}")
46+
print(reduce(set.union, summary[dtype], set()))
47+
48+
print("All:")
49+
print(
50+
reduce(
51+
set.union, (reduce(set.union, value, set()) for value in summary.values())
52+
)
53+
)

0 commit comments

Comments
 (0)