Nautilus extension for mounting FUSE filesystems



-----BEGIN PGP SIGNED MESSAGE-----
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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFE5R/NWEgeeLQ8a74RAiVdAKDre3OtY5UnRjCYLtcSB4vFsX7NdgCeLHsc
+yzIz8zVj8gCvYKReGXUMDc=
=1+Hk
-----END PGP SIGNATURE-----
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)
        fusetab_file.close()
    
    def mount(self, menu, file):
        if file.is_gone():
            return
        
        # Strip leading file://
        filename = urllib.unquote(file.get_uri()[7:])
        os.system(self.mounts[filename])

    def unmount(self, menu, file):
        if file.is_gone():
            return
        
        # 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:
            return

        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:
            return

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

        if not os.path.ismount(filename):
            mount_item = nautilus.MenuItem('Nautilus::mount_fuse_mount',
                                    'Mount',
                                     'Mount this FUSE mount.')
            mount_item.connect('activate', self.mount, file)
        
            return mount_item,
            
        else: 
            unmount_item = nautilus.MenuItem('Nautilus::unmount_fuse_mount',
                                   'Unmount',
                                   '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]