swh.fuse.fuse module#

class swh.fuse.fuse.Fuse(cache: FuseCache, conf: Dict[str, Any], graph_backend: GraphBackend, obj_backend: ContentBackend)[source]#

Bases: Operations

Software Heritage Filesystem in Userspace (FUSE).

Locally mount parts of the archive and navigate it as a virtual file system.

This class ties together pyfuse3 and the configured cache and back-end.

shutdown() None[source]#
inode2entry(inode: InodeT) FuseEntry[source]#

Return the entry matching a given inode

async get_metadata(swhid: CoreSWHID) Any[source]#

Retrieve metadata for a given SWHID using Software Heritage API

async get_blob(swhid: CoreSWHID) bytes[source]#

Retrieve the blob bytes for a given content SWHID using Software Heritage API

async get_history(swhid: CoreSWHID) List[CoreSWHID][source]#

Retrieve a revision’s history using Software Heritage Graph API

async get_visits(url_encoded: str) List[Dict[str, Any]][source]#

Retrieve origin visits given an encoded-URL using Software Heritage API

async get_attrs(entry: FuseEntry) EntryAttributes[source]#

Return entry attributes

async getattr(inode: InodeT, _ctx: RequestContext) EntryAttributes[source]#

Get attributes for a given inode

async opendir(inode: InodeT, _ctx: RequestContext) FileHandleT[source]#

Open a directory referred by a given inode

async readdir(fh: FileHandleT, offset: int, token: ReaddirToken) None[source]#

Read entries in an open directory

async open(inode: InodeT, _flags: int, _ctx: RequestContext) FileInfo[source]#

Open an inode and return a unique file handle

async read(fh: FileHandleT, offset: int, length: int) bytes[source]#

Read length bytes from file handle fh at position offset

async lookup(parent_inode: InodeT, name: FileNameT, _ctx: RequestContext) EntryAttributes[source]#

Look up a directory entry by name and get its attributes

Return target of symbolic link inode.

ctx will be a RequestContext instance.

Remove a file

async getxattr(inode: InodeT, name: XAttrNameT, _ctx: RequestContext) bytes[source]#

This allows someone to get the extend attribute “user.swhid” on entities that have one (this is mostly useful when traversing source trees). The attribute value is a SWHID string.

swh.fuse.fuse.graph_backend_factory(conf: Dict[str, Any], cache: FuseCache) GraphBackend[source]#
swh.fuse.fuse.obj_backend_factory(conf: Dict[str, Any], cache: FuseCache) ContentBackend[source]#
class swh.fuse.fuse.SwhFsTmpMount(config=None)[source]#

Bases: object

This context manager will mount the Software Heritage archive on a temporary folder, in a separate thread running its own asyncio event loop. It returns a Path object pointing to the mountpoint, that will be deleted when exiting the context. Note that the main thread will likely wait a bit before entering the context, until the mountpoint appears.

Example:

with SwhFsTmpMount() as mountpoint:
    swhid = "swh:1:cnt:c839dea9e8e6f0528b468214348fee8669b305b2"
    hello_world_path = mountpoint / "archive" / swhid
    print(open(hello_world_path).read())

SwhFS will be configured as if launched via the swh fs mount command, so please set the SWH_CONFIG_FILE environment variable pointing to the relevant configuration file. The config parameter is intended for unit tests.

See also Advice for parallelization.

async swh.fuse.fuse.main(swhids: List[CoreSWHID], root_path: Path, conf: Dict[str, Any], content_backend: ContentBackend | None = None) None[source]#

swh-fuse CLI entry-point