Nautilus extension for mounting FUSE filesystems

Hash: SHA1

I wrote this in twenty minutes this evening to scratch an itch, and I
thought someone else might find it useful.  It's a simple extension that
adds a mount (or unmount, if it's mounted) item to the context menu of
FUSE mount points.

Information about FUSE mount points is stored in a file called
~/.fusetab, which consists of one line per mount point, with each line
consisting of two comma separated values, in the form:

<absolute path to mount point>, <command line to mount file system>

That's really all there is to it.  The next step (if one's goal was to
make it as easy to use FUSE mounts as gnome-vfs) would probably be to
write a control panel like the "Connect to Server..." one, that would
create the mount points and add the .fusetab entries, but since I'm
content with doing it manually, I probably won't bother.

Needless to say, this extension has not been extensively tested, so use
it at your own risk.  The main known problem it has is that you have to
restart nautilus for it to pick up new .fusetab entries.  Since I don't
really want to parse the file every time a context menu comes up, I'm
not sure how to fix that.

The extension is attached.

Jonathan Doda
Version: GnuPG v1.4.2.2 (GNU/Linux)

import os
import urllib
import nautilus

FUSETAB_PATH = "~/.fusetab"

class FUSEMountExtension(nautilus.MenuProvider):
    def __init__(self):
        fusetab_file = open(os.path.expanduser(FUSETAB_PATH))
        self.mounts = dict(line.split(",") for line in fusetab_file)
    def mount(self, menu, file):
        if file.is_gone():
        # Strip leading file://
        filename = urllib.unquote(file.get_uri()[7:])

    def unmount(self, menu, file):
        if file.is_gone():
        # Strip leading file://
        filename = urllib.unquote(file.get_uri()[7:])
        os.system('fusermount -u "%s"' % filename)
    def get_file_items(self, window, files):
        if len(files) != 1:

        file = files[0]

        # We're only going to put ourselves on fuse mounts context menus
        filename = urllib.unquote(file.get_uri()[7:])
        if filename not in self.mounts:

        # Gnome can only handle file:
        # In the future we might want to copy the file locally
        if file.get_uri_scheme() != 'file':

        if not os.path.ismount(filename):
            mount_item = nautilus.MenuItem('Nautilus::mount_fuse_mount',
                                     'Mount this FUSE mount.')
            mount_item.connect('activate', self.mount, file)
            return mount_item,
            unmount_item = nautilus.MenuItem('Nautilus::unmount_fuse_mount',
                                   'Unmount this FUSE mount.')
            unmount_item.connect('activate', self.unmount, file)
            return unmount_item,

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]