Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/private/deposit_read.py
Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | class SWHDepositReadArchives(SWHGetDepositAPI, SWHPrivateAPIView, | ||||
} | } | ||||
def __init__(self): | def __init__(self): | ||||
super().__init__() | super().__init__() | ||||
self.extraction_dir = self.config['extraction_dir'] | self.extraction_dir = self.config['extraction_dir'] | ||||
if not os.path.exists(self.extraction_dir): | if not os.path.exists(self.extraction_dir): | ||||
os.makedirs(self.extraction_dir) | os.makedirs(self.extraction_dir) | ||||
def retrieve_archives(self, deposit_id): | |||||
"""Given a deposit identifier, returns its associated archives' path. | |||||
Yields: | |||||
path to deposited archives | |||||
""" | |||||
deposit_requests = self._deposit_requests( | |||||
deposit_id, request_type=ARCHIVE_TYPE) | |||||
for deposit_request in deposit_requests: | |||||
yield deposit_request.archive.path | |||||
def process_get(self, req, collection_name, deposit_id): | def process_get(self, req, collection_name, deposit_id): | ||||
"""Build a unique tarball from the multiple received and stream that | """Build a unique tarball from the multiple received and stream that | ||||
content to the client. | content to the client. | ||||
Args: | Args: | ||||
req (Request): | req (Request): | ||||
collection_name (str): Collection owning the deposit | collection_name (str): Collection owning the deposit | ||||
deposit_id (id): Deposit concerned by the reading | deposit_id (id): Deposit concerned by the reading | ||||
Returns: | Returns: | ||||
Tuple status, stream of content, content-type | Tuple status, stream of content, content-type | ||||
""" | """ | ||||
archive_paths = list(self.retrieve_archives(deposit_id)) | archive_paths = [r.archive.path for r in self._deposit_requests( | ||||
with aggregate_tarballs(self.extraction_dir, | deposit_id, request_type=ARCHIVE_TYPE)] | ||||
archive_paths) as path: | with aggregate_tarballs(self.extraction_dir, archive_paths) as path: | ||||
return FileResponse(open(path, 'rb'), | return FileResponse(open(path, 'rb'), | ||||
status=status.HTTP_200_OK, | status=status.HTTP_200_OK, | ||||
content_type='application/octet-stream') | content_type='application/octet-stream') | ||||
class SWHDepositReadMetadata(SWHGetDepositAPI, SWHPrivateAPIView, | class SWHDepositReadMetadata(SWHGetDepositAPI, SWHPrivateAPIView, | ||||
DepositReadMixin): | DepositReadMixin): | ||||
"""Class in charge of aggregating metadata on a deposit. | """Class in charge of aggregating metadata on a deposit. | ||||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |