Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 68 additions & 1 deletion src/omero/plugins/obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ def on_go(self, ctx, args):
+ str(self.get_field(field)) + "\n")
except AttributeError:
pass
proxy = proxy.strip()

self.tx_state.set_value(proxy, dest=self.tx_cmd.dest)

Expand Down Expand Up @@ -460,6 +461,62 @@ def on_go(self, ctx, args):
self.tx_state.set_value(proxy, dest=self.tx_cmd.dest)


class ParentsTxAction(NonFieldTxAction):

def on_go(self, ctx, args):
from omero.cmd import FindParents
import omero.callbacks

if len(self.tx_cmd.arg_list) < 3:
ctx.die(335, "usage: parents OBJ type [type ...]")

req = FindParents()
req.targetObjects = {self.kls: [self.obj.id.val]}
req.typesOfParents = self.tx_cmd.arg_list[2:]
handle = self.client.sf.submit(req)
cb = omero.callbacks.CmdCallbackI(self.client, handle)
cb.loop(8, 500)

rsp = cb.getResponse()
if isinstance(rsp, omero.cmd.ERR):
proxy = "failed: '%s'" % rsp.name
else:
proxy = ""
for kls, ids in rsp.parents.items():
proxy += (kls.split(".")[-1] + ":"
+ ",".join(str(id) for id in ids) + "\n")
proxy = proxy.strip()
self.tx_state.set_value(proxy, dest=self.tx_cmd.dest)


class ChildrenTxAction(NonFieldTxAction):

def on_go(self, ctx, args):
from omero.cmd import FindChildren
import omero.callbacks

if len(self.tx_cmd.arg_list) < 3:
ctx.die(335, "usage: children OBJ type [type ...]")

req = FindChildren()
req.targetObjects = {self.kls: [self.obj.id.val]}
req.typesOfChildren = self.tx_cmd.arg_list[2:]
handle = self.client.sf.submit(req)
cb = omero.callbacks.CmdCallbackI(self.client, handle)
cb.loop(8, 500)

rsp = cb.getResponse()
if isinstance(rsp, omero.cmd.ERR):
proxy = "failed: '%s'" % rsp.name
else:
proxy = ""
for kls, ids in rsp.children.items():
proxy += (kls.split(".")[-1] + ":"
+ ",".join(str(id) for id in ids) + "\n")
proxy = proxy.strip()
self.tx_state.set_value(proxy, dest=self.tx_cmd.dest)


class TxState(object):

def __init__(self, ctx):
Expand Down Expand Up @@ -513,6 +570,12 @@ class ObjControl(BaseControl):
Dataset:123
$ omero obj get Dataset:123 description

$ bin/omero obj children Dataset:123 Image
Image:51,52
$ bin/omero obj parents Image:51 Dataset Fileset
Dataset:123
Fileset:51

$ omero obj new MapAnnotation ns=example.com
MapAnnotation:456
$ omero obj map-set MapAnnotation:456 mapValue foo bar
Expand Down Expand Up @@ -548,7 +611,7 @@ def _configure(self, parser):
"command", nargs="?",
choices=("new", "update", "null",
"map-get", "map-set",
"get", "list-get"),
"get", "list-get", "parents", "children"),
help="operation to be performed")
parser.add_argument(
"Class", nargs="?",
Expand Down Expand Up @@ -611,6 +674,10 @@ def parse(self, tx_state, arg_list=None, line=None):
return ObjGetTxAction(tx_state, tx_cmd)
elif tx_cmd.action == "list-get":
return ListGetTxAction(tx_state, tx_cmd)
elif tx_cmd.action == "parents":
return ParentsTxAction(tx_state, tx_cmd)
elif tx_cmd.action == "children":
return ChildrenTxAction(tx_state, tx_cmd)
else:
raise self.ctx.die(100, "Unknown command: %s" % tx_cmd)

Expand Down
2 changes: 1 addition & 1 deletion test/unit/clitest/test_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

"""
Test of the omero/plugins/tx.py module
Test of the omero/plugins/obj.py module
"""

from builtins import object
Expand Down