簡體   English   中英

gio:檢查是否已安裝卷

[英]gio: check if volume is mounted

我正在做類似的事情:

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。 如何檢查隨附的卷是否已安裝/最佳方法是什么?

也許您可以執行以下操作:

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)

要么

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM