Bluez-obex 和 python opp 服务器,如何更改文件存储位置?
Bluez-obex and python opp server, how to change where files are stored?
我正在使用 bluez-obex 创建一个基于 python 的 opp obex 服务器,但是我在更改目录时遇到了问题。我的代码基于 并将其转换为带有文件路径的 class 作为输入。我的当前代码不断得到 KeyError: 'object does not export any interfaces; you might need to pass object path as the 2nd argument for get()'
。我设置的路径错误吗?我的 class 代码和调用函数如下。
from gi.repository import GLib
import pydbus
class opp_server():
def __init__(self, path):
self.BUS_NAME = 'org.bluez.obex'
self.PATH = '/org/bluez/obex'
self.AGENT_MANAGER_INTERFACE = 'org.bluez.obex.AgentManager1'
self.AGENT_INTERFACE = 'org.bluez.obex.Agent1'
self.SESSION_INTERFACE = 'org.bluez.obex.Session1'
self.TRANSFER_INTERFACE = 'org.bluez.obex.Transfer1'
self.ses_bus = pydbus.SessionBus()
self.path = path
def transfer_status_handler(self, iface, props_changed, props_removed):
if iface == self.TRANSFER_INTERFACE:
status = props_changed.get('Status')
if status == 'complete':
print('Transfer complete')
elif status == 'queued':
print('Still queued')
elif status == 'active':
print('transferring')
elif status == 'suspended':
print('Suspended')
elif status == 'error':
print('error')
def iface_added_handler(self, dbus_path, interfaces):
if self.SESSION_INTERFACE in interfaces and 'server' in dbus_path:
print('Server session added')
elif self.TRANSFER_INTERFACE in interfaces and 'server' in dbus_path:
print('Transfer started')
transfer = self.ses_bus.get(self.BUS_NAME, dbus_path)
transfer.onPropertiesChanged = self.transfer_status_handler
def AuthorizePush(self):
print('Authorize Push', self.path)
transfer = self.ses_bus.get(self.BUS_NAME, self.path)
props = transfer.GetAll(self.TRANSFER_INTERFACE)
print(props)
return props.get('Name')
def Cancel(self):
print('Authorization Cancelled')
def Release(self):
pass
def server(self):
obex_mngr = self.ses_bus.get('org.bluez.obex', '/')
obex_mngr.onInterfacesAdded = self.iface_added_handler
mainloop = GLib.MainLoop()
self.ses_bus.register_object('/test/agent', self.AuthorizePush(), None)
print('Agent created')
agnt_mngr = ses_bus.get(self.BUS_NAME, self.PATH)
agnt_mngr.RegisterAgent('/test/agent')
print('Agent registered')
try:
mainloop.run()
except KeyboardInterrupt:
mainloop.quit()
调用 class
server = servertest.opp_server('/home/pi/GAMMA/ImageData')
server.server()
您似乎混淆了 DBus 对象路径和文件系统路径。对于 AuthorizePush
,输入是 org.bluez.obex.Transfer1
接口的 DBus 对象路径,但您正在尝试使用要放置文件的文件系统路径。
当您 publish/export 您的 org.bluez.obex.Agent1
界面时,您需要使用相同参数的三个方法。可能值得查看 Exporting own objects
的 pydbus 教程
obexd
是从以下信息开始的:/usr/share/dbus-1/services/org.bluez.obex.service
对我来说是:
[D-BUS Service]
Name=org.bluez.obex
Exec=/usr/lib/bluetooth/obexd
SystemdService=obex.service
obexd
可以用其他选项启动,从帮助可以看出:
$ /usr/lib/bluetooth/obexd -h
Usage:
obexd [OPTION?]
Help Options:
-h, --help Show help options
Application Options:
-d, --debug=DEBUG Enable debug information output
-p, --plugin=NAME,... Specify plugins to load
-P, --noplugin=NAME,... Specify plugins not to load
-n, --nodetach Run with logging in foreground
-r, --root=PATH Specify root folder location. Both absolute and relative can be used, but relative paths are assumed to be relative to user $HOME folder. Default $XDG_CACHE_HOME
-S, --root-setup=SCRIPT Root folder setup script
-l, --symlinks Allow symlinks leading outside of the root folder
-c, --capability=FILE Specify capability file, use '!' mark for scripts
-a, --auto-accept Automatically accept push requests
因此您可以使用 --root=PATH
选项更改默认位置。
如果您确实想更改代码中的路径,则需要使从 AuthorizePush
返回的值具有绝对路径。例如:
def AuthorizePush(self, path):
transfer = ses_bus.get(BUS_NAME, path)
props = transfer.GetAll(TRANSFER_INTERFACE)
return '/tmp/' + props.get('Name')
这会将文件放入 /tmp
目录。
我正在使用 bluez-obex 创建一个基于 python 的 opp obex 服务器,但是我在更改目录时遇到了问题。我的代码基于 KeyError: 'object does not export any interfaces; you might need to pass object path as the 2nd argument for get()'
。我设置的路径错误吗?我的 class 代码和调用函数如下。
from gi.repository import GLib
import pydbus
class opp_server():
def __init__(self, path):
self.BUS_NAME = 'org.bluez.obex'
self.PATH = '/org/bluez/obex'
self.AGENT_MANAGER_INTERFACE = 'org.bluez.obex.AgentManager1'
self.AGENT_INTERFACE = 'org.bluez.obex.Agent1'
self.SESSION_INTERFACE = 'org.bluez.obex.Session1'
self.TRANSFER_INTERFACE = 'org.bluez.obex.Transfer1'
self.ses_bus = pydbus.SessionBus()
self.path = path
def transfer_status_handler(self, iface, props_changed, props_removed):
if iface == self.TRANSFER_INTERFACE:
status = props_changed.get('Status')
if status == 'complete':
print('Transfer complete')
elif status == 'queued':
print('Still queued')
elif status == 'active':
print('transferring')
elif status == 'suspended':
print('Suspended')
elif status == 'error':
print('error')
def iface_added_handler(self, dbus_path, interfaces):
if self.SESSION_INTERFACE in interfaces and 'server' in dbus_path:
print('Server session added')
elif self.TRANSFER_INTERFACE in interfaces and 'server' in dbus_path:
print('Transfer started')
transfer = self.ses_bus.get(self.BUS_NAME, dbus_path)
transfer.onPropertiesChanged = self.transfer_status_handler
def AuthorizePush(self):
print('Authorize Push', self.path)
transfer = self.ses_bus.get(self.BUS_NAME, self.path)
props = transfer.GetAll(self.TRANSFER_INTERFACE)
print(props)
return props.get('Name')
def Cancel(self):
print('Authorization Cancelled')
def Release(self):
pass
def server(self):
obex_mngr = self.ses_bus.get('org.bluez.obex', '/')
obex_mngr.onInterfacesAdded = self.iface_added_handler
mainloop = GLib.MainLoop()
self.ses_bus.register_object('/test/agent', self.AuthorizePush(), None)
print('Agent created')
agnt_mngr = ses_bus.get(self.BUS_NAME, self.PATH)
agnt_mngr.RegisterAgent('/test/agent')
print('Agent registered')
try:
mainloop.run()
except KeyboardInterrupt:
mainloop.quit()
调用 class
server = servertest.opp_server('/home/pi/GAMMA/ImageData')
server.server()
您似乎混淆了 DBus 对象路径和文件系统路径。对于 AuthorizePush
,输入是 org.bluez.obex.Transfer1
接口的 DBus 对象路径,但您正在尝试使用要放置文件的文件系统路径。
当您 publish/export 您的 org.bluez.obex.Agent1
界面时,您需要使用相同参数的三个方法。可能值得查看 Exporting own objects
obexd
是从以下信息开始的:/usr/share/dbus-1/services/org.bluez.obex.service
对我来说是:
[D-BUS Service]
Name=org.bluez.obex
Exec=/usr/lib/bluetooth/obexd
SystemdService=obex.service
obexd
可以用其他选项启动,从帮助可以看出:
$ /usr/lib/bluetooth/obexd -h
Usage:
obexd [OPTION?]
Help Options:
-h, --help Show help options
Application Options:
-d, --debug=DEBUG Enable debug information output
-p, --plugin=NAME,... Specify plugins to load
-P, --noplugin=NAME,... Specify plugins not to load
-n, --nodetach Run with logging in foreground
-r, --root=PATH Specify root folder location. Both absolute and relative can be used, but relative paths are assumed to be relative to user $HOME folder. Default $XDG_CACHE_HOME
-S, --root-setup=SCRIPT Root folder setup script
-l, --symlinks Allow symlinks leading outside of the root folder
-c, --capability=FILE Specify capability file, use '!' mark for scripts
-a, --auto-accept Automatically accept push requests
因此您可以使用 --root=PATH
选项更改默认位置。
如果您确实想更改代码中的路径,则需要使从 AuthorizePush
返回的值具有绝对路径。例如:
def AuthorizePush(self, path):
transfer = ses_bus.get(BUS_NAME, path)
props = transfer.GetAll(TRANSFER_INTERFACE)
return '/tmp/' + props.get('Name')
这会将文件放入 /tmp
目录。