Exemplo n.º 1
0
    def _find_compositor(self, dataset_key):
        """Find the compositor object for the given dataset_key."""
        # NOTE: This function can not find a modifier that performs
        # one or more modifications if it has modifiers see if we can find
        # the unmodified version first
        src_node = None
        if isinstance(dataset_key, DataQuery) and dataset_key.get('modifiers'):
            new_dict = dataset_key.to_dict()
            new_dict['modifiers'] = tuple(new_dict['modifiers'][:-1])
            new_prereq = DataQuery.from_dict(new_dict)
            src_node, u = self._find_dependencies(new_prereq)
            # Update the requested DatasetQuery with information from the src
            if src_node is not None:
                dataset_key = self._update_modifier_id(dataset_key,
                                                       src_node.name)
            if u:
                return None, u
        elif isinstance(dataset_key, str):
            dataset_key = DataQuery(name=dataset_key)
        try:
            compositor = self.get_compositor(dataset_key)
        except KeyError:
            raise KeyError("Can't find anything called {}".format(
                str(dataset_key)))

        cid = compositor.id
        root = Node(cid, data=(compositor, [], []))
        if src_node is not None:
            self.add_child(root, src_node)
            root.data[1].append(src_node)

        query = cid.create_dep_filter(dataset_key)
        # 2.1 get the prerequisites
        LOG.trace(
            "Looking for composite prerequisites for: {}".format(dataset_key))
        prereqs, unknowns = self._get_compositor_prereqs(
            root, compositor.attrs['prerequisites'], query=query)
        if unknowns:
            # Should we remove all of the unknown nodes that were found ?
            # if there is an unknown prerequisite are we in trouble?
            return None, unknowns
        root.data[1].extend(prereqs)

        # Get the optionals
        LOG.trace(
            "Looking for optional prerequisites for: {}".format(dataset_key))
        optional_prereqs, _ = self._get_compositor_prereqs(
            root,
            compositor.attrs['optional_prerequisites'],
            skip=True,
            query=query)
        root.data[2].extend(optional_prereqs)

        return root, set()
Exemplo n.º 2
0
    def _get_coordinates_for_dataset_key(self, dsid):
        """Get the coordinate dataset keys for *dsid*."""
        ds_info = self.all_ids[dsid]
        cids = []

        for cinfo in ds_info.get('coordinates', []):
            if not isinstance(cinfo, dict):
                cinfo = {'name': cinfo}
            for key in self._co_keys:
                if key == 'name':
                    continue
                if key in ds_info:
                    if ds_info[key] is not None:
                        cinfo[key] = ds_info[key]
            cid = DataQuery.from_dict(cinfo)
            cids.append(self.get_dataset_key(cid))

        return cids