def connect_to_remote(password, username): c = omero.client(host=OMERO_SERVER, port=OMERO_PORT, args=["--Ice.Config=/dev/null", "--omero.debug=1"]) c.createSession(username, password) remote_conn = BlitzGateway(client_obj=c) cli = omero.cli.CLI() cli.loadplugins() cli.set_client(c) # del os.environ["ICE_CONFIG"] return c, cli, remote_conn
def cliImport(client, ipath, destID, skip, depth, namespace, dataset=None, conn=None): # create import call string args = createArgumentList(ipath, destID, skip, depth) images_skipped = None images_imported = None try: with tempfile.NamedTemporaryFile(suffix=".stdout") as stdout: with tempfile.NamedTemporaryFile(suffix=".stderr") as stderr: cli = omero.cli.CLI() cli.loadplugins() #cli.set_client(client) cli.set_client(client.createClient(secure=True)) args.extend(["--file", stdout.name]) args.extend(["--errs", stderr.name]) cli.invoke(args) images_skipped, images_imported = parseLogFile(stderr) print("Images imported: ", len(images_imported)) print("Images skipped: ", len(images_skipped)) if dataset: #append log file #link reportFile to object ann = conn.createFileAnnfromLocalFile(stderr.name, mimetype="text/csv", ns=namespace + "_log") dataset.linkAnnotation(ann) return images_skipped, images_imported, stderr except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() print('ERROR at cli import: %s\n %s %s' % (str(e), exc_type, exc_tb.tb_lineno)) return None, None, None finally: return images_skipped, images_imported, None
# Connect to remote omero c = omero.client(host=host, port=port, args=["--Ice.Config=/dev/null", "--omero.debug=1"]) c.joinSession(sessionUuid) try: # Just to test connection, print the projects. remote_conn = BlitzGateway(client_obj=c) for p in remote_conn.getObjects("Project"): print p.id, p.name print "Connected to ", REMOTE_HOST, ", now to transfer image" cli = omero.cli.CLI() cli.loadplugins() cli.set_client(c) del os.environ["ICE_CONFIG"] # Find image files uploaded_image_ids = [] for image_id in ids: image = local_conn.getObject("Image", image_id) print image.getName() temp_file = NamedTemporaryFile().name try: # TODO haven't tested an image with multiple files. for f in image.getImportedImageFiles(): file_loc = os.path.join(managed_dir, f.path, f.name) print "file location is: ", file_loc with open(temp_file, 'wr') as f, stdout_redirected(f):