Exemple #1
0
    def _merge_sta_element(self,
                           net_element,
                           sta_element,
                           namespaces=settings.STATIONXML_NAMESPACES):
        """
        Merges a *StationXML* :code:`<Station></Station>` epoch element into a
        :code:`<Network></Network>` epoch element. Merging is performed
        recursively down to :code:`<Channel><Channel>` epochs.
        """
        # XXX(damb): Check if <Station></Station> epoch element is already
        # available - if not simply append.
        for _sta_element in net_element.iterfind(sta_element.tag):
            if elements_equal(sta_element,
                              _sta_element,
                              exclude_tags=[
                                  '{}{}'.format(ns, self.CHANNEL_TAG)
                                  for ns in namespaces
                              ],
                              recursive=False):
                # XXX(damb): Channels are ALWAYS appended; no merging is
                # performed
                for _cha_element in self._emerge_cha_elements(
                        sta_element, namespaces):
                    _sta_element.append(_cha_element)
                break

        else:
            net_element.append(sta_element)
Exemple #2
0
    def _merge_sta_element(self,
                           net_element,
                           sta_element,
                           namespaces=settings.STATIONXML_NAMESPACES):

        # order child elements by tag
        sta_element[:] = sorted(sta_element, key=lambda c: c.tag)

        # XXX(damb): Check if <Station></Station> epoch element is already
        # available - if not simply append.
        for _sta_element in net_element.iterfind(sta_element.tag):

            _sta_element[:] = sorted(_sta_element, key=lambda c: c.tag)
            if elements_equal(sta_element,
                              _sta_element,
                              exclude_tags=[
                                  '{}{}'.format(ns, self.CHANNEL_TAG)
                                  for ns in namespaces
                              ],
                              recursive=False):
                # XXX(damb): Channels are ALWAYS appended; no merging is
                # performed
                for _cha_element in self._emerge_cha_elements(
                        sta_element, namespaces):
                    _sta_element.append(_cha_element)
                break

        else:
            net_element.append(sta_element)
Exemple #3
0
    def _emerge_net_element(self, net_element, exclude_tags=[]):
        """
        Emerge a :code:`<Network></Network>` epoch element.

        :param net_element: Emerge a network epoch element
        :type net_element: :py:class:`lxml.etree.Element`
        :param list exclude_tags: List of child element tags to be excluded
            while comparing
        :returns: Tuple of :code:`net_element` or a reference to an already
            existing network epoch element and a boolean value if the network
            element already is known (:code:`True`) else :code:`False`
        :rtype: tuple
        """
        # order child elements by tag
        net_element[:] = sorted(net_element, key=lambda c: c.tag)

        for existing_net_element in self._network_elements:
            if elements_equal(net_element,
                              existing_net_element,
                              exclude_tags,
                              recursive=True):
                return existing_net_element, True

        self._network_elements.append(net_element)
        return net_element, False
Exemple #4
0
    def test_unequal(self):
        t = etree.parse(self.ifd).getroot()
        t[:] = sorted(t, key=lambda c: c.tag)
        t_other = copy.deepcopy(t)
        # remove a single child element (here the first one)
        t_other[:] = t[1:]

        self.assertFalse(elements_equal(t, t_other))
Exemple #5
0
    def test_unequal_with_exclude_nonrecursive(self):
        t = etree.parse(self.ifd).getroot()
        t[:] = sorted(t, key=lambda c: c.tag)
        t_other = copy.deepcopy(t)
        # manipulate a single child element
        t_other[1][0].text = 'FOO'

        self.assertFalse(
            elements_equal(
                t, t_other,
                exclude_tags=['{}{}'.format(ns, 'Description') for ns in \
                              settings.STATIONXML_NAMESPACES],
                recursive=False))
Exemple #6
0
    def test_equal(self):
        t = etree.parse(self.ifd).getroot()
        t[:] = sorted(t, key=lambda c: c.tag)
        t_other = copy.deepcopy(t)

        self.assertTrue(elements_equal(t, t_other))