Skip to content

Instantly share code, notes, and snippets.

@chris-allan
Last active December 23, 2015 13:09
Show Gist options
  • Select an option

  • Save chris-allan/6639776 to your computer and use it in GitHub Desktop.

Select an option

Save chris-allan/6639776 to your computer and use it in GitHub Desktop.
Create an OMERO Dataset from the command line
#!/usr/bin/env python
# encoding: utf-8
"""
Create an OMERO Dataset from the command line
Adapted from OME forum post of "Josh Moore <josh@glencoesoftware.com>":
* http://www.openmicroscopy.org/community/viewtopic.php?f=4&t=602
Copyright (C) 2013 Glencoe Software, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
import sys
import omero
from omero.rtypes import rstring
from omero_ext import argparse
client = omero.client()
session = client.getProperty("omero.sess")
session = client.joinSession(session)
p = argparse.ArgumentParser()
p.add_argument("name", type=omero.rtypes.rstring)
p.add_argument("description", type=omero.rtypes.rstring)
p.add_argument("--project_id", type=omero.rtypes.rlong, default=None)
ns, other = p.parse_known_args()
updateService = session.getUpdateService()
d = omero.model.DatasetI()
d.setName(ns.name)
d.setDescription(ns.description)
if ns.project_id is not None:
d.linkProject(omero.model.ProjectI(ns.project_id, False))
d = updateService.saveAndReturnObject(d)
print d.id.val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment