示例#1
0
async def main(swhids: List[CoreSWHID], root_path: Path,
               conf: Dict[str, Any]) -> None:
    """ swh-fuse CLI entry-point """

    # Use pyfuse3 asyncio layer to match the rest of Software Heritage codebase
    pyfuse3_asyncio.enable()

    async with FuseCache(conf["cache"]) as cache:
        fs = Fuse(root_path, cache, conf)

        # Initially populate the cache
        for swhid in swhids:
            try:
                await fs.get_metadata(swhid)
            except Exception as err:
                fs.logger.exception("Cannot prefetch object %s: %s", swhid,
                                    err)

        fuse_options = set(pyfuse3.default_options)
        fuse_options.add("fsname=swhfs")

        try:
            pyfuse3.init(fs, root_path, fuse_options)
            await pyfuse3.main()
        except Exception as err:
            fs.logger.error("Error running FUSE: %s", err)
        finally:
            fs.shutdown()
            pyfuse3.close(unmount=True)
示例#2
0
async def mount(client,
                id,
                destination: str,
                offset_id=0,
                limit=None,
                filter_music=False,
                debug_fuse=False,
                reverse=False,
                updates=False,
                fsname="tgfs"):
    pyfuse3_asyncio.enable()
    fuse_options = set(pyfuse3.default_options)
    fuse_options.add('fsname=' + fsname)

    if debug_fuse:
        fuse_options.add('debug')

    # in order to use numeric id
    if isinstance(id, int):
        await client.get_dialogs()

    logging.debug("Querying entity %s" % id)

    entity: Entity = await client.get_entity(id)

    logging.debug("Got '%s'" % get_display_name(entity))

    logging.info(
        "Querying %s messages starting with message_id %d, music: %s" %
        (limit if limit else "all", offset_id, filter_music))

    messages, documents_handles = await client.get_documents(
        entity,
        limit=limit,
        filter_music=filter_music,
        offset_id=offset_id,
        reverse=reverse)

    logging.info("Mounting %d files to %s" %
                 (len(documents_handles), destination))
    # logging.debug("Files: %s" % ([doc['id'] for msg, doc in documents], ))

    telegram_fs = TelegramFsAsync()

    for msg, dh in zip(messages, documents_handles):
        telegram_fs.add_file(msg, dh)

    if updates:
        client.add_event_handler(
            create_new_files_handler(client, telegram_fs, entity), )

    pyfuse3.init(telegram_fs, destination, fuse_options)

    await pyfuse3.main(min_tasks=10)
示例#3
0
import asyncio
import stat
import logging
import errno
import pyfuse3
import pyfuse3_asyncio

try:
    import faulthandler
except ImportError:
    pass
else:
    faulthandler.enable()

log = logging.getLogger(__name__)
pyfuse3_asyncio.enable()

class TestFs(pyfuse3.Operations):
    def __init__(self):
        super(TestFs, self).__init__()
        self.hello_name = b"message"
        self.hello_inode = pyfuse3.ROOT_INODE+1
        self.hello_data = b"hello world\n"

    async def getattr(self, inode, ctx=None):
        entry = pyfuse3.EntryAttributes()
        if inode == pyfuse3.ROOT_INODE:
            entry.st_mode = (stat.S_IFDIR | 0o755)
            entry.st_size = 0
        elif inode == self.hello_inode:
            entry.st_mode = (stat.S_IFREG | 0o644)