Example #1
0
def unlink_attribute_references(group, ref_attr_names_types=None):
    # Locate any variable and group attributes previously identified as
    # variable references, and reconstruct the attribute string from the names
    # of the referenced elements.
    groups_and_vars = ncg.all_variables(group) + ncg.all_groups(group)
    for elem in groups_and_vars:
        for ref_name, _ in REFERENCE_ATTRIBUTES_NAMES_AND_TYPES:
            attr = elem.attributes.get(ref_name, None)
            if attr:
                attr.value = ' '.join(defstring_from_reftag(reftag)
                                      for reftag in attr.value)
Example #2
0
def link_attribute_references(group):
    # Locate all variable and group attributes that contain variable
    # references (i.e. names), and replace their values with data containing
    # links to the actual variables, so we can reconstruct these attributes
    # after possibly renaming variables.
    groups_and_vars = ncg.all_variables(group) + ncg.all_groups(group)
    for elem in groups_and_vars:
        in_group = (elem if isinstance(elem, nco.Group)
                    else elem.container.in_element)
        assert isinstance(in_group, nco.Group)
        for ref_name, ref_type in REFERENCE_ATTRIBUTES_NAMES_AND_TYPES:
            attr = elem.attributes.get(ref_name, None)
            if attr:
                refs = split_noempties(attr.value, ' ')
                attr.value = [reftag_from_defstring(ref, in_group, ref_type)
                              for ref in refs]
Example #3
0
 def test_all_groups(self):
     walk_objs = list(all_groups(self.root))
     self._check_all_of_type(walk_objs, nco.Group)