Ejemplo n.º 1
0
    def ensure_dataset_locations(self, dataset_id, uris):
        """
        Add a location to a dataset if it is not already recorded.
        :type dataset_id: str or uuid.UUID
        :type uris: list[str]
        """

        for uri in uris:
            scheme, body = _split_uri(uri)

            try:
                self._connection.execute(
                    DATASET_LOCATION.insert(),
                    dataset_ref=dataset_id,
                    uri_scheme=scheme,
                    uri_body=body,
                )
            except IntegrityError as e:
                if e.orig.pgcode == PGCODE_UNIQUE_CONSTRAINT:
                    raise DuplicateRecordError('Location already exists: %s' %
                                               uri)
                raise