我正在做一些类似的事情:
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。如何检查附带的卷是否已装入/执行此操作的最佳方法是什么?
发布于 2011-04-20 05:42:18
我在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)发布于 2011-04-19 06:28:26
也许你可以这样做:
if location.find_enclosing_mount() == None
location.mount_enclosing_volume(mo, callbackz) https://stackoverflow.com/questions/5709454
复制相似问题