def doChange(self, obj_type, obj_id, group_id, test_should_pass=True, return_complete=True): """ Performs the change-group action, waits on completion and checks that the result is not an error. """ prx = self.gateway.chgrpObject(obj_type, obj_id, group_id) if not return_complete: return prx cb = CmdCallbackI(self.gateway.c, prx) for i in range(10): cb.loop(20, 500) if prx.getResponse() != None: break self.assertNotEqual(prx.getResponse(), None) status = prx.getStatus() rsp = prx.getResponse() if test_should_pass: if isinstance(rsp, ERR): self.fail("Found ERR when test_should_pass==true: %s (%s) params=%s" % (rsp.category, rsp.name, rsp.parameters)) self.assertFalse(State.FAILURE in prx.getStatus().flags) else: if isinstance(rsp, OK): self.fail("Found OK when test_should_pass==false: %s", rsp) self.assertTrue(State.FAILURE in prx.getStatus().flags) return rsp
def doSubmit(self, request, client, test_should_pass=True): """ Performs the request waits on completion and checks that the result is not an error. """ sf = client.sf prx = sf.submit(request) self.assertFalse(State.FAILURE in prx.getStatus().flags) cb = CmdCallbackI(client, prx) cb.loop(20, 500) self.assertNotEqual(prx.getResponse(), None) status = prx.getStatus() rsp = prx.getResponse() if test_should_pass: if isinstance(rsp, ERR): self.fail("Found ERR when test_should_pass==true: %s (%s) params=%s" % (rsp.category, rsp.name, rsp.parameters)) self.assertFalse(State.FAILURE in prx.getStatus().flags) else: if isinstance(rsp, OK): self.fail("Found OK when test_should_pass==false: %s", rsp) self.assertTrue(State.FAILURE in prx.getStatus().flags) return rsp
def write_to_omero(self): to_delete = {"Annotation": self.mapannids + self.fileannids} delCmd = omero.cmd.Delete2(targetObjects=to_delete) handle = self.client.getSession().submit(delCmd) callback = None try: callback = CmdCallbackI(self.client, handle) loops = max(10, len(self.mapannids) / 10) delay = 500 callback.loop(loops, delay) rsp = callback.getResponse() if isinstance(rsp, omero.cmd.OK): ndma = len( rsp.deletedObjects.get( "ome.model.annotations.MapAnnotation", [])) log.info("Deleted %d MapAnnotation(s)", ndma) ndfa = len( rsp.deletedObjects.get( "ome.model.annotations.FileAnnotation", [])) log.info("Deleted %d FileAnnotation(s)", ndfa) else: log.error("Delete failed: %s", rsp) finally: if callback: callback.close(True) else: handle.close()
def wait_on_callback(self, conn, proxy, test_should_pass=True): """ Handles callback on proxy handle and checks that the result is not an error. """ cb = CmdCallbackI(conn.c, proxy) try: for i in range(10): cb.loop(20, 500) if proxy.getResponse() is not None: break assert proxy.getResponse() is not None proxy.getStatus() rsp = proxy.getResponse() if test_should_pass: assert not isinstance(rsp, ERR) assert State.FAILURE not in proxy.getStatus().flags else: assert not isinstance(rsp, OK) assert State.FAILURE in proxy.getStatus().flags return rsp finally: cb.close(True)
def doChange(gateway, obj_type, obj_ids, group_id, container_id=None, test_should_pass=True, return_complete=True): """ Performs the change-group action, waits on completion and checks that the result is not an error. """ prx = gateway.chgrpObjects(obj_type, obj_ids, group_id, container_id) if not return_complete: return prx cb = CmdCallbackI(gateway.c, prx) try: for i in range(10): cb.loop(20, 500) if prx.getResponse() is not None: break assert prx.getResponse() is not None prx.getStatus() rsp = prx.getResponse() if test_should_pass: assert not isinstance(rsp, ERR), \ "Found ERR when test_should_pass==true: %s (%s) params=%s" \ % (rsp.category, rsp.name, rsp.parameters) assert State.FAILURE not in prx.getStatus().flags else: assert not isinstance(rsp, OK), \ "Found OK when test_should_pass==false: %s" % rsp assert State.FAILURE in prx.getStatus().flags return rsp finally: cb.close(True)
def write_to_omero(self): to_delete = {"Annotation": self.mapannids + self.fileannids} delCmd = omero.cmd.Delete2(targetObjects=to_delete) handle = self.client.getSession().submit(delCmd) callback = None try: callback = CmdCallbackI(self.client, handle) loops = max(10, len(self.mapannids) / 10) delay = 500 callback.loop(loops, delay) rsp = callback.getResponse() if isinstance(rsp, omero.cmd.OK): ndma = len(rsp.deletedObjects.get( "ome.model.annotations.MapAnnotation", [])) log.info("Deleted %d MapAnnotation(s)", ndma) ndfa = len(rsp.deletedObjects.get( "ome.model.annotations.FileAnnotation", [])) log.info("Deleted %d FileAnnotation(s)", ndfa) else: log.error("Delete failed: %s", rsp) finally: if callback: callback.close(True) else: handle.close()
def doSubmit(self, request, client, test_should_pass=True, omero_group=None): """ Performs the request waits on completion and checks that the result is not an error. """ sf = client.sf if omero_group is not None: prx = sf.submit(request, {'omero.group': str(omero_group)}) else: prx = sf.submit(request) assert State.FAILURE not in prx.getStatus().flags cb = CmdCallbackI(client, prx) cb.loop(20, 500) assert prx.getResponse() is not None rsp = prx.getResponse() if test_should_pass: if isinstance(rsp, ERR): assert False,\ "Found ERR when test_should_pass==true: %s (%s) params=%s" %\ (rsp.category, rsp.name, rsp.parameters) assert State.FAILURE not in prx.getStatus().flags else: if isinstance(rsp, OK): assert False, "Found OK when test_should_pass==false: %s" % rsp assert State.FAILURE in prx.getStatus().flags return rsp
def doSubmit(self, request, client, test_should_pass=True): """ Performs the request waits on completion and checks that the result is not an error. """ sf = client.sf prx = sf.submit(request) assert not State.FAILURE in prx.getStatus().flags cb = CmdCallbackI(client, prx) cb.loop(20, 500) assert prx.getResponse() != None status = prx.getStatus() rsp = prx.getResponse() if test_should_pass: if isinstance(rsp, ERR): assert False,\ "Found ERR when test_should_pass==true: %s (%s) params=%s" %\ (rsp.category, rsp.name, rsp.parameters) assert not State.FAILURE in prx.getStatus().flags else: if isinstance(rsp, OK): assert False, "Found OK when test_should_pass==false: %s" % rsp assert State.FAILURE in prx.getStatus().flags return rsp
def doChange(self, obj_type, obj_ids, group_id, container_id=None, test_should_pass=True, return_complete=True): """ Performs the change-group action, waits on completion and checks that the result is not an error. """ prx = self.gateway.chgrpObjects(obj_type, obj_ids, group_id, container_id) if not return_complete: return prx cb = CmdCallbackI(self.gateway.c, prx) try: for i in range(10): cb.loop(20, 500) if prx.getResponse() != None: break self.assertNotEqual(prx.getResponse(), None) status = prx.getStatus() rsp = prx.getResponse() if test_should_pass: if isinstance(rsp, ERR): self.fail("Found ERR when test_should_pass==true: %s (%s) params=%s" % (rsp.category, rsp.name, rsp.parameters)) self.assertFalse(State.FAILURE in prx.getStatus().flags) else: if isinstance(rsp, OK): self.fail("Found OK when test_should_pass==false: %s", rsp) self.assertTrue(State.FAILURE in prx.getStatus().flags) return rsp finally: cb.close(True)
def doChange(self, group_id, permissions, test_should_pass=True, return_complete=True): """ Performs the chmod action, waits on completion and checks that the result is not an error. """ prx = self.gateway.chmodGroup(group_id, permissions) if not return_complete: return prx cb = CmdCallbackI(self.gateway.c, prx) cb.loop(20, 500) # This fails (see #8439). Can comment out this line and # try a different way of waiting for result - This never completes... import time rsp = prx.getResponse() i = 0 while (rsp is None): time.sleep(10) rsp = prx.getResponse() i += 1 print "rsp", i, rsp self.assertNotEqual(rsp, None) status = prx.getStatus() if test_should_pass: if isinstance(rsp, ERR): self.fail("Found ERR when test_should_pass==true: %s (%s) params=%s" % (rsp.category, rsp.name, rsp.parameters)) self.assertFalse(State.FAILURE in prx.getStatus().flags) else: if isinstance(rsp, OK): self.fail("Found OK when test_should_pass==false: %s", rsp) self.assertTrue(State.FAILURE in prx.getStatus().flags) return rsp
def doSubmit(self, request, client, test_should_pass=True): """ Performs the request waits on completion and checks that the result is not an error. """ sf = client.sf prx = sf.submit(request) self.assertFalse(State.FAILURE in prx.getStatus().flags) cb = CmdCallbackI(client, prx) cb.loop(20, 500) self.assertNotEqual(prx.getResponse(), None) status = prx.getStatus() rsp = prx.getResponse() if test_should_pass: if isinstance(rsp, ERR): self.fail( "Found ERR when test_should_pass==true: %s (%s) params=%s" % (rsp.category, rsp.name, rsp.parameters)) self.assertFalse(State.FAILURE in prx.getStatus().flags) else: if isinstance(rsp, OK): self.fail("Found OK when test_should_pass==false: %s", rsp) self.assertTrue(State.FAILURE in prx.getStatus().flags) return rsp
def submit(self, req): import omero handle = self.client.sf.submit(req) cb = CmdCallbackI(self.client, handle) try: cb.loop(50, 1000) rsp = cb.getResponse() if isinstance(rsp, omero.cmd.ERR): raise Exception(rsp) return rsp finally: cb.close(True)
def testChgrpImage(self): # Data Setup img = self.new_image() img = self.update.saveAndReturnObject(img) # New method chgrp = omero.cmd.Chgrp2(targetObjects={'Image': [img.id.val]}) handle = self.sf.submit(chgrp) cb = CmdCallbackI(self.client, handle) cb.loop(20, 750) # Check Data self.query.get("Image", img.id.val)
def testChgrpImage(self): # One user in two groups client, exp = self.new_client_and_user() update = client.sf.getUpdateService() query = client.sf.getQueryService() # Data Setup img = self.new_image() img = update.saveAndReturnObject(img) # New method chgrp = omero.cmd.Chgrp(type="/Image", id=img.id.val, options=None) handle = client.sf.submit(chgrp) cb = CmdCallbackI(client, handle) cb.loop(20, 750) # Check Data query.get("Image", img.id.val)
def doSubmit(self, request, client, test_should_pass=True, omero_group=None): """ Performs the request(s), waits on completion and checks that the result is not an error. The request can either be a single command or a list of commands. If the latter then the request list will be wrapped in a DoAll. """ if isinstance(request, list): request = DoAll(request) sf = client.sf if omero_group is not None: prx = sf.submit(request, {'omero.group': str(omero_group)}) else: prx = sf.submit(request) assert State.FAILURE not in prx.getStatus().flags cb = CmdCallbackI(client, prx) cb.loop(20, 500) assert prx.getResponse() is not None rsp = prx.getResponse() if test_should_pass: if isinstance(rsp, ERR): assert False, ( "Found ERR when test_should_pass==true: %s (%s) params=%s" % (rsp.category, rsp.name, rsp.parameters)) assert State.FAILURE not in prx.getStatus().flags else: if isinstance(rsp, OK): assert False, ("Found OK when test_should_pass==false: %s" % rsp) assert State.FAILURE in prx.getStatus().flags return rsp
def doChange(self, group_id, permissions, test_should_pass=True, return_complete=True): """ Performs the chmod action, waits on completion and checks that the result is not an error. """ prx = self.gateway.chmodGroup(group_id, permissions) if not return_complete: return prx cb = CmdCallbackI(self.gateway.c, prx) cb.loop(20, 500) # This fails (see #8439). Can comment out this line and # try a different way of waiting for result - This never completes... import time rsp = prx.getResponse() i = 0 while (rsp is None): time.sleep(10) rsp = prx.getResponse() i += 1 print "rsp", i, rsp self.assertNotEqual(rsp, None) status = prx.getStatus() if test_should_pass: if isinstance(rsp, ERR): self.fail( "Found ERR when test_should_pass==true: %s (%s) params=%s" % (rsp.category, rsp.name, rsp.parameters)) self.assertFalse(State.FAILURE in prx.getStatus().flags) else: if isinstance(rsp, OK): self.fail("Found OK when test_should_pass==false: %s", rsp) self.assertTrue(State.FAILURE in prx.getStatus().flags) return rsp
def doChange(gateway, obj_type, obj_ids, group_id, container_id=None, test_should_pass=True, return_complete=True): """ Performs the change-group action, waits on completion and checks that the result is not an error. """ prx = gateway.chgrpObjects(obj_type, obj_ids, group_id, container_id) if not return_complete: return prx cb = CmdCallbackI(gateway.c, prx) try: for i in range(10): cb.loop(20, 500) if prx.getResponse() != None: break assert prx.getResponse() is not None status = prx.getStatus() rsp = prx.getResponse() if test_should_pass: assert not isinstance(rsp, ERR),\ "Found ERR when test_should_pass==true: %s (%s) params=%s" \ % (rsp.category, rsp.name, rsp.parameters) assert State.FAILURE not in prx.getStatus().flags else: assert not isinstance(rsp, OK),\ "Found OK when test_should_pass==false: %s" % rsp assert State.FAILURE in prx.getStatus().flags return rsp finally: cb.close(True)
def doSubmit(self, request, client, test_should_pass=True, omero_group=None): """ Performs the request(s), waits on completion and checks that the result is not an error. The request can either be a single command or a list of commands. If the latter then the request list will be wrapped in a DoAll. """ if isinstance(request, list): request = DoAll(request) sf = client.sf if omero_group is not None: prx = sf.submit(request, {"omero.group": str(omero_group)}) else: prx = sf.submit(request) assert State.FAILURE not in prx.getStatus().flags cb = CmdCallbackI(client, prx) cb.loop(20, 500) assert prx.getResponse() is not None rsp = prx.getResponse() if test_should_pass: if isinstance(rsp, ERR): assert False, "Found ERR when test_should_pass==true: %s (%s) params=%s" % ( rsp.category, rsp.name, rsp.parameters, ) assert State.FAILURE not in prx.getStatus().flags else: if isinstance(rsp, OK): assert False, "Found OK when test_should_pass==false: %s" % rsp assert State.FAILURE in prx.getStatus().flags return rsp
def assert_import(client, proc, files, wait): """Wait and check that we imported an image.""" hashes = upload_files(proc, files, client) print('Hashes:\n %s' % '\n '.join(hashes)) handle = proc.verifyUpload(hashes) cb = CmdCallbackI(client, handle) # https://github.com/openmicroscopy/openmicroscopy/blob/v5.4.9/components/blitz/src/ome/formats/importer/ImportLibrary.java#L631 if wait == 0: cb.close(False) return None if wait < 0: while not cb.block(2000): sys.stdout.write('.') sys.stdout.flush() sys.stdout.write('\n') else: cb.loop(wait, 1000) rsp = cb.getResponse() if isinstance(rsp, omero.cmd.ERR): raise Exception(rsp) assert len(rsp.pixels) > 0 return rsp