Skip to content

Commit 81a28d2

Browse files
author
Deepak Mewar
committed
List IDS paths that have name and identifier
but not full identifier structs(name, index, description) Signed-off-by: Deepak Mewar <deepak.mewar@iter.org>
1 parent bcd47fe commit 81a28d2

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tools/idslist_name_identifier.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import imas
2+
from imas.util import find_paths
3+
import re
4+
import argparse
5+
6+
def main():
7+
parser = argparse.ArgumentParser(
8+
description="List IDS paths that have name+identifier but are not full identifier structs"
9+
)
10+
parser.add_argument(
11+
"-v",
12+
"--version",
13+
default="4.0.0",
14+
help="Data dictionary version to use (default: 4.0.0)",
15+
)
16+
args = parser.parse_args()
17+
18+
cp = imas.IDSFactory(args.version)
19+
ids_list = cp.ids_names()
20+
21+
for ids_name in ids_list:
22+
obj = cp.new(ids_name)
23+
# Find parents that have both 'name' and 'identifier' children
24+
name_paths = find_paths(obj, "(^|/)name$")
25+
id_paths = find_paths(obj, "(^|/)identifier$")
26+
27+
def parent_of(p):
28+
return p.rsplit('/', 1)[0] if '/' in p else ''
29+
30+
name_parents = set(parent_of(p) for p in name_paths)
31+
id_parents = set(parent_of(p) for p in id_paths)
32+
33+
both_parents = sorted(name_parents & id_parents)
34+
filtered = []
35+
for parent in both_parents:
36+
# build sibling full paths
37+
def full(p):
38+
return f"{parent}/{p}" if parent else p
39+
40+
has_index = bool(find_paths(obj, f'^{re.escape(full("index"))}$'))
41+
has_desc = bool(find_paths(obj, f'^{re.escape(full("description"))}$'))
42+
43+
# Exclude parents that have name + index + description (full identifier struct)
44+
if has_index and has_desc:
45+
continue
46+
filtered.append(parent)
47+
48+
if filtered:
49+
print(ids_name, filtered)
50+
51+
52+
if __name__ == "__main__":
53+
main()
54+

0 commit comments

Comments
 (0)