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 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 fs_usage(client, objecttype, objectid): req = DiskUsage2() req.targetObjects = {objecttype: [objectid]} cb = None handle = None try: handle = client.sf.submit(req) cb = CmdCallbackI(client, handle) # Wait for finish while True: found = cb.block(1000) if found: break rsp = cb.getResponse() # status = cb.getStatus() except KeyboardInterrupt: # If user uses Ctrl-C, then cancel if handle is not None: logging.warning("Attempting cancel...") if handle.cancel(): logging.warning("Cancelled") else: logging.warning("Failed to cancel") finally: if cb is not None: cb.close(True) # Close handle sizebytes = sum(rsp.totalBytesUsed.values()) nfiles = sum(rsp.totalFileCount.values()) return sizebytes, nfiles
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 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