def archival_storage_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 send_file(request, extracted_file_path)
def archival_storage_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 send_file(request, thumbnail_path)
def transfer_file_download(request, uuid): # get file basename try: file = models.File.objects.get(uuid=uuid) except: raise Http404 file_basename = os.path.basename(file.currentlocation) shared_directory_path = helpers.get_server_config_value('sharedDirectory') transfer = models.Transfer.objects.get(uuid=file.transfer.uuid) path_to_transfer = transfer.currentlocation.replace('%sharedPath%', shared_directory_path) path_to_file = file.currentlocation.replace('%transferDirectory%', path_to_transfer) return send_file(request, path_to_file)
def transfer_file_download(request, uuid): # get file basename try: file = models.File.objects.get(uuid=uuid) except: raise Http404 file_basename = os.path.basename(file.currentlocation) shared_directory_path = helpers.get_server_config_value('sharedDirectory') transfer = models.Transfer.objects.get(uuid=file.transfer.uuid) path_to_transfer = transfer.currentlocation.replace( '%sharedPath%', shared_directory_path) path_to_file = file.currentlocation.replace('%transferDirectory%', path_to_transfer) return send_file(request, path_to_file)
def archival_storage_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 send_file(request, extracted_file_path)
def archival_storage_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 send_file(request, thumbnail_path)
def archival_storage_aip_download(request, uuid): aip = elasticSearchFunctions.connect_and_get_aip_data(uuid) return send_file(request, aip.filePath)
def archival_storage_sip_download(request, path): full_path = os.path.join(os.path.dirname(AIPSTOREPATH), path) return send_file(request, full_path)