Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/private/deposit_read.py
Show All 12 Lines | |||||
from rest_framework import status | from rest_framework import status | ||||
from swh.core import tarball | from swh.core import tarball | ||||
from swh.model import identifiers | from swh.model import identifiers | ||||
from swh.deposit.utils import normalize_date | from swh.deposit.utils import normalize_date | ||||
from . import DepositReadMixin, SWHPrivateAPIView | from . import DepositReadMixin, SWHPrivateAPIView | ||||
from ...config import SWH_PERSON, ARCHIVE_TYPE | from ...config import SWH_PERSON, ARCHIVE_TYPE | ||||
from ..common import SWHGetDepositAPI | from ..common import GetAPI | ||||
from ...models import Deposit | from ...models import Deposit | ||||
@contextmanager | @contextmanager | ||||
def aggregate_tarballs(extraction_dir, archive_paths): | def aggregate_tarballs(extraction_dir, archive_paths): | ||||
"""Aggregate multiple tarballs into one and returns this new archive's | """Aggregate multiple tarballs into one and returns this new archive's | ||||
path. | path. | ||||
Show All 25 Lines | def aggregate_tarballs(extraction_dir, archive_paths): | ||||
shutil.rmtree(aggregated_tarball_rootdir) | shutil.rmtree(aggregated_tarball_rootdir) | ||||
try: | try: | ||||
yield temp_tarpath | yield temp_tarpath | ||||
finally: | finally: | ||||
shutil.rmtree(dir_path) | shutil.rmtree(dir_path) | ||||
class SWHDepositReadArchives(SWHPrivateAPIView, SWHGetDepositAPI, DepositReadMixin): | class SWHDepositReadArchives(SWHPrivateAPIView, GetAPI, DepositReadMixin): | ||||
"""Dedicated class to read a deposit's raw archives content. | """Dedicated class to read a deposit's raw archives content. | ||||
Only GET is supported. | Only GET is supported. | ||||
""" | """ | ||||
ADDITIONAL_CONFIG = { | ADDITIONAL_CONFIG = { | ||||
"extraction_dir": ("str", "/tmp/swh-deposit/archive/"), | "extraction_dir": ("str", "/tmp/swh-deposit/archive/"), | ||||
Show All 25 Lines | def process_get(self, request, collection_name, deposit_id): | ||||
with aggregate_tarballs(self.extraction_dir, archive_paths) as path: | with aggregate_tarballs(self.extraction_dir, archive_paths) as path: | ||||
return FileResponse( | return FileResponse( | ||||
open(path, "rb"), | open(path, "rb"), | ||||
status=status.HTTP_200_OK, | status=status.HTTP_200_OK, | ||||
content_type="application/zip", | content_type="application/zip", | ||||
) | ) | ||||
class SWHDepositReadMetadata(SWHPrivateAPIView, SWHGetDepositAPI, DepositReadMixin): | class SWHDepositReadMetadata(SWHPrivateAPIView, GetAPI, DepositReadMixin): | ||||
"""Class in charge of aggregating metadata on a deposit. | """Class in charge of aggregating metadata on a deposit. | ||||
""" | """ | ||||
ADDITIONAL_CONFIG = { | ADDITIONAL_CONFIG = { | ||||
"provider": ( | "provider": ( | ||||
"dict", | "dict", | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 103 Lines • Show Last 20 Lines |