Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/private/deposit_check.py
# Copyright (C) 2017-2019 The Software Heritage developers | # Copyright (C) 2017-2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import json | import json | ||||
import re | import re | ||||
import tarfile | import tarfile | ||||
import zipfile | import zipfile | ||||
from rest_framework import status | from rest_framework import status | ||||
from . import DepositReadMixin | from . import DepositReadMixin, SWHPrivateAPIView | ||||
from ..common import SWHGetDepositAPI, SWHPrivateAPIView | from ..common import SWHGetDepositAPI | ||||
from ...config import DEPOSIT_STATUS_VERIFIED, DEPOSIT_STATUS_REJECTED | from ...config import DEPOSIT_STATUS_VERIFIED, DEPOSIT_STATUS_REJECTED | ||||
from ...config import ARCHIVE_TYPE | from ...config import ARCHIVE_TYPE | ||||
from ...models import Deposit | from ...models import Deposit | ||||
MANDATORY_FIELDS_MISSING = 'Mandatory fields are missing' | MANDATORY_FIELDS_MISSING = 'Mandatory fields are missing' | ||||
ALTERNATE_FIELDS_MISSING = 'Mandatory alternate fields are missing' | ALTERNATE_FIELDS_MISSING = 'Mandatory alternate fields are missing' | ||||
MANDATORY_ARCHIVE_UNREADABLE = 'At least one of its associated archives is not readable' # noqa | MANDATORY_ARCHIVE_UNREADABLE = 'At least one of its associated archives is not readable' # noqa | ||||
MANDATORY_ARCHIVE_INVALID = 'Mandatory archive is invalid (i.e contains only one archive)' # noqa | MANDATORY_ARCHIVE_INVALID = 'Mandatory archive is invalid (i.e contains only one archive)' # noqa | ||||
MANDATORY_ARCHIVE_UNSUPPORTED = 'Mandatory archive type is not supported' | MANDATORY_ARCHIVE_UNSUPPORTED = 'Mandatory archive type is not supported' | ||||
MANDATORY_ARCHIVE_MISSING = 'Deposit without archive is rejected' | MANDATORY_ARCHIVE_MISSING = 'Deposit without archive is rejected' | ||||
ARCHIVE_EXTENSIONS = [ | ARCHIVE_EXTENSIONS = [ | ||||
'zip', 'tar', 'tar.gz', 'xz', 'tar.xz', 'bz2', | 'zip', 'tar', 'tar.gz', 'xz', 'tar.xz', 'bz2', | ||||
'tar.bz2', 'Z', 'tar.Z', 'tgz', '7z' | 'tar.bz2', 'Z', 'tar.Z', 'tgz', '7z' | ||||
] | ] | ||||
PATTERN_ARCHIVE_EXTENSION = re.compile( | PATTERN_ARCHIVE_EXTENSION = re.compile( | ||||
r'.*\.(%s)$' % '|'.join(ARCHIVE_EXTENSIONS)) | r'.*\.(%s)$' % '|'.join(ARCHIVE_EXTENSIONS)) | ||||
class SWHChecksDeposit(SWHGetDepositAPI, SWHPrivateAPIView, DepositReadMixin): | class SWHChecksDeposit(SWHPrivateAPIView, SWHGetDepositAPI, 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. | ||||
""" | """ | ||||
def _check_deposit_archives(self, deposit): | def _check_deposit_archives(self, deposit): | ||||
"""Given a deposit, check each deposit request of type archive. | """Given a deposit, check each deposit request of type archive. | ||||
▲ Show 20 Lines • Show All 165 Lines • Show Last 20 Lines |