gio:检查音量是否已挂载
我正在做类似这样的事情:
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()
但是如果这个卷已经被挂载了,就会出现一个gio.Error的错误。我该如何检查这个卷是否已经挂载了呢?有没有什么好的方法?
2 个回答
1
也许你可以试试这样做:
if location.find_enclosing_mount() == None
location.mount_enclosing_volume(mo, callbackz)
0
我在Nullege上找到两个代码片段,看起来可以解决这个问题:
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)
或者
# 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)