2011-04-18 101 views
0

我做這樣的事情:GIO:檢查是否卷裝

mo = gio.MountOperation() 

mo.connect('ask-password', ask_password_cb) 

location = gio.File("ssh://[email protected]/home/leon/test.txt") 
location.mount_enclosing_volume(mo, callbackz) 

loop = gobject.MainLoop() 
loop.run() 

但是,如果卷已安裝,它拋出一個gio.Error。我如何檢查封閉的卷是否已經掛載/最好的方法是什麼?

回答

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) 

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

也許你可以做這樣的事情:

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