From 2efefdfdd6b08247f0ebfd7277d553973aadb12b Mon Sep 17 00:00:00 2001 From: Karl-Hermann Wieners <karl-hermann.wieners@mpimet.mpg.de> Date: Thu, 23 Jul 2020 21:27:38 +0200 Subject: [PATCH] Configuration: Added new way to disable namelist groups (.hide) Namelist groups may be disabled by setting the special variable '.hide' to 'true'. This allows to selectively re-enable groups in higher order config files by setting '.hide' to 'false' --- CHANGES.txt | 7 +++++++ mkexp | 5 +++-- test.py | 23 +++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index e402dac..02c908e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -15,6 +15,13 @@ Global * Changed version info to be retrieved from version control system. This requires an additional 'make' step before running +Configuration +------------- + +* Added new way to disable namelist groups by setting the special variable + '.hide' to 'true'. This allows to selectively re-enable groups in higher + order config files by setting '.hide' to 'false' + Templates --------- diff --git a/mkexp b/mkexp index 7580759..d5661c7 100755 --- a/mkexp +++ b/mkexp @@ -169,8 +169,9 @@ def format_namelist(section, group=None): iterator = {group: section[group]}.iteritems() if group else section.iteritems() for group, contents in iterator: if isinstance(contents, dict): + hidden = is_set(contents.get('.hide', 'false')) group_id = group.lower() - if not any(map(lambda x: re.match(x, group_id), black_list)): + if not hidden and not any(map(lambda x: re.match(x, group_id), black_list)): # Create list of removed keys remove_keys = get_remove_list(contents, '.remove') group_names = group_id.split(' ', 1) @@ -179,7 +180,7 @@ def format_namelist(section, group=None): else: lines.write('&'+group_names[0]+" ! '"+group_names[1]+"'\n") for key, value in contents.iteritems(): - if key not in remove_keys: + if key[0] != '.' and key not in remove_keys: key = key.lower() indent = base_indent + len(key) + 3 for line in contents.comments.get(key, []): diff --git a/test.py b/test.py index feb855d..72117e3 100644 --- a/test.py +++ b/test.py @@ -525,6 +525,29 @@ class NamelistTestCase(MkexpSimpleTestCase): value = 43 """) + def test_namelist_hide(self): + self.run_test(""" + %{NAMELIST} + """, """ + &group1 + value = 41 + / + &group3 + value = 43 + / + """, """ + [namelists] + [[namelist]] + [[[group1]]] + value = 41 + [[[group2]]] + .hide = true + value = 42 + [[[group3]]] + .hide = dont_care_if_we_dont_start_with_t + value = 43 + """) + class JinjaTemplateTestCase(MkexpSimpleTestCase): def test_ignore_blocks(self): -- GitLab