gio:检查卷是否已安装

发布于 2024-11-02 07:23:50 字数 463 浏览 0 评论 0原文

我正在做类似的事情:

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

I'm doing something like:

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

But if the volume is already mounted it throws a gio.Error. How can I check if the enclosed volume is already mounted / what is the best way to do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吹泡泡o 2024-11-09 07:23:50

也许你可以这样做:

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

Maybe you can do something like this:

if location.find_enclosing_mount() == None
   location.mount_enclosing_volume(mo, callbackz) 
情栀口红 2024-11-09 07:23:50

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

I found two snippets of code on Nullege that seem to do the trick:

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文