Beispiel #1
0
def aip_file_download(request, uuid):
    # get file basename
    file = models.File.objects.get(uuid=uuid)
    file_basename = os.path.basename(file.currentlocation)

    # get file's AIP's properties
    sipuuid = helpers.get_file_sip_uuid(uuid)
    aip = elasticSearchFunctions.connect_and_get_aip_data(sipuuid)
    aip_filepath = aip.filePath

    # create temp dir to extract to
    temp_dir = tempfile.mkdtemp()

    # work out path components
    aip_archive_filename = os.path.basename(aip_filepath)
    subdir = os.path.splitext(aip_archive_filename)[0]
    path_to_file_within_aip_data_dir \
      = os.path.dirname(file.originallocation.replace('%transferDirectory%', ''))

    file_relative_path = os.path.join(subdir, 'data',
                                      path_to_file_within_aip_data_dir,
                                      file_basename)

    #return HttpResponse('7za e -o' + temp_dir + ' ' + aip_filepath + ' ' + file_relative_path)

    # extract file from AIP
    command_data = [
        '7za', 'e', '-o' + temp_dir, aip_filepath, file_relative_path
    ]

    subprocess.call(command_data)

    # send extracted file
    extracted_file_path = os.path.join(temp_dir, file_basename)
    return helpers.send_file(request, extracted_file_path)
Beispiel #2
0
def send_thumbnail(request, fileuuid):
    # get AIP location to use to find root of AIP storage
    sipuuid = helpers.get_file_sip_uuid(fileuuid)
    aip = elasticSearchFunctions.connect_and_get_aip_data(sipuuid)
    aip_filepath = aip.filePath

    # strip path to AIP from root of AIP storage
    for index in range(1, 10):
        aip_filepath = os.path.dirname(aip_filepath)

    # derive thumbnail path
    thumbnail_path = os.path.join(
        aip_filepath,
        'thumbnails',
        sipuuid,
        fileuuid + '.jpg'
    )

    # send "blank" thumbnail if one exists:
    # Because thumbnails aren't kept in ElasticSearch they can be queried for,
    # during searches, from multiple dashboard servers.
    # Because ElasticSearch don't know if a thumbnail exists or not, this is
    # a way of not causing visual disruption if a thumbnail doesn't exist.
    if not os.path.exists(thumbnail_path):
        thumbnail_path = os.path.join(settings.BASE_PATH, 'media/images/1x1-pixel.png')

    return helpers.send_file(request, thumbnail_path)
Beispiel #3
0
def search_augment_file_results(raw_results):
    modifiedResults = []

    for item in raw_results.hits.hits:
        clone = item.fields.copy()

        # try to find AIP details in database
        try:
            # get AIP data from ElasticSearch
            aip = elasticSearchFunctions.connect_and_get_aip_data(
                clone['AIPUUID'])

            # augment result data
            clone['sipname'] = aip.name
            clone['fileuuid'] = clone['FILEUUID']
            clone['href'] = aip.filePath.replace(AIPSTOREPATH + '/',
                                                 "AIPsStore/")

        except:
            aip = None
            clone['sipname'] = False

        clone['filename'] = os.path.basename(clone['filePath'])
        clone['document_id'] = item['_id']
        clone['document_id_no_hyphens'] = item['_id'].replace('-', '____')

        modifiedResults.append(clone)

    return modifiedResults
Beispiel #4
0
def aip_file_download(request, uuid):
    # get file basename
    file          = models.File.objects.get(uuid=uuid)
    file_basename = os.path.basename(file.currentlocation)

    # get file's AIP's properties
    sipuuid      = helpers.get_file_sip_uuid(uuid)
    aip          = elasticSearchFunctions.connect_and_get_aip_data(sipuuid)
    aip_filepath = aip['fields']['filePath'][0]

    # work out path components
    aip_archive_filename = os.path.basename(aip_filepath)

    # splittext doesn't deal with double extensions, so special-case .tar.bz2
    if aip_archive_filename.endswith('.tar.bz2'):
        subdir = aip_archive_filename[:-8]
    else:
        subdir = os.path.splitext(aip_archive_filename)[0]

    # Strip %Directory% from the path
    path_to_file_within_aip_data_dir = os.path.dirname(file.currentlocation.replace('%transferDirectory%', '').replace('%SIPDirectory%', ''))

    file_relative_path = os.path.join(
      subdir,
      'data',
      path_to_file_within_aip_data_dir,
      file_basename
    )

    redirect_url = storage_service.extract_file_url(aip['fields']['uuid'][0], file_relative_path)
    return HttpResponseRedirect(redirect_url)
Beispiel #5
0
def search_augment_file_results(raw_results):
    modifiedResults = []

    for item in raw_results.hits.hits:
        clone = item.fields.copy()

        # try to find AIP details in database
        try:
            # get AIP data from ElasticSearch
            aip = elasticSearchFunctions.connect_and_get_aip_data(clone['AIPUUID'])

            # augment result data
            clone['sipname'] = aip.name
            clone['fileuuid'] = clone['FILEUUID']
            clone['href'] = aip.filePath.replace(AIPSTOREPATH + '/', "AIPsStore/")

        except:
            aip = None
            clone['sipname'] = False

        clone['filename'] = os.path.basename(clone['filePath'])
        clone['document_id'] = item['_id']
        clone['document_id_no_hyphens'] = item['_id'].replace('-', '____')

        modifiedResults.append(clone)

    return modifiedResults
Beispiel #6
0
def aip_delete(request, uuid):
    try:
        aip = elasticSearchFunctions.connect_and_get_aip_data(uuid)
        aip_filepath = aip['filePath']
        os.remove(aip_filepath)
        elasticSearchFunctions.delete_aip(uuid)
        elasticSearchFunctions.connect_and_delete_aip_files(uuid)
        return HttpResponseRedirect(reverse('components.archival_storage.views.overview'))
    except:
        raise Http404
Beispiel #7
0
def aip_delete(request, uuid):
    try:
        aip = elasticSearchFunctions.connect_and_get_aip_data(uuid)
        aip_filepath = aip['filePath']
        os.remove(aip_filepath)
        elasticSearchFunctions.delete_aip(uuid)
        elasticSearchFunctions.connect_and_delete_aip_files(uuid)
        return HttpResponseRedirect(
            reverse('components.archival_storage.views.overview'))
    except:
        raise Http404
Beispiel #8
0
def aip_file_download(request, uuid):
    # get file basename
    file          = models.File.objects.get(uuid=uuid)
    file_basename = os.path.basename(file.currentlocation)

    # get file's AIP's properties
    sipuuid      = helpers.get_file_sip_uuid(uuid)
    aip          = elasticSearchFunctions.connect_and_get_aip_data(sipuuid)
    aip_filepath = aip.filePath

    # create temp dir to extract to
    temp_dir = tempfile.mkdtemp()

    # work out path components
    aip_archive_filename = os.path.basename(aip_filepath)
    subdir = os.path.splitext(aip_archive_filename)[0]
    path_to_file_within_aip_data_dir \
      = os.path.dirname(file.originallocation.replace('%transferDirectory%', ''))

    file_relative_path = os.path.join(
      subdir,
      'data',
      path_to_file_within_aip_data_dir,
      file_basename
    )

    #return HttpResponse('7za e -o' + temp_dir + ' ' + aip_filepath + ' ' + file_relative_path)

    # extract file from AIP
    command_data = [
        '7za',
        'e',
        '-o' + temp_dir,
        aip_filepath,
        file_relative_path
    ]

    subprocess.call(command_data)

    # send extracted file
    extracted_file_path = os.path.join(temp_dir, file_basename)
    return helpers.send_file(request, extracted_file_path)
Beispiel #9
0
def send_thumbnail(request, fileuuid):
    # get AIP location to use to find root of AIP storage
    sipuuid = helpers.get_file_sip_uuid(fileuuid)
    aip = elasticSearchFunctions.connect_and_get_aip_data(sipuuid)
    aip_filepath = aip.filePath

    # strip path to AIP from root of AIP storage
    for index in range(1, 10):
        aip_filepath = os.path.dirname(aip_filepath)

    # derive thumbnail path
    thumbnail_path = os.path.join(aip_filepath, 'thumbnails', sipuuid,
                                  fileuuid + '.jpg')

    # send "blank" thumbnail if one exists:
    # Because thumbnails aren't kept in ElasticSearch they can be queried for,
    # during searches, from multiple dashboard servers.
    # Because ElasticSearch don't know if a thumbnail exists or not, this is
    # a way of not causing visual disruption if a thumbnail doesn't exist.
    if not os.path.exists(thumbnail_path):
        thumbnail_path = os.path.join(settings.BASE_PATH,
                                      'media/images/1x1-pixel.png')

    return helpers.send_file(request, thumbnail_path)
Beispiel #10
0
def aip_download(request, uuid):
    aip = elasticSearchFunctions.connect_and_get_aip_data(uuid)
    return helpers.send_file_or_return_error_response(request, aip.filePath,
                                                      'AIP')
Beispiel #11
0
def archival_storage_aip_download(request, uuid):
    aip = elasticSearchFunctions.connect_and_get_aip_data(uuid)
    return send_file(request, aip.filePath)
Beispiel #12
0
def aip_download(request, uuid):
    aip = elasticSearchFunctions.connect_and_get_aip_data(uuid)
    return helpers.send_file_or_return_error_response(request, aip.filePath, 'AIP')
Beispiel #13
0
def archival_storage_aip_download(request, uuid):
    aip = elasticSearchFunctions.connect_and_get_aip_data(uuid)
    return send_file(request, aip.filePath)