Exemple #1
0
    def check(self):

        from omero.cli import CLI
        from omero.gateway import BlitzGateway

        cli = CLI()
        cli.loadplugins()
        cli.onecmd('login -q')

        try:
            gateway = BlitzGateway(client_obj=cli.get_client())
            for experiment in self.m["experiments"]:
                self.check_object(gateway, experiment, "Project")
            for experiment in self.m["screens"]:
                self.check_object(gateway, experiment, "Screen")
            if "map" in self.m:
                if self.m["experiments"]:
                    study_type = "Project"
                else:
                    study_type = "Screen"
                self.check_object(gateway, self.m, study_type)
        finally:
            if cli:
                cli.close()
            gateway.close()
Exemple #2
0
def as_stdout(path, readers="", extra_args=None):
    """Returns the import candidates for the given path.

    you can pass more arguments to the `import` command through the
    extra_args argument in the form of a list.

    ..code ::

    >>> as_stdout("/my/dir/with_tifs", extra_args=["--depth", "6"])

    """
    if extra_args is None:
        extra_args = []
    path = _to_list(path)
    readers = str(readers)
    cli = CLI()
    cli.loadplugins()
    if readers:
        cli.invoke(["import", "-l"] + [
            readers,
        ] + extra_args + ["-f"] + path)
    else:
        cli.invoke(["import"] + extra_args + ["-f"] + path)
    if cli.rv != 0:
        raise omero.InternalException(
            None, None, "'import -f' exited with a rc=%s. "
            "See console for more information" % cli.rv)
Exemple #3
0
def main():
    parser = Parser()
    parser.add_login_arguments()
    parser.add_argument("--orphans", action="store_true")
    parser.add_argument("--unknown", action="store_true")
    parser.add_argument("--search", action="store_true")
    parser.add_argument("--images", action="store_true")
    parser.add_argument("--copy-from", type=long, default=None)
    parser.add_argument("--copy-type", default="Image")
    parser.add_argument("--copy-to", type=long, default=None)
    parser.add_argument("screen", nargs="?")
    ns = parser.parse_args()

    cli = CLI()
    cli.loadplugins()
    client = cli.conn(ns)
    try:
        query = client.sf.getQueryService()
        if ns.orphans:
            orphans(query)
        elif ns.unknown:
            unknown(query)
        elif ns.search:
            search = client.sf.createSearchService()
            check_search(query, search)
        elif not ns.screen:
            stat_screens(query)
        else:
            if ns.copy_to:
                copy(client, ns.copy_from, ns.copy_type, ns.copy_to)
            else:
                for x in stat_plates(query, ns.screen, ns.images):
                    print x
    finally:
        cli.close()
def check(obj):

    from omero.cli import CLI
    from omero.gateway import BlitzGateway

    cli = CLI()
    cli.loadplugins()
    cli.onecmd('login')

    try:
        gateway = BlitzGateway(client_obj=cli.get_client())
        remote_obj = gateway.getObject(
                obj.type, attributes={"name": obj.name})
        errors = []
        if remote_obj.description != obj.description:
            errors.append("current:%s\nexpected:%s" % (
                remote_obj.description, obj.description))
        for al in remote_obj._getAnnotationLinks(
                ns="openmicroscopy.org/omero/client/mapAnnotation"):
            mapValue = al.child.mapValue
            kv_pairs = [(m.name, m.value) for m in mapValue]
            for i in range(len(kv_pairs)):
                if kv_pairs[i] != obj.map[i]:
                    errors.append(
                        "current:%s\nexpected:%s" % (kv_pairs[i], obj.map[i]))
        if not errors:
            log.info("No annotations mismatch detected")
        else:
            for e in errors:
                log.info("Found some annotations mismatch")
                print e
    finally:
        if cli:
            cli.close()
        gateway.close()
Exemple #5
0
    def check(self):

        from omero.cli import CLI
        from omero.gateway import BlitzGateway

        cli = CLI()
        cli.loadplugins()
        cli.onecmd('login -q')

        try:
            gateway = BlitzGateway(client_obj=cli.get_client())
            for experiment in self.m["experiments"]:
                self.check_object(gateway, experiment, "Project")
            for experiment in self.m["screens"]:
                self.check_object(gateway, experiment, "Screen")
            if "map" in self.m:
                if self.m["experiments"]:
                    study_type = "Project"
                else:
                    study_type = "Screen"
                self.check_object(gateway, self.m, study_type)
        finally:
            if cli:
                cli.close()
            gateway.close()
Exemple #6
0
def main():
    parser = Parser()
    parser.add_login_arguments()
    parser.add_argument("--orphans", action="store_true")
    parser.add_argument("--unknown", action="store_true")
    parser.add_argument("--search", action="store_true")
    parser.add_argument("--images", action="store_true")
    parser.add_argument("--copy-from", type=long, default=None)
    parser.add_argument("--copy-type", default="Image")
    parser.add_argument("--copy-to", type=long, default=None)
    parser.add_argument("screen", nargs="?")
    ns = parser.parse_args()

    cli = CLI()
    cli.loadplugins()
    client = cli.conn(ns)
    try:
        query = client.sf.getQueryService()
        if ns.orphans:
            orphans(query)
        elif ns.unknown:
            unknown(query)
        elif ns.search:
            search = client.sf.createSearchService()
            check_search(query, search)
        elif not ns.screen:
            stat_screens(query)
        else:
            if ns.copy_to:
                copy(client, ns.copy_from, ns.copy_type, ns.copy_to)
            else:
                for x in stat_plates(query, ns.screen, ns.images):
                    print x
    finally:
        cli.close()
Exemple #7
0
 class T(Thread):
     def run(self, *args):
         pause = random.random()
         event.wait(pause)
         self.cli = CLI()
         self.cli.loadplugins()
         self.con = self.cli.controls["admin"]
         self.cmp = self.con.ctx
Exemple #8
0
 class T(Thread):
     def run(self, *args):
         pause = random.random()
         event.wait(pause)
         self.cli = CLI()
         self.cli.loadplugins()
         self.con = self.cli.controls["admin"]
         self.cmp = self.con.ctx
Exemple #9
0
def main():
    parser = Parser()
    parser.add_login_arguments()
    parser.add_argument("--orphans", action="store_true")
    parser.add_argument("--unknown", action="store_true")
    parser.add_argument("--search", action="store_true")
    parser.add_argument("--images", action="store_true")
    parser.add_argument("--release",
                        default="TODO",
                        help="The name of the release, e.g. 'prod88'")
    parser.add_argument(
        "--disable-fsusage",
        action="store_true",
        help=("Disable fs usage file size and counts. "
              "Use this flag if the script is taking too long."))
    parser.add_argument(
        "--format",
        default="tsv",
        help=(
            "Output format, includes 'string', 'csv', 'tsv' (default), and "
            "'json'. "
            "'tsv' can be appended to the IDR studies.csv file with no further "
            "processing. "
            "All other formats include headers and totals. "
            "'string' is the most human readable (fixed width columns). "))
    parser.add_argument("studies",
                        nargs='*',
                        help="Studies to be processed, default all (idr*)")
    parser.add_argument('-v', '--verbose', action='count', default=0)
    ns = parser.parse_args()

    levels = [logging.WARNING, logging.INFO, logging.DEBUG]
    level = levels[min(len(levels) - 1, ns.verbose)]
    logging.basicConfig(level=level,
                        format="%(asctime)s %(levelname)s %(message)s")

    cli = CLI()
    cli.loadplugins()
    client = cli.conn(ns)
    try:
        query = client.sf.getQueryService()
        if ns.orphans:
            orphans(query)
        elif ns.unknown:
            unknown(query, ns.studies)
        elif ns.search:
            search = client.sf.createSearchService()
            check_search(query, search)
        else:
            df = stat_top_level(client,
                                ns.studies,
                                release=ns.release,
                                fsusage=(not ns.disable_fsusage),
                                append_totals=(ns.format != 'tsv'))
            print_stats(df, ns.format)
    finally:
        cli.close()
def as_stdout(path, readers=""):
        path = _to_list(path)
        readers = str(readers)
        cli = CLI()
        cli.loadplugins()
        if readers:
            cli.invoke(["import", "-l", readers, "-f"]+path)
        else:
            cli.invoke(["import", "-f"]+path)
        if cli.rv != 0:
            raise omero.InternalException(None, None, "'import -f' exited with a rc=%s. See console for more information" % cli.rv)
Exemple #11
0
 def test_client_nologin(self, connstr):
     c = CLI()
     c.loadplugins()
     with pytest.raises(Exception) as exc:
         c = omero.client(connstr)
         c.createSession('root', 'omero')
     assert issubclass(exc.type, (
         Ice.ConnectionRefusedException,
         Ice.ConnectionLostException,
         Ice.ProtocolException,
     ))
Exemple #12
0
def as_stdout(path, readers=""):
    path = _to_list(path)
    readers = str(readers)
    cli = CLI()
    cli.loadplugins()
    if readers:
        cli.invoke(["import", "-l", readers, "-f"] + path)
    else:
        cli.invoke(["import", "-f"] + path)
    if cli.rv != 0:
        raise omero.InternalException(
            None, None, "'import -f' exited with a rc=%s. "
            "See console for more information" % cli.rv)
Exemple #13
0
def main():
    parser = Parser()
    parser.add_login_arguments()
    parser.add_argument("file")
    parser.add_argument("object")
    ns = parser.parse_args()

    cli = CLI()
    cli.loadplugins()
    client = cli.conn(ns)
    try:
        screen_metadata(client, ns.file, ns.object)
    finally:
        cli.close()
Exemple #14
0
def main():
    parser = Parser()
    parser.add_login_arguments()
    parser.add_argument("file")
    parser.add_argument("object")
    ns = parser.parse_args()

    cli = CLI()
    cli.loadplugins()
    client = cli.conn(ns)
    try:
        screen_metadata(client, ns.file, ns.object)
    finally:
        cli.close()
Exemple #15
0
    def check(self, update=False):

        from omero.cli import CLI
        from omero.gateway import BlitzGateway

        cli = CLI()
        cli.loadplugins()
        cli.onecmd('login -q')

        try:
            gateway = BlitzGateway(client_obj=cli.get_client())
            self.check_study(gateway, update=update)
        finally:
            if cli:
                cli.close()
            gateway.close()
class External(object):
    """
    Manages the execution of shell and OMERO CLI commands
    """
    def __init__(self, dir):
        """
        :param dir: The server directory, can be None if you are not
                    interacting with OMERO
        """
        self.cli = None
        self.dir = None
        if dir:
            self.dir = os.path.abspath(dir)
        self.cli = CLI()
        self.cli.loadplugins()

    def get_config(self, raise_missing=True):
        """
        Returns a dictionary of all OMERO config properties
        """
        configxml = os.path.join(self.dir, 'etc', 'grid', 'config.xml')
        try:
            configobj = ConfigXml(configxml, read_only=True)
        except Exception as e:
            log.warning('config.xml not found: %s', e)
            if raise_missing:
                raise
            return {}
        cfgdict = configobj.as_map()
        configobj.close()
        return cfgdict

    def update_config(self, newcfg):
        cfg = ConfigXml(os.path.join(self.dir, 'etc', 'grid', 'config.xml'))
        for k, v in newcfg.items():
            cfg[k] = v
        cfg.close()

    def omero_cli(self, command):
        """
        Runs an OMERO CLI command
        """
        assert isinstance(command, list)
        log.info('Running omero: %s', ' '.join(command))
        return self.cli.invoke(command)
Exemple #17
0
def perform_import(conf, transfer="ln_s"):

    # see https://docs.openmicroscopy.org/omero/5.6.2/users/cli/sessions.html

    cmd = [
        "import",
        "-s",
        conf["server"],
        "-p",
        conf["port"],
        "--sudo",
        "root",
        "-w",
        conf["admin_passwd"],
        "-u",
        conf["username"],
        "--exclude",
        "clientpath",
        "--file",
        Path(conf["out_file"]).absolute().as_posix(),
        "--output",
        "yaml",
        "--errs",
        Path("err.txt").absolute().as_posix(),
        "--bulk",
        conf["bulk_yml"],
    ]
    if conf["group"]:
        cmd.extend(["-g", conf["group"]])

    if transfer:
        cmd.extend(["--transfer", transfer])

    cli = CLI()
    cli.loadplugins()
    pwd_idx = cmd.index(conf["admin_passwd"])
    cmd_str = cmd.copy()
    cmd_str[pwd_idx] = "XXX"
    log.info("Invoking omero %s", " ".join(cmd_str))
    cli.invoke(cmd)
def run(studyfile, targetstr):
    try:
        # `omero shell --login` automatically creates the client object
        session = client.getSession()
        cli = None
    except NameError:
        cli = CLI()
        cli.loadplugins()
        cli.onecmd('login')
        session = cli.get_client().getSession()

    try:
        us = session.getUpdateService()

        target = ProxyStringType()(targetstr)
        with open(studyfile) as f:
            rowkvs = get_pairs(f)
        links = create_map_annotation([target], rowkvs, ns)
        ids = us.saveAndReturnIds(links)
        print 'Created MapAnnotation links: %s' % ids
    finally:
        if cli:
            cli.close()
    for ds in project.listChildren():
        for img in ds.listChildren():
            channels = img.getChannels(noRE=True)
            lc = channels[channel_index].getLogicalChannel()
            lc.setName(channel_name)
            lc.save()


if len(sys.argv) < 4:
    printusage()
else:
    channel_index = int(sys.argv[1])
    channel_name = sys.argv[2]
    target = sys.argv[3].split(':')
    if target[0] == 'Project':
        project_id = int(target[1])
    else:
        printusage()

cli = CLI()
cli.loadplugins()
cli.onecmd('login -q')

try:
    conn = BlitzGateway(client_obj=cli.get_client())
    rename(conn, project_id, channel_index, channel_name)
finally:
    if cli:
        cli.close()
        conn.close()
Exemple #20
0
def hrm_to_omero(conn, id_str, image_file):
    """Upload an image into a specific dataset in OMERO.

    In case we know from the suffix that a given file format is not supported
    by OMERO, the upload will not be initiated at all (e.g. for SVI-HDF5,
    having the suffix '.h5').

    The import itself is done by instantiating the CLI class, assembling the
    required arguments, and finally running cli.invoke(). This eventually
    triggers the importer() method defined in OMERO's Python bindings in
    <OMERO.server/lib/python/omero/plugins/import.py>, respectively (source)
    <openmicroscopy.git/components/tools/OmeroPy/src/omero/plugins/import.py>.

    Parameters
    ==========
    id_str: str - the ID of the target dataset in OMERO (e.g. "G:7:Dataset:23")
    image_file: str - the local image file including the full path

    Returns
    =======
    True in case of success, False otherwise.
    """
    if image_file.lower().endswith(('.h5', '.hdf5')):
        print 'ERROR: HDF5 files are not supported by OMERO!'
        return False
    # TODO I: group switching required!!
    _, gid, obj_type, dset_id = id_str.split(':')
    # we have to create the annotations *before* we actually upload the image
    # data itself and link them to the image during the upload - the other way
    # round is not possible right now as the CLI wrapper (see below) doesn't
    # expose the ID of the newly created object in OMERO (confirmed by J-M and
    # Sebastien on the 2015 OME Meeting):
    namespace = 'deconvolved.hrm'
    #### mime = 'text/plain'
    # extract the image basename without suffix:
    # TODO: is it [0-9a-f] or really [0-9a-z] as in the original PHP code?
    basename = re.sub(r'(_[0-9a-f]{13}_hrm)\..*', r'\1', image_file)
    comment = gen_parameter_summary(basename + '.parameters.txt')
    #### annotations = []
    #### # TODO: the list of suffixes should not be hardcoded here!
    #### for suffix in ['.hgsb', '.log.txt', '.parameters.txt']:
    ####     if not os.path.exists(basename + suffix):
    ####         continue
    ####     ann = conn.createFileAnnfromLocalFile(
    ####         basename + suffix, mimetype=mime, ns=namespace, desc=None)
    ####     annotations.append(ann.getId())
    # currently there is no direct "Python way" to import data into OMERO, so
    # we have to use the CLI wrapper for this:
    from omero.cli import CLI
    cli = CLI()
    cli.loadplugins()
    # NOTE: cli._client should be replaced with cli.set_client() when switching
    # to support for OMERO 5.1 and later only:
    cli._client = conn.c
    import_args = ["import"]
    import_args.extend(['-d', dset_id])
    if comment is not None:
        import_args.extend(['--annotation_ns', namespace])
        import_args.extend(['--annotation_text', comment])
    #### for ann_id in annotations:
    ####     import_args.extend(['--annotation_link', str(ann_id)])
    import_args.append(image_file)
    # print("import_args: " + str(import_args))
    try:
        cli.invoke(import_args, strict=True)
    except:
        print('ERROR: uploading "%s" to %s failed!' % (image_file, id_str))
        # print(import_args)
        return False
    return True
Exemple #21
0
 def test_cli_nologin(self, connstr):
     c = CLI()
     c.loadplugins()
     with pytest.raises(omero.cli.NonZeroReturnCode):
         c.invoke('login -q -C {} -u root -w omero'.format(connstr),
                  strict=True)
Exemple #22
0
 def test_cli_login(self, connstr):
     c = CLI()
     c.loadplugins()
     c.invoke('login -q -C {} -u root -w omero'.format(connstr),
              strict=True)
     c.invoke('logout', strict=True)
Exemple #23
0
    def status(self, args):
        self.ctx.invoke(["admin", "status", args.name])

    def stop(self, args):
        if self._isWindows():
            try:
                command = ["icegridnode", "--stop", "OMERO."+args.name]
                self.ctx.call(command)
                command = ["icegridnode", "--uninstall", "OMERO."+args.name]
                self.ctx.call(command)
            except NonZeroReturnCode, nzrc:
                self._handleNZRC(nzrc)
        else:
                pid = open(self._pid(), "r").readline()
                os.kill(int(pid), signal.SIGTERM)
                # command = ["icegridadmin"] + [self._intcfg()] + ["-c", "node
                # shutdown %s" % args.name]
                # self.ctx.call(command)

    def kill(self, args):
        pid = open(self._pid(), "r").readline()
        os.kill(int(pid), signal.SIGKILL)

try:
    register("node", NodeControl, HELP)
except NameError:
    if __name__ == "__main__":
        cli = CLI()
        cli.loadplugins()
        cli.invoke(sys.argv[1:])
Exemple #24
0
def hrm_to_omero(conn, id_str, image_file):
    """Upload an image into a specific dataset in OMERO.

    In case we know from the suffix that a given file format is not supported
    by OMERO, the upload will not be initiated at all (e.g. for SVI-HDF5,
    having the suffix '.h5').

    The import itself is done by instantiating the CLI class, assembling the
    required arguments, and finally running cli.invoke(). This eventually
    triggers the importer() method defined in OMERO's Python bindings in
    <OMERO.server/lib/python/omero/plugins/import.py>, respectively (source)
    <openmicroscopy.git/components/tools/OmeroPy/src/omero/plugins/import.py>.

    Parameters
    ==========
    id_str: str - the ID of the target dataset in OMERO (e.g. "G:7:Dataset:23")
    image_file: str - the local image file including the full path

    Returns
    =======
    True in case of success, False otherwise.
    """
    if image_file.lower().endswith(('.h5', '.hdf5')):
        print 'ERROR: HDF5 files are not supported by OMERO!'
        return False
    # TODO I: group switching required!!
    _, gid, obj_type, dset_id = id_str.split(':')
    # we have to create the annotations *before* we actually upload the image
    # data itself and link them to the image during the upload - the other way
    # round is not possible right now as the CLI wrapper (see below) doesn't
    # expose the ID of the newly created object in OMERO (confirmed by J-M and
    # Sebastien on the 2015 OME Meeting):
    namespace = 'deconvolved.hrm'
    #### mime = 'text/plain'
    # extract the image basename without suffix:
    # TODO: is it [0-9a-f] or really [0-9a-z] as in the original PHP code?
    basename = re.sub(r'(_[0-9a-f]{13}_hrm)\..*', r'\1', image_file)
    comment = gen_parameter_summary(basename + '.parameters.txt')
    #### annotations = []
    #### # TODO: the list of suffixes should not be hardcoded here!
    #### for suffix in ['.hgsb', '.log.txt', '.parameters.txt']:
    ####     if not os.path.exists(basename + suffix):
    ####         continue
    ####     ann = conn.createFileAnnfromLocalFile(
    ####         basename + suffix, mimetype=mime, ns=namespace, desc=None)
    ####     annotations.append(ann.getId())
    # currently there is no direct "Python way" to import data into OMERO, so
    # we have to use the CLI wrapper for this:
    from omero.cli import CLI
    cli = CLI()
    cli.loadplugins()
    # NOTE: cli._client should be replaced with cli.set_client() when switching
    # to support for OMERO 5.1 and later only:
    cli._client = conn.c
    import_args = ["import"]
    import_args.extend(['-d', dset_id])
    if comment is not None:
        import_args.extend(['--annotation_ns', namespace])
        import_args.extend(['--annotation_text', comment])
    #### for ann_id in annotations:
    ####     import_args.extend(['--annotation_link', str(ann_id)])
    import_args.append(image_file)
    # print("import_args: " + str(import_args))
    try:
        cli.invoke(import_args, strict=True)
    except:
        print('ERROR: uploading "%s" to %s failed!' % (image_file, id_str))
        # print(import_args)
        return False
    return True