Python fuse.FUSE Examples

The following are 12 code examples of fuse.FUSE(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module fuse , or try the search function .
Example #1
Source File: oxfs.py    From oxfs with MIT License 6 votes vote down vote up
def fuse_main(self, mount_point):
        self.__class__.__name__ = 'oxfs'
        if 'Darwin' == self.sys:
            fuse = FUSE(self, mount_point, foreground=True, nothreads=True,
                        allow_other=True, auto_cache=True,
                        uid=os.getuid(), gid=os.getgid(),
                        defer_permissions=True, kill_on_unmount=True,
                        noappledouble=True, noapplexattr=True,
                        nosuid=True, nobrowse=True, volname=self.host)
        elif 'Linux' == self.sys:
            fuse = FUSE(self, mount_point, foreground=True, nothreads=True,
                        allow_other=True, auto_cache=True,
                        uid=os.getuid(), gid=os.getgid(),
                        auto_unmount=True)
        else:
            self.logger.error('not supported system, {}'.format(self.sys))
            sys.exit() 
Example #2
Source File: tier1_tests.py    From b2_fuse with MIT License 6 votes vote down vote up
def init_b2fuse():
    config = load_config("config.yaml")

    os.makedirs("mountpoint")

    filesystem = B2Fuse(
        config["accountId"],
        config["applicationKey"],
        config["bucketId"],
        config["enableHashfiles"],
        config["memoryLimit"],
        config["tempFolder"],
        config["useDisk"],
    )

    fuse = FUSE(filesystem, "mountpoint", nothreads=True, foreground=False)

    return fuse 
Example #3
Source File: fuse_inmem_fs.py    From backdoros with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def main(argc, argv):
    if (argc < 2):
        print("USAGE: " + argv[0] + " <mount path>")
        return 0

    print("Running FUSE ...")
    # logging.basicConfig(level=logging.DEBUG)
    fuse = FUSE(Memory(), argv[1], foreground=False, nothreads=True)
    print("Done!")


###############
# Entry Point #
############### 
Example #4
Source File: zfuse.py    From zfsp with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def mount(pool, mountpoint):
    zf = ZFSFuse(pool)
    fuse = FUSE(zf, mountpoint,
                foreground=True,
                rdonly=True,
                nobrowse=True,
                jail_symlinks=True,
                nolocalcaches=True,
                # debug=True,
                ) 
Example #5
Source File: router.py    From gitfs with Apache License 2.0 5 votes vote down vote up
def __getattr__(self, attr_name):
        """
        It will only be called by the `__init__` method from `fuse.FUSE` to
        establish which operations will be allowed after mounting the
        filesystem.
        """

        methods = inspect.getmembers(FUSE, predicate=callable)
        fuse_allowed_methods = set(elem[0] for elem in methods)

        return attr_name in fuse_allowed_methods - set(["bmap", "lock"]) 
Example #6
Source File: fuse_runner.py    From parsec-cloud with GNU Affero General Public License v3.0 5 votes vote down vote up
def _bootstrap_mountpoint(base_mountpoint_path: PurePath, workspace_fs) -> PurePath:
    # Find a suitable path where to mount the workspace. The check we are doing
    # here are not atomic (and the mount operation is not itself atomic anyway),
    # hence there is still edgecases where the mount can crash due to concurrent
    # changes on the mountpoint path
    workspace_name = workspace_fs.get_workspace_name()
    for tentative in count(1):
        if tentative == 1:
            dirname = workspace_name
        else:
            dirname = f"{workspace_name} ({tentative})"
        mountpoint_path = base_mountpoint_path / dirname

        try:
            # On POSIX systems, mounting target must exists
            trio_mountpoint_path = trio.Path(mountpoint_path)
            await trio_mountpoint_path.mkdir(mode=0o700, exist_ok=True, parents=True)
            base_st_dev = (await trio.Path(base_mountpoint_path).stat()).st_dev
            initial_st_dev = (await trio_mountpoint_path.stat()).st_dev
            if initial_st_dev != base_st_dev:
                # mountpoint_path seems to already have a mountpoint on it,
                # hence find another place to setup our own mountpoint
                continue
            if list(await trio_mountpoint_path.iterdir()):
                # mountpoint_path not empty, cannot mount there
                continue
            return mountpoint_path, initial_st_dev

        except OSError:
            # In case of hard crash, it's possible the FUSE mountpoint is still
            # mounted (but points to nothing). In such case just mount in
            # another place
            continue 
Example #7
Source File: ff4d.py    From ff4d with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def space_usage_allocated(space_usage):
  '''Return the space usage allocation for an individual or team account as applicable.'''
  return space_usage.allocation.get_individual().allocated if space_usage.allocation.is_individual() else space_usage.allocation.get_team().allocated


##################################
# Class: FUSE Dropbox operations #
################################## 
Example #8
Source File: ratarmount.py    From ratarmount with MIT License 5 votes vote down vote up
def readdir( self, path, fh ):
        # we only need to return these special directories. FUSE automatically expands these and will not ask
        # for paths like /../foo/./../bar, so we don't need to worry about cleaning such paths
        yield '.'
        yield '..'

        files = self._getUnionMountListDir( path )
        if files is not None:
            for key in files:
                yield key
            return

        # If no folder was found, check whether the special .versions folder was requested
        result = self._decodeVersionsPathAPI( path )
        if not result:
            return
        path, pathIsVersions, fileVersion = result

        if not pathIsVersions:
            files = self._getUnionMountListDir( path )
            if files is not None:
                for key in files:
                    yield key
            return

        # Print all available versions of the file at filePath as the contents of the special '.versions' folder
        version = 0
        for mountSource in self.mountSources:
            if isinstance( mountSource, str ):
                realPath = os.path.join( mountSource, path.lstrip( os.path.sep ) )
                if os.path.lexists( realPath ):
                    version += 1
                    yield str( version )
            else:
                result = mountSource.getFileInfo( path, listVersions = True )
                for x in result.keys():
                    version += 1
                    yield str( version ) 
Example #9
Source File: ratarmount.py    From ratarmount with MIT License 5 votes vote down vote up
def cli( args = None ):
    tmpArgs = sys.argv if args is None else args
    if '--version' in tmpArgs or '-v' in tmpArgs:
        print( "ratarmount", __version__ )
        return

    args = parseArgs( args )

    # Convert the comma separated list of key[=value] options into a dictionary for fusepy
    fusekwargs = dict( [ option.split( '=', 1 ) if '=' in option else ( option, True )
                       for option in args.fuse.split( ',' ) ] ) if args.fuse else {}
    if args.prefix:
        fusekwargs['modules'] = 'subdir'
        fusekwargs['subdir'] = args.prefix

    if args.mount_point in args.mount_source:
        fusekwargs['nonempty'] = True

    global printDebug
    printDebug = args.debug

    fuseOperationsObject = TarMount(
        pathToMount          = args.mount_source,
        clearIndexCache      = args.recreate_index,
        recursive            = args.recursive,
        gzipSeekPointSpacing = args.gzip_seek_point_spacing,
        mountPoint           = args.mount_point )

    fuse.FUSE( operations = fuseOperationsObject,
               mountpoint = args.mount_point,
               foreground = args.foreground,
               nothreads  = True, # Can't access SQLite database connection object from multiple threads
               **fusekwargs ) 
Example #10
Source File: mitogen-fuse.py    From mitogen with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def main(router):
    if len(sys.argv) != 3:
        print('usage: %s <host> <mountpoint>' % sys.argv[0])
        sys.exit(1)

    kwargs = {}
    if sys.platform == 'darwin':
        kwargs['volname'] = '%s (Mitogen)' % (sys.argv[1],)

    fuse.FUSE(
        operations=Operations(sys.argv[1]),
        mountpoint=sys.argv[2],
        foreground=True,
        **kwargs
    ) 
Example #11
Source File: fuse.py    From filesystem_spec with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def run(fs, path, mount_point, foreground=True, threads=False):
    """ Mount stuff in a local directory

    This uses fusepy to make it appear as if a given path on an fsspec
    instance is in fact resident within the local file-system.

    This requires that fusepy by installed, and that FUSE be available on
    the system (typically requiring a package to be installed with
    apt, yum, brew, etc.).

    Parameters
    ----------
    fs: file-system instance
        From one of the compatible implementations
    path: str
        Location on that file-system to regard as the root directory to
        mount. Note that you typically should include the terminating "/"
        character.
    mount_point: str
        An empty directory on the local file-system where the contents of
        the remote path will appear
    foreground: bool
        Whether or not calling this function will block. Operation will
        typically be more stable if True.
    threads: bool
        Whether or not to create threads when responding to file operations
        within the mounter directory. Operation will typically be more
        stable if False.

    """
    func = lambda: FUSE(
        FUSEr(fs, path), mount_point, nothreads=not threads, foreground=True
    )
    if foreground is False:
        th = threading.Thread(target=func)
        th.daemon = True
        th.start()
        return th
    else:  # pragma: no cover
        try:
            func()
        except KeyboardInterrupt:
            pass 
Example #12
Source File: ratarmount.py    From ratarmount with MIT License 4 votes vote down vote up
def _decodeVersionsPathAPI( self, filePath ):
        """
        Do a loop over the parent path parts to resolve possible versions in parent folders.
        Note that multiple versions of a folder always are union mounted. So, for the path to a file
        inside those folders the exact version of a parent folder can simply be removed for lookup.
        Therefore, translate something like: /foo.version/3/bar.version/2/mimi.version/1 into
        /foo/bar/mimi.version/1
        This is possibly time-costly but requesting a different version from the most recent should
        be a rare occurence and FUSE also checks all parent parts before accessing a file so it
        might only slow down access by roughly factor 2.
        """

        # @todo make it work for files ending with '.versions'.
        # Currently, this feature would be hidden by those files. But, I think this should be quite rare.
        # I could allow arbitrary amounts of dots like '....versions' but then it wouldn't be discernible
        # for ...versions whether the versions of ..versions or .versions file was requested. I could add
        # a rule for the decision, like ...versions shows the versions of .versions and ....versions for
        # ..versions, however, all of this might require an awful lot of file existence checking.
        # My first idea was to use hidden subfolders for each file like path/to/file/.versions/1 but FUSE
        # checks the parents in a path that they are directories first, so getattr or readdir is not even
        # called for path/to/file/.versions if path/to/file is not a directory.
        # Another alternative might be one hidden folder at the root for a parallel file tree, like
        # /.versions/path/to/file/3 but that runs into similar problems when trying to specify the file
        # version or if a .versions root directory exists.

        filePathParts = filePath.lstrip( '/' ).split( '/' )
        filePath = ''
        pathIsVersions = False
        fileVersion = None # Not valid if None or parentIsVersions is True
        for part in filePathParts:
            # Skip over the exact version specified
            if pathIsVersions:
                try:
                    fileVersion = int( part )
                    assert str( fileVersion ) == part
                except:
                    return None
                pathIsVersions = False
                continue

            # Simply append normal existing folders
            tmpFilePath = '/'.join( [ filePath, part ] )
            if self._getUnionMountFileInfo( tmpFilePath ):
                filePath = tmpFilePath
                fileVersion = 0
                continue

            # If current path does not exist, check if it is a special versions path
            if part.endswith( '.versions' ) and len( part ) > len( '.versions' ):
                pathIsVersions = True
                filePath = tmpFilePath[:-len( '.versions' )]
                continue

            # Parent path does not exist and is not a versions path, so any subpaths also won't exist either
            return None

        return filePath, pathIsVersions, ( None if pathIsVersions else fileVersion )