def _remove_setting(self, config, keys, info=None): """Remove a setting from the configuration, if it exists.""" section, option = self._get_section_option_from_keys(keys) if config.get([section, option]) is None: return False if info is None: info = self.INFO_REMOVED node = config.unset([section, option]) value = "" if node.value: value = node.value self.add_report(section, option, value, info)
def annotate_config_with_metadata( config, meta_config, ignore_regexes=None, metadata_properties=None ): """Add metadata to the metomi.rose.config.ConfigNode.comments attribute. config -- a metomi.rose.config.ConfigNode instance, containing app or suite data. meta_config -- a metomi.rose.config.ConfigNode instance, containing metadata for config. ignore_regexes -- (default None) a list of uncompiled regular expressions - if a setting contains any of these, don't include it in the annotated output. """ if ignore_regexes is None: ignore_regexes = [] ignore_recs = [re.compile(_) for _ in ignore_regexes] unset_keys = [] for keylist, node in config.walk(): section = keylist[0] option = None if len(keylist) > 1: option = keylist[1] id_ = metomi.rose.macro.get_id_from_section_option(section, option) if any(_.search(id_) for _ in ignore_recs): unset_keys.append(keylist) continue metadata = metomi.rose.macro.get_metadata_for_config_id( id_, meta_config ) metadata_text = format_metadata_as_text( metadata, only_these_options=metadata_properties ) metadata_lines = [" " + line for line in metadata_text.splitlines()] node.comments = metadata_lines + node.comments for keylist in unset_keys: config.unset(keylist) return config