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 a开发者_JAVA百科lready 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)
精彩评论