Пример #1
0
    def get_selection_from_location(self, location='.'):
        """
        Return a PFDBObj object based on a location.

        i.e.:
          run.Process.Topology.get_selection_from_location('.') =>
              run.Process.Topology
          run.Process.Topology.get_selection_from_location('..') => run.Process
          run.Process.Topology.get_selection_from_location('../../Geom') =>
              run.Geom
          run.Process.Topology.get_selection_from_location('/Geom') => run.Geom
        """
        current_location = self
        path_items = location.split('/')
        if location[0] == '/':
            while current_location._parent_ is not None:
                current_location = current_location._parent_

        next_list = [current_location]
        for path_item in path_items:
            if not path_item:
                continue

            current_list = next_list
            next_list = []

            if path_item == '..':
                next_list.extend(map(map_to_parent, current_list))
            elif path_item == '.':
                next_list.extend(map(map_to_self, current_list))
            elif path_item[0] == '{':
                multi_list = map(map_to_children_of_type(path_item[1:-1]),
                                 current_list)
                next_list = [
                    item for sublist in multi_list for item in sublist
                ]
            else:
                next_list.extend(map(map_to_child(path_item), current_list))
                if len(next_list) and isinstance(next_list[0], list):
                    next_list = [
                        item for sublist in next_list for item in sublist
                    ]

        return next_list
Пример #2
0
    def select(self, location='.'):
        """
        Return a PFDBObj object based on a location.

        i.e.:
          run.Process.Topology.select('.') => run.Process.Topology
          run.Process.Topology.select('..') => run.Process
          run.Process.Topology.select('../../Geom') => run.Geom
          run.Process.Topology.select('/Geom') => run.Geom
        """
        current_location = self
        path_items = location.split('/')
        if location.startswith('/'):
            while current_location._parent_ is not None:
                current_location = current_location._parent_

        next_list = [current_location]
        for path_item in path_items:
            if not path_item:
                continue

            current_list = next_list
            next_list = []

            if path_item == '..':
                next_list.extend(map(map_to_parent, current_list))
            elif path_item == '.':
                next_list.extend(map(map_to_self, current_list))
            elif path_item.startswith('{'):
                multi_list = map(map_to_children_of_type(path_item[1:-1]),
                                 current_list)
                next_list = [x for sublist in multi_list for x in sublist]
            else:
                next_list.extend(
                    filter(filter_none,
                           map(map_to_child(path_item), current_list)))
                if next_list and isinstance(next_list[0], list):
                    next_list = [x for sublist in next_list for x in sublist]

        return next_list