gio:检查卷是否已装入

2024-06-28 15:20:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我在做类似的事情:

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()

但是如果卷已经装入,它会抛出一个地理错误. 如何检查封闭卷是否已装入/最好的方法是什么?在


Tags: loopconnectlocationpassword事情sshfileask
2条回答

也许你可以这样做:

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

我在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)

或者

^{pr2}$

相关问题 更多 >