Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/service.py
# Copyright (C) 2015-2020 The Software Heritage developers | # Copyright (C) 2015-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 Affero General Public License version 3, or any later version | # License: GNU Affero 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 itertools | import itertools | ||||
import os | import os | ||||
import re | import re | ||||
from collections import defaultdict | from collections import defaultdict | ||||
from typing import Any, Dict, List, Set, Iterator, Optional, Tuple | from typing import Any, Dict, List, Set, Iterator, Optional, Tuple | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from swh.storage.algos import diff, revisions_walker | |||||
from swh.model.identifiers import CONTENT, DIRECTORY, RELEASE, REVISION, SNAPSHOT | from swh.model.identifiers import CONTENT, DIRECTORY, RELEASE, REVISION, SNAPSHOT | ||||
from swh.storage.algos import diff, revisions_walker | |||||
from swh.vault.exc import NotFoundExc as VaultNotFoundExc | |||||
from swh.web import config | from swh.web import config | ||||
from swh.web.common import converters | from swh.web.common import converters | ||||
from swh.web.common import query | from swh.web.common import query | ||||
from swh.web.common.exc import BadInputExc, NotFoundExc | from swh.web.common.exc import BadInputExc, NotFoundExc | ||||
from swh.web.common.origin_visits import get_origin_visit | from swh.web.common.origin_visits import get_origin_visit | ||||
from swh.web.common.typing import OriginInfo, OriginVisitInfo | from swh.web.common.typing import OriginInfo, OriginVisitInfo | ||||
▲ Show 20 Lines • Show All 1,059 Lines • ▼ Show 20 Lines | def lookup_directory_through_revision(revision, path=None, limit=100, with_data=False): | ||||
""" | """ | ||||
rev = lookup_revision_through(revision, limit) | rev = lookup_revision_through(revision, limit) | ||||
if not rev: | if not rev: | ||||
raise NotFoundExc("Revision with criterion %s not found!" % revision) | raise NotFoundExc("Revision with criterion %s not found!" % revision) | ||||
return (rev["id"], lookup_directory_with_revision(rev["id"], path, with_data)) | return (rev["id"], lookup_directory_with_revision(rev["id"], path, with_data)) | ||||
def _vault_request(vault_fn, *args, **kwargs): | |||||
try: | |||||
return vault_fn(*args, **kwargs) | |||||
ardumont: With D3127, can be `except (swh.vault.exc.)NotFound`... now ;)
(i may be off on the swh.vault. | |||||
except VaultNotFoundExc: | |||||
return None | |||||
def vault_cook(obj_type, obj_id, email=None): | def vault_cook(obj_type, obj_id, email=None): | ||||
"""Cook a vault bundle. | """Cook a vault bundle. | ||||
""" | """ | ||||
return vault.cook(obj_type, obj_id, email=email) | return _vault_request(vault.cook, obj_type, obj_id, email=email) | ||||
def vault_fetch(obj_type, obj_id): | def vault_fetch(obj_type, obj_id): | ||||
"""Fetch a vault bundle. | """Fetch a vault bundle. | ||||
""" | """ | ||||
return vault.fetch(obj_type, obj_id) | return _vault_request(vault.fetch, obj_type, obj_id) | ||||
def vault_progress(obj_type, obj_id): | def vault_progress(obj_type, obj_id): | ||||
"""Get the current progress of a vault bundle. | """Get the current progress of a vault bundle. | ||||
""" | """ | ||||
return vault.progress(obj_type, obj_id) | return _vault_request(vault.progress, obj_type, obj_id) | ||||
def diff_revision(rev_id): | def diff_revision(rev_id): | ||||
"""Get the list of file changes (insertion / deletion / modification / | """Get the list of file changes (insertion / deletion / modification / | ||||
renaming) for a particular revision. | renaming) for a particular revision. | ||||
""" | """ | ||||
rev_sha1_git_bin = _to_sha1_bin(rev_id) | rev_sha1_git_bin = _to_sha1_bin(rev_id) | ||||
▲ Show 20 Lines • Show All 126 Lines • Show Last 20 Lines |
With D3127, can be except (swh.vault.exc.)NotFound... now ;)
(i may be off on the swh.vault.exception module ;)