예제 #1
0
def rest_download_refts_resource_bag(request, shortkey, *args, **kwargs):
    tempdir = None
    _, authorized, _ = authorize(
        request,
        shortkey,
        needed_permission=ACTION_TO_AUTHORIZE.VIEW_RESOURCE,
        raises_exception=True)
    try:

        path = "bags/" + str(shortkey) + ".zip"
        response_irods = download_bag_from_irods(request,
                                                 path,
                                                 rest_call=True,
                                                 use_async=False)

        if not response_irods.streaming:
            raise Exception("Failed to stream RefTS bag")
        else:
            tempdir = tempfile.mkdtemp()
            response = assemble_refts_bag(shortkey,
                                          response_irods.streaming_content,
                                          temp_dir=tempdir)
            return response

    except Exception as e:
        logger.exception("rest_download_refts_resource_bag: %s" % (e.message))
        response = HttpResponse(status=503)
        response.content = "Failed to download this resource!"
        return response
    finally:
        if tempdir is not None:
            shutil.rmtree(tempdir)
예제 #2
0
def download_refts_resource_bag(request, shortkey, *args, **kwargs):
    tempdir = None
    try:
        _, authorized, _ = authorize(
            request,
            shortkey,
            needed_permission=ACTION_TO_AUTHORIZE.VIEW_RESOURCE,
            raises_exception=False)
        if not authorized:
            response = HttpResponse(status=401)
            response.content = "<h3>You do not have permission to download this resource!</h3>"
            return response

        path = "bags/" + str(shortkey) + ".zip"
        response_irods = download_bag_from_irods(request,
                                                 path,
                                                 use_async=False,
                                                 use_reverse_proxy=False)

        tempdir = tempfile.mkdtemp()
        response = assemble_refts_bag(shortkey,
                                      response_irods.streaming_content,
                                      temp_dir=tempdir)

        return response
    except Exception as e:
        logger.exception("download_refts_resource_bag: %s" % (str(e)))
        response = HttpResponse(status=503)
        response.content = "<h3>Failed to download this resource!</h3>"
        return response
    finally:
        if tempdir is not None:
            shutil.rmtree(tempdir)