Exemple #1
0
    def do_import(self, project_name, dataset_name, ext, image_dir, image_num):
        image_files = []
        p_id = -1
        d_id = -1

        if os.path.isfile(image_dir):  # target = file
            image_files.append(image_dir)
        elif os.path.isdir(image_dir):  # target = dir
            search_command = '*' + ext
            image_files = glob.glob(os.path.join(image_dir, search_command))
        else:
            print "Cannot find file or dir:", image_dir
            return -1

        if len(image_files) != int(image_num):
            raise Exception(
                "Number of images does not match: %s <> %s in %s" %
                (str(len(image_files)), str(int(image_num)), dataset_name))

        image_files.sort()  # ソート
        for image_file in image_files:
            if os.path.isfile(image_file):
                cli = omero.cli.CLI()
                cli.loadplugins()
                cli.invoke([
                    "login", "-s", self.HOST, "-p", self.PORT, "-u", self.USER,
                    "-w", self.PASSWORD, "-C"
                ],
                           strict=True)
                cli.invoke(["sessions", "group", self.GROUP], strict=True)
                try:
                    p_id, d_id = self.create_containers(
                        project_name, dataset_name)
                    title = os.path.basename(image_file)  # OMEROで見えるファイル名
                    cli.invoke(
                        ["import", "-d",
                         str(d_id), "-n", title, image_file],
                        strict=True)
                    print p_id, d_id
                except:
                    print "Import failed for %s : %s" % (image_file, str(
                        cli.rv))

                cli.close()

        return p_id, d_id
Exemple #2
0
def close_remote_connection(c, cli, remote_conn):
    remote_conn.close()
    c.closeSession()
    cli.close()