简体   繁体   中英

gio: check if volume is mounted

I'm doing something like:

mo = gio.MountOperation()

mo.connect('ask-password', ask_password_cb)

location = gio.File("ssh://leon@concepts.tim-online.nl/home/leon/test.txt")
location.mount_enclosing_volume(mo, callbackz)

loop = gobject.MainLoop()
loop.run()

But if the volume is already mounted it throws a gio.Error. How can I check if the enclosed volume is already mounted / what is the best way to do that?

Maybe you can do something like this:

if location.find_enclosing_mount() == None
   location.mount_enclosing_volume(mo, callbackz) 

I found two snippets of code on Nullege that seem to do the trick:

try:
    retval = gfile.mount_enclosing_volume_finish(result)
except gio.Error, e:
    # If we run the tests too fast
    if e.code == gio.ERROR_ALREADY_MOUNTED:
        print ('WARNING: testfile is already mounted, '
        'skipping test')
        loop.quit()
        return
    raise
self.failUnless(retval)

OR

# Already mounted ?
if g_file.query_exists():
    self._folder = g_file
else:
    mount_operation = MountOperation()
    mount_operation.set_anonymous(True)
    g_file.mount_enclosing_volume(mount_operation, self._mount_end)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM