Beispiel #1
0
    def parse_pid_dataobject_path(self, metadata, key='URL'):
        """ Parse url / irods path """

        url = metadata.get(key)
        if url is None:
            return url

        # NOTE: this would only work until the protocol is unchanged
        url = url.replace('irods://', '')

        # path_pieces = url.split(path.os.sep)[1:]
        path_pieces = url.split(path.os.sep)
        path_pieces[0] = path.os.sep

        # TEMPORARY FIX, waiting to decide final PID structure
        try:
            if path_pieces[3] == 'api' and path_pieces[4] == 'registered':
                path_pieces[0] = "/"
                path_pieces[1] = "/"
                path_pieces[2] = "/"
                path_pieces[3] = "/"
                path_pieces[4] = "/"

        except BaseException:
            log.error("Error parsing URL, not enough tokens? %s", path_pieces)

        # print("pieces", path_pieces)
        ipath = str(path.build(path_pieces))
        log.verbose("Data object: %s", ipath)

        return ipath
Beispiel #2
0
    def connect_client(self, force_no_credentials=False, disable_logs=False):

        if getattr(self, '_handle_client', None) is None:

            if disable_logs:
                import logging
                logging.getLogger('b2handle').setLevel(logging.WARNING)

            # With credentials
            if force_no_credentials:
                self._handle_client = b2handle.instantiate_for_read_access()
                log.debug("HANDLE client connected [w/out credentials]")
            else:
                found = False
                file = os.environ.get('HANDLE_CREDENTIALS', None)
                if file is not None:
                    from utilities import path
                    credentials_path = path.build(file)
                    found = path.file_exists_and_nonzero(credentials_path)
                    if not found:
                        log.warning("B2HANDLE credentials file not found %s",
                                    file)

                if found:
                    self._handle_client = \
                        b2handle.instantiate_with_credentials(
                            credentials.load_from_JSON(file)
                        )
                    log.debug("HANDLE client connected [w/ credentials]")
                    return self._handle_client, True

        return self._handle_client, False
Beispiel #3
0
    def get_ingestion_path_on_host(self, batch_id):
        '''
        Return the path where the data is located
        on the Rancher host.

        The parts of the path can be configured,
        see: RESOURCES_LOCALPATH=/usr/share
        see: SEADATA_WORKSPACE_INGESTION=ingestion

        Example: /usr/share/ingestion/<batch_id>
        '''
        paths = [self._handle._localpath]  # "/usr/share" (default)
        paths.append(INGESTION_DIR)  # "batches"  (default)
        paths.append(batch_id)
        return str(path.build(paths))
Beispiel #4
0
    def get_irods_path(self, irods_client, mypath, suffix=None):
        '''
        Helper to construct a path of a data object
        inside irods.

        Note: Helper, only used inside this file.
        Note: The irods_client is of class
        IrodsPythonClient, defined in module
        rapydo/http-api/restapi/flask_ext/flask_irods/client
        '''
        paths = [mypath]
        if suffix is not None:
            paths.append(suffix)
        from utilities import path
        suffix_path = str(path.build(paths))
        return irods_client.get_current_zone(suffix=suffix_path)
Beispiel #5
0
    def get_ingestion_path_in_container(self):
        '''
        Return the path where the data is located
        mounted inside the Rancher containers.

        The start of the path can be configured,
        see: RESOURCES_LOCALPATH=/usr/local
        The directory name is fixed.

        Note: The batch_id is not part of the path,
        as every container only works on one batch
        anyway. With every batch being mounted into
        the same path, the programs inside the container
        can easily operate on whichever data is inside
        that directory.

        Example: /usr/share/batch/
        '''
        paths = [FS_PATH_IN_CONTAINER]  # "/usr/share/batch" (hard-coded)
        return str(path.build(paths))
Beispiel #6
0
    def connect_client(self, force_no_credentials=False):

        found = False

        # With credentials
        if not force_no_credentials:
            file = os.environ.get('HANDLE_CREDENTIALS', None)
            if file is not None:
                from utilities import path
                credentials_path = path.build(file)
                found = path.file_exists_and_nonzero(credentials_path)
                if not found:
                    log.warning("B2HANDLE credentials file not found %s", file)

            if found:
                client = b2handle.instantiate_with_credentials(
                    credentials.load_from_JSON(file))
                log.info("PID client connected: w/ credentials")
                return client, True

        client = b2handle.instantiate_for_read_access()
        log.warning("PID client connected: NO credentials")
        return client, False
Beispiel #7
0
 def join_paths(self, paths):
     return str(path.build(paths))
Beispiel #8
0
    def get_batch_path(self, icom, batch_id):

        from utilities import path
        suffix_path = str(path.build(['batchs', batch_id]))
        return icom.get_current_zone(suffix=suffix_path)