问题描述
我试图做一个简单的命令行客户端通过GIO的Python绑定访问共享(是的,主要要求是使用GIO)。
I am trying to make a simple command line client for accessing shares via the Python bindings of gio (yes, the main requirement is to use gio).
我可以看到,与它比较是predecessor GNOME-VFS,它提供了一些方法做认证的东西(子类化 MountOperation
),甚至一些方法这是相当具体到Samba共享,如 set_domain()
。
I can see that comparing with it's predecessor gnome-vfs, it provides some means to do authentication stuff (subclassing MountOperation
), and even some methods which are quite specific to samba shares, like set_domain()
.
但我仍坚持这一code:
But I'm stuck with this code:
import gio
fh = gio.File("smb://server_name/")
如果该服务器需要身份验证,我想这是需要 fh.mount_enclosing_volume()的调用
,因为这种方法需要一个 MountOperation
作为参数。问题是,调用此方法不执行任何操作,和逻辑 fh.enumerate_children()
(列出可用的股份)的随之而来的失败。
If that server needs authentication, I suppose that a call to fh.mount_enclosing_volume()
is needed, as this methods takes a MountOperation
as a parameter. The problem is that calling this methods does nothing, and the logical fh.enumerate_children()
(to list the available shares) that comes next fails.
任何人都可以提供如何做到这一点与GIO来完成工作的例子?
Anybody could provide a working example of how this would be done with gio ?
推荐答案
下面似乎需要装入卷的最低code:
The following appears to be the minimum code needed to mount a volume:
def mount(f):
op = gio.MountOperation()
op.connect('ask-password', ask_password_cb)
f.mount_enclosing_volume(op, mount_done_cb)
def ask_password_cb(op, message, default_user, default_domain, flags):
op.set_username(USERNAME)
op.set_domain(DOMAIN)
op.set_password(PASSWORD)
op.reply(gio.MOUNT_OPERATION_HANDLED)
def mount_done_cb(obj, res):
obj.mount_enclosing_volume_finish(res)
(从。)
另外,你可能需要一个glib.MainLoop运行,因为GIO安装功能是异步的。见GVFS贴装源$ C $ C的详细信息。
In addition, you may need a glib.MainLoop running because GIO mount functions are asynchronous. See the gvfs-mount source code for details.
这篇关于在python访问Samba共享与GIO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!