【问题标题】:gio: check if volume is mountedgio:检查卷是否已安装
【发布时间】:2011-04-18 22:05:54
【问题描述】:

我正在做类似的事情:

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。如何检查封闭卷是否已安装/最好的方法是什么?

【问题讨论】:

    标签: python gnome gio


    【解决方案1】:

    也许你可以这样做:

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

    【讨论】:

      【解决方案2】:

      我在 Nullege 上发现了两个 sn-ps 代码似乎可以解决问题:

      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)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-12-31
        • 2016-11-30
        • 1970-01-01
        • 1970-01-01
        • 2020-07-10
        • 2019-11-21
        • 2013-03-24
        相关资源
        最近更新 更多