diff --git a/swh/fuse/fs/artifact.py b/swh/fuse/fs/artifact.py index eb296f7aab3b9bde47bf18ff084399be9c488e75..db05133353745a6887da7aea1667ac5be24de758 100644 --- a/swh/fuse/fs/artifact.py +++ b/swh/fuse/fs/artifact.py @@ -5,18 +5,36 @@ from typing import Any, AsyncIterator -from swh.fuse.fs.entry import ArtifactEntry, EntryMode +from swh.fuse.fs.entry import EntryMode, FuseEntry from swh.model.identifiers import CONTENT, DIRECTORY, SWHID # Avoid cycling import Fuse = "Fuse" -def typify(name: str, mode: int, fuse: Fuse, swhid: SWHID, prefetch: Any = None) -> Any: +class ArtifactEntry(FuseEntry): + """ FUSE virtual entry for a Software Heritage Artifact + + Attributes: + swhid: Software Heritage persistent identifier + prefetch: optional prefetched metadata used to set entry attributes + """ + + def __init__( + self, name: str, mode: int, fuse: Fuse, swhid: SWHID, prefetch: Any = None + ): + super().__init__(name, mode, fuse) + self.swhid = swhid + self.prefetch = prefetch + + +def typify( + name: str, mode: int, fuse: Fuse, swhid: SWHID, prefetch: Any = None +) -> ArtifactEntry: """ Create an artifact entry corresponding to the given artifact type """ - constructor = {CONTENT: Content, DIRECTORY: Directory} - return constructor[swhid.object_type](name, mode, fuse, swhid, prefetch) + getters = {CONTENT: Content, DIRECTORY: Directory} + return getters[swhid.object_type](name, mode, fuse, swhid, prefetch) class Content(ArtifactEntry): diff --git a/swh/fuse/fs/entry.py b/swh/fuse/fs/entry.py index e16a7d56614d27526b5c18300623a1a95d39a492..bb2866aaa0b0accfbea2fb190c87e07f388c884a 100644 --- a/swh/fuse/fs/entry.py +++ b/swh/fuse/fs/entry.py @@ -5,9 +5,6 @@ from enum import IntEnum from stat import S_IFDIR, S_IFREG -from typing import Any - -from swh.model.identifiers import SWHID # Avoid cycling import Fuse = "Fuse" @@ -49,19 +46,3 @@ class FuseEntry: async def __aiter__(self): return None - - -class ArtifactEntry(FuseEntry): - """ FUSE virtual entry for a Software Heritage Artifact - - Attributes: - swhid: Software Heritage persistent identifier - prefetch: optional prefetched metadata used to set entry attributes - """ - - def __init__( - self, name: str, mode: int, fuse: Fuse, swhid: SWHID, prefetch: Any = None - ): - super().__init__(name, mode, fuse) - self.swhid = swhid - self.prefetch = prefetch