Source code for swh.fuse.backends
# Copyright (C) 2025 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
"""
FUSE backends
-------------
These classes are abstraction layers to the archive's graph and object storage.
"""
from abc import ABC, abstractmethod
from typing import Any, Dict, List, Tuple
from swh.model.swhids import CoreSWHID
[docs]
class GraphBackend(ABC):
"""
Methods required by the FUSE logic to create its folders layout.
Those methods must return dicts compliant with the Web API, to ease their use and
caching in the :py:class:`swh.fuse.fuse.Fuse` class.
Fields listed in method specifications below are the minimal required fields.
At worst, set them to ``None`` (because this is better supported by
``swh-web-client``'s ``typify_json``).
Additional fields will be included in the various `meta.json` files proposed
by this virtual file system.
"""
[docs]
@abstractmethod
async def get_history(self, swhid: CoreSWHID) -> List[Tuple[str, str]]:
"""
Return a list of tuples ``(swhid, revision swhid)``
"""
[docs]
@abstractmethod
async def get_visits(self, url_encoded: str) -> List[Dict[str, Any]]:
"""
Return a list of objects
Each object should contain fields ``date`` (ISO), ``origin`` (str),
``snapshot`` (SWHID's hash as str)
"""
[docs]
class ObjBackend(ABC):
"""
Methods required by the FUSE logic to provide files' contents.
"""
[docs]
@abstractmethod
async def get_blob(self, swhid: CoreSWHID) -> bytes:
"""
Fetch the content of a ``cnt`` object.
"""