def run(password, project_name, dataset_name, host, port):

    for user_number in range(1, 41):
        username = "******" % user_number
        print(username)
        conn = BlitzGateway(username, password, host=host, port=port)
        try:
            conn.connect()
            project = ProjectI()
            project.setName(rstring(project_name))
            update_service = conn.getUpdateService()
            project = update_service.saveAndReturnObject(project)

            ds = conn.getObject("Dataset",
                                attributes={'name': dataset_name},
                                opts={'owner': conn.getUserId()})
            if ds is None:
                print("No dataset with name %s found" % dataset_name)
                continue

            dataset_id = ds.getId()
            print(username, dataset_id)

            link = ProjectDatasetLinkI()
            link.setParent(ProjectI(project.getId().getValue(), False))
            link.setChild(DatasetI(dataset_id, False))
            conn.getUpdateService().saveObject(link)
        except Exception as exc:
            print("Error while creating project: %s" % str(exc))
        finally:
            conn.close()
示例#2
0
def post_dataset(conn, dataset_name, project_id=None, description=None):
    """Create a new dataset.

    Parameters
    ----------
    conn : ``omero.gateway.BlitzGateway`` object
        OMERO connection.
    dataset_name : str
        Name of the Dataset being created.
    project_id : int, optional
        Id of Project in which to create the Dataset. If no Project is
        specified, the Dataset will be orphaned.
    description : str
        Description for the new Dataset.

    Returns
    -------
    dataset_id : int
        Id of the dataset that has been created.

    Examples
    --------
    Create a new orphaned Dataset:
    >>> did = post_dataset(conn, "New Dataset")
    >>> did
    234

    Create a new Dataset in Project:120:
    >>> did = post_dataset(conn, "Child of 120", project_id=120)
    >>> did
    """
    if type(dataset_name) is not str:
        raise TypeError('Dataset name must be a string')

    if type(description) is not str and description is not None:
        raise TypeError('Dataset description must be a string')

    dataset = DatasetWrapper(conn, DatasetI())
    dataset.setName(dataset_name)
    if description is not None:
        dataset.setDescription(description)
    dataset.save()

    if project_id is not None:
        if type(project_id) is not int:
            raise TypeError('Project ID must be integer')

        link = ProjectDatasetLinkI()
        link.setParent(ProjectI(project_id, False))
        link.setChild(DatasetI(dataset.getId(), False))
        conn.getUpdateService().saveObject(link)

    return dataset.getId()
示例#3
0
def create_new_dataset(ctx, project_id, ds_name, ):
    dataset_obj = omero.model.DatasetI()
    dataset_obj.setName(rstring(ds_name))
    dataset_obj = gateway.getUpdateService(ctx).saveAndReturnObject(dataset_obj)
    dataset_id = dataset_obj.getId().getValue()

    dm = gateway.getFacility(DataManagerFacility)
    link = ProjectDatasetLinkI();
    link.setChild(dataset_obj);
    link.setParent(ProjectI(project_id, False));
    r = dm.saveAndReturnObject(ctx, link);
    return dataset_id 
def run(password, project_name, dataset_name, host, port):

    for user_number in range(1, 51):
        username = "******" % user_number
        print(username)
        conn = BlitzGateway(username, password, host=host, port=port)
        try:
            conn.connect()

            params = omero.sys.ParametersI()
            params.addString('username', username)
            # make sure only one result is returned by query
            params.page(0, 1)
            query = "from Project where name='%s' \
                    AND details.owner.omeName=:username \
                    ORDER BY id DESC" % project_name
            service = conn.getQueryService()
            pr_list = service.findAllByQuery(query, params, conn.SERVICE_OPTS)

            if pr_list is None:
                print("No project with name %s found" % project_name)
                continue

            project_id = pr_list[0].getId().getValue()
            print(username, project_id)

            params = omero.sys.ParametersI()
            params.addString('username', username)
            # make sure only one result is returned by query
            params.page(0, 1)
            query = "from Dataset where name='%s' \
                     AND details.owner.omeName=:username \
                     ORDER BY id DESC" % dataset_name
            service = conn.getQueryService()
            ds_list = service.findAllByQuery(query, params, conn.SERVICE_OPTS)

            if ds_list is None:
                print("No dataset with name %s found" % dataset_name)
                continue

            dataset_id = ds_list[0].getId().getValue()
            print(username, dataset_id)

            link = ProjectDatasetLinkI()
            link.setParent(ProjectI(project_id, False))
            link.setChild(DatasetI(dataset_id, False))
            conn.getUpdateService().saveObject(link)
        except Exception as exc:
            print("Error while linking to project: %s" % str(exc))
        finally:
            conn.close()
示例#5
0
    def link(self, obj1, obj2, client=None):
        """
        Links two linkable model entities together by creating an instance of
        the correct link entity (e.g. ProjectDatasetLinkI) and persisting it
        in the DB. Accepts client instance to allow calls to happen in correct
        user contexts. Currently support links are:
          * project/dataset
          * dataset/image
          * image/annotation

        :param obj1: parent object
        :param obj2: child object
        :param client: The client to use to create the link
        """
        if client is None:
            client = self.client
        if isinstance(obj1, ProjectI):
            if isinstance(obj2, DatasetI):
                link = ProjectDatasetLinkI()
        elif isinstance(obj1, DatasetI):
            if isinstance(obj2, ImageI):
                link = DatasetImageLinkI()
        elif isinstance(obj1, ImageI):
            if isinstance(obj2, Annotation):
                link = ImageAnnotationLinkI()
        else:
            assert False, "Object type not supported."

        """check if object exist or not"""
        if obj1.id is None:
            link.setParent(obj1)
        else:
            link.setParent(obj1.proxy())
        if obj2.id is None:
            link.setChild(obj2)
        else:
            link.setChild(obj2.proxy())
        return client.sf.getUpdateService().saveAndReturnObject(link)
示例#6
0
    def link(self, obj1, obj2, client=None):
        """
        Links two linkable model entities together by creating an instance of
        the correct link entity (e.g. ProjectDatasetLinkI) and persisting it
        in the DB. Accepts client instance to allow calls to happen in correct
        user contexts. Currently support links are:
          * project/dataset
          * dataset/image
          * image/annotation

        :param obj1: parent object
        :param obj2: child object
        :param client: The client to use to create the link
        """
        if client is None:
            client = self.client
        if isinstance(obj1, ProjectI):
            if isinstance(obj2, DatasetI):
                link = ProjectDatasetLinkI()
        elif isinstance(obj1, DatasetI):
            if isinstance(obj2, ImageI):
                link = DatasetImageLinkI()
        elif isinstance(obj1, ImageI):
            if isinstance(obj2, Annotation):
                link = ImageAnnotationLinkI()
        else:
            assert False, "Object type not supported."
        """check if object exist or not"""
        if obj1.id is None:
            link.setParent(obj1)
        else:
            link.setParent(obj1.proxy())
        if obj2.id is None:
            link.setChild(obj2)
        else:
            link.setChild(obj2.proxy())
        return client.sf.getUpdateService().saveAndReturnObject(link)