Accessing samba shares with gio in python

谁都会走 提交于 2019-12-04 07:54:24

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)

(Derived from gvfs-mount.)

In addition, you may need a glib.MainLoop running because GIO mount functions are asynchronous. See the gvfs-mount source code for details.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!