Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/deposit/loader.py
# Copyright (C) 2019-2020 The Software Heritage developers | # Copyright (C) 2019-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 datetime | import datetime | ||||
import json | import json | ||||
import logging | import logging | ||||
import requests | import requests | ||||
from typing import Any, Dict, Iterator, List, Mapping, Optional, Sequence, Tuple, Union | from typing import Any, Dict, Iterator, List, Mapping, Optional, Sequence, Tuple, Union | ||||
import types | |||||
import attr | import attr | ||||
from swh.model.hashutil import hash_to_hex, hash_to_bytes | from swh.model.hashutil import hash_to_hex, hash_to_bytes | ||||
from swh.model.model import ( | from swh.model.model import ( | ||||
Person, | Person, | ||||
Revision, | Revision, | ||||
RevisionType, | RevisionType, | ||||
▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | def load(self) -> Dict: | ||||
# Update deposit status | # Update deposit status | ||||
try: | try: | ||||
if not success: | if not success: | ||||
self.client.status_update(self.deposit_id, status="failed") | self.client.status_update(self.deposit_id, status="failed") | ||||
return r | return r | ||||
snapshot_id = hash_to_bytes(r["snapshot_id"]) | snapshot_id = hash_to_bytes(r["snapshot_id"]) | ||||
branches = self.storage.snapshot_get(snapshot_id)["branches"] | snapshot = self.storage.snapshot_get(snapshot_id) | ||||
if not snapshot: | |||||
return r | |||||
branches = snapshot["branches"] | |||||
logger.debug("branches: %s", branches) | logger.debug("branches: %s", branches) | ||||
if not branches: | if not branches: | ||||
return r | return r | ||||
rev_id = branches[b"HEAD"]["target"] | rev_id = branches[b"HEAD"]["target"] | ||||
revisions = self.storage.revision_get([rev_id]) | revisions = list(self.storage.revision_get([rev_id])) | ||||
# FIXME: inconsistency between tests and production code | if not revisions: | ||||
if isinstance(revisions, types.GeneratorType): | return r | ||||
revisions = list(revisions) | |||||
revision = revisions[0] | revision = revisions[0] | ||||
if not revision: | |||||
return r | |||||
# Retrieve the revision identifier | # Retrieve the revision identifier | ||||
dir_id = revision["directory"] | dir_id = revision["directory"] | ||||
# update the deposit's status to success with its | # update the deposit's status to success with its | ||||
# revision-id and directory-id | # revision-id and directory-id | ||||
self.client.status_update( | self.client.status_update( | ||||
self.deposit_id, | self.deposit_id, | ||||
▲ Show 20 Lines • Show All 98 Lines • Show Last 20 Lines |