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 deleteRoi(self, roi_id): """ Delete the given ROI :param roi: an ROI object :type roi: `omero.model.Roi` """ from omero.callbacks import CmdCallbackI # @UnresolvedImport handle = self.conn.deleteObjects("Roi", [roi_id], deleteAnns=True, deleteChildren=True) callback = CmdCallbackI(self.conn.c, handle) while not callback.block(500): if self.args.verbose: print_date(".", newline=False, incl_date=False) time.sleep(2) callback.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