def user_file_exists()

in airavata_django_portal_sdk/user_storage/api.py [0:0]


def user_file_exists(request, path, storage_resource_id=None, experiment_id=None):
    """
    If file exists, return data product URI, else None. If `experiment_id`
    provided then the path will be relative to the experiment data directory.
    """
    if remoteapi.is_remote_api_configured():
        resp = remoteapi.call(request,
                              "/user-storage/~/{path}",
                              path_params={"path": path},
                              params={"experiment-id": experiment_id},
                              raise_for_status=False)
        if resp.status_code == HTTPStatus.NOT_FOUND:
            return None
        resp.raise_for_status()
        if resp.json()['isDir']:
            return None
        else:
            return resp.json()['files'][0]['dataProductURI']
    final_path, owner_username = _get_final_path_and_owner_username(request, path, experiment_id)
    backend = get_user_storage_provider(
        request, storage_resource_id=storage_resource_id, owner_username=owner_username)
    if backend.is_file(final_path):
        _, files = backend.get_metadata(final_path)
        full_path = files[0]['resource_path']
        data_product_uri = _get_data_product_uri(request, full_path,
                                                 backend.resource_id, owner=owner_username)
        return data_product_uri
    else:
        return None