diff --git a/src/omero/plugins/obj.py b/src/omero/plugins/obj.py index e9fd44226..ff24626a7 100755 --- a/src/omero/plugins/obj.py +++ b/src/omero/plugins/obj.py @@ -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) @@ -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): @@ -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 @@ -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="?", @@ -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) diff --git a/test/unit/clitest/test_obj.py b/test/unit/clitest/test_obj.py index 3b48e179e..348be1c0c 100644 --- a/test/unit/clitest/test_obj.py +++ b/test/unit/clitest/test_obj.py @@ -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