diff --git a/CHANGES.txt b/CHANGES.txt index e402dac4c7890237ee49bdb69bb894cd620856c0..02c908e56c10588d6840773b92a14bf073109649 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 7580759f21cb846c43655892b96a243fdf5bc0e4..d5661c74613e9da3ce71bc839fee4375880a90f7 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 feb855d2ee209a293beddec7a5f394973c16c110..72117e3c48c450aaefc1361e034802d5be8bb128 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):