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-2020 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 itertools import chain | from itertools import chain | ||||
from shutil import get_unpack_formats | from shutil import get_unpack_formats | ||||
from rest_framework import status | from rest_framework import status | ||||
from swh.scheduler.utils import create_oneshot_task_dict | from swh.scheduler.utils import create_oneshot_task_dict | ||||
from . import DepositReadMixin, SWHPrivateAPIView | from . import DepositReadMixin, SWHPrivateAPIView | ||||
from ..common import SWHGetDepositAPI | from ..common import APIGet | ||||
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 = ( | MANDATORY_ARCHIVE_UNREADABLE = ( | ||||
"At least one of its associated archives is not readable" # noqa | "At least one of its associated archives is not readable" # noqa | ||||
Show All 22 Lines | |||||
def known_archive_format(filename): | def known_archive_format(filename): | ||||
return any( | return any( | ||||
filename.endswith(t) for t in chain(*(x[1] for x in get_unpack_formats())) | filename.endswith(t) for t in chain(*(x[1] for x in get_unpack_formats())) | ||||
) | ) | ||||
class SWHChecksDeposit(SWHPrivateAPIView, SWHGetDepositAPI, DepositReadMixin): | class SWHChecksDeposit(SWHPrivateAPIView, APIGet, 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 164 Lines • Show Last 20 Lines |