예제 #1
0
def _get_arrange_directory_tree(backlog_uuid, original_path, arrange_path):
    """ Fetches all the children of original_path from backlog_uuid and creates
    an identical tree in arrange_path.

    Helper function for copy_to_arrange.
    """
    # TODO Use ElasticSearch, since that's where we're getting the original info from now?  Could be easier to get file UUID that way
    ret = []
    browse = storage_service.browse_location(backlog_uuid, original_path)

    # Add everything that is not a directory (ie that is a file)
    entries = [e for e in browse["entries"] if e not in browse["directories"]]
    for entry in entries:
        if entry not in ("processingMCP.xml"):
            path = os.path.join(original_path, entry)
            relative_path = (path.replace(DEFAULT_BACKLOG_PATH, "", 1),)
            try:
                file_info = storage_service.get_file_metadata(
                    relative_path=relative_path
                )[0]
            except storage_service.ResourceNotFound:
                logger.warning(
                    "No file information returned from the Storage Service for file at relative_path: %s",
                    relative_path,
                )
                raise
            file_uuid = file_info["fileuuid"]
            transfer_uuid = file_info["sipuuid"]
            ret.append(
                {
                    "original_path": path,
                    "arrange_path": os.path.join(arrange_path, entry),
                    "file_uuid": file_uuid,
                    "transfer_uuid": transfer_uuid,
                }
            )

    # Add directories and recurse, adding their children too
    for directory in browse["directories"]:
        original_dir = os.path.join(original_path, directory, "")
        arrange_dir = os.path.join(arrange_path, directory, "")
        # Don't fetch metadata or logs dirs
        # TODO only filter if the children of a SIP ie /arrange/sipname/metadata
        if directory not in ("metadata", "logs"):
            ret.append(
                {
                    "original_path": None,
                    "arrange_path": arrange_dir,
                    "file_uuid": None,
                    "transfer_uuid": None,
                }
            )
            ret.extend(
                _get_arrange_directory_tree(backlog_uuid, original_dir, arrange_dir)
            )

    return ret
예제 #2
0
def directory_children_proxy_to_storage_server(request, location_uuid, basePath=False):
    path = ''
    if (basePath):
        path = base64.b64decode(basePath)
    path = path + base64.b64decode(request.GET.get('base_path', ''))
    path = path + base64.b64decode(request.GET.get('path', ''))

    response = storage_service.browse_location(location_uuid, path)
    response = _prepare_browse_response(response)

    return helpers.json_response(response)
예제 #3
0
def directory_children_proxy_to_storage_server(request, location_uuid, basePath=False):
    path = ""
    if basePath:
        path = b64decode_string(basePath)
    path = path + b64decode_string(request.GET.get("base_path", ""))
    path = path + b64decode_string(request.GET.get("path", ""))

    response = storage_service.browse_location(location_uuid, path)
    response = _prepare_browse_response(response)

    return helpers.json_response(response)
예제 #4
0
def _get_arrange_directory_tree(backlog_uuid, original_path, arrange_path):
    """ Fetches all the children of original_path from backlog_uuid and creates
    an identical tree in arrange_path.

    Helper function for copy_to_arrange.
    """
    # TODO Use ElasticSearch, since that's where we're getting the original info from now?  Could be easier to get file UUID that way
    ret = []
    browse = storage_service.browse_location(backlog_uuid, original_path)

    # Add everything that is not a directory (ie that is a file)
    entries = [e for e in browse['entries'] if e not in browse['directories']]
    for entry in entries:
        if entry not in ('processingMCP.xml'):
            path = os.path.join(original_path, entry)
            relative_path = path.replace(DEFAULT_BACKLOG_PATH, '', 1)
            try:
                file_info = storage_service.get_file_metadata(
                    relative_path=relative_path)[0]
            except storage_service.ResourceNotFound:
                logger.warning(
                    'No file information returned from the Storage Service for file at relative_path: %s',
                    relative_path)
                raise
            file_uuid = file_info['fileuuid']
            transfer_uuid = file_info['sipuuid']
            ret.append({
                'original_path': path,
                'arrange_path': os.path.join(arrange_path, entry),
                'file_uuid': file_uuid,
                'transfer_uuid': transfer_uuid
            })

    # Add directories and recurse, adding their children too
    for directory in browse['directories']:
        original_dir = os.path.join(original_path, directory, '')
        arrange_dir = os.path.join(arrange_path, directory, '')
        # Don't fetch metadata or logs dirs
        # TODO only filter if the children of a SIP ie /arrange/sipname/metadata
        if not directory in ('metadata', 'logs'):
            ret.append({
                'original_path': None,
                'arrange_path': arrange_dir,
                'file_uuid': None,
                'transfer_uuid': None
            })
            ret.extend(
                _get_arrange_directory_tree(backlog_uuid, original_dir,
                                            arrange_dir))

    return ret