基于异步的dbus接口

adbus的Python项目详细描述


使用python的asyncio模块的python的d-bus绑定。

状态

https://api.codacy.com/project/badge/Grade/c66c19cdcadd4c83bc4b70596d65aa7ahttps://api.codacy.com/project/badge/Coverage/c66c19cdcadd4c83bc4b70596d65aa7a

依赖关系

  1. python=3.7
  2. libsystemd>;=232(不需要systemd,只需要libsystemd,这是一个单独的包)
  3. cython>;=0.25.2(仅在进行任何更改时需要重新生成sdbus.c)

建造/安装

  • 为开发python而就地构建./setup.py build_ext–in place
  • html文档存储在gh pages分支中,因此github将 作为github页面使用。要构建它们: 一。查看gh pages分支到../python adbus/html 2.CD成文档 三。sphinx apidoc-o源/./adbus 四。制作HTML

单元测试

注意:有些测试用例需要systemd中的busctl工具。

  • 从根目录(例如)运行特定的单元测试:python-m unittest tests.test_sdbus_method.test.test_method_single_str
  • 要从根目录(例如)运行特定的单元测试模块,请执行以下操作: python-m unittest tests.test_sdbus_方法
  • 从根目录运行所有单元测试:python-m unittest 探索

服务器示例

对象示例

这是一个可以连接到服务的对象示例。

importadbusimporttypingclassExampleClass(adbus.server.Object):signal1:int=adbus.server.Signal()signal2:typing.List[int]=adbus.server.Signal()property1:str=adbus.server.Property('none',read_only=True,hidden=True)property2:typing.List[int]=adbus.server.Property(['rr','ff'],deprectiated=True)def__init__(self,service):super().__init__(service,path='/xxx/yyy',interface='yyy.xxx')@adbus.method(name='test',hidden=True)deftest_method(self,r:int,gg:str)->int:returnr+10defdo_something(self):self.signal1.emit(14)

设置多个属性

可以同时设置多个属性,这将延迟属性 更新信号,并为所有属性更改发送一个信号。这是个好习惯 这在更改多个属性时,将减少D总线上的通信量。

注意:必须在循环中运行。

客户示例

通过代理访问远程接口

可以使用代理将远程接口映射到本地实例化类。

注意:如果偶数循环未运行,则不会捕获任何信号,属性也不会 缓存(即在每次访问时读取,而不是跟踪属性更改信号)

这是一个原型,用于查看它的外观,它尚未实现。

service=adbus.Service(bus='session')proxy=adbus.client.Proxy(service,'com.example.xxx','/com/example/Service1',interface='com.example.service.unit')asyncdefproxy_examples():awaitproxy.update()# initialize the proxy# == Access Propertiesawaitproxy.remote_propertyX.set(45)print(awaitproxy.remote_propertyY.get())# == orawaitproxy.remote_propertyX(45)print(awaitproxy.remote_propertyY())# == Access Methodsasyncio.ensure_future(proxy.remote_method_foo("some info"))# don't wait for resultx=awaitproxy.remote_method_bar(100,12,-45)# wait for result# == Add a Coroutine to a Signalasyncdeflocal_method(signal_data:int):print(signal_data)proxy.remote_signal.add(local_method)# == orproxy.remote_signal(local_method)# == Remove a Coroutine to a Signalproxy.remote_signal.remove(local_method)# == or (if already added)proxy.remote_signal(local_method)# == Access a method using a different interface nameproxy['com.example.service.serve'].remote_method_800(b"data")# == Create a new proxy from a node in the proxyproxy_new=awaitproxy('Test')# == Loop through all nodes in a proxysum_cnt=0asyncfornodeinproxy:try:sum_cnt+=awaitnode.countexceptAttributeError:pass# == set multiple properties in one message (if linked to an adbus based server)asyncwithproxyasp:p.property1="some data"p.property2=[1,2,3,4,5]loop=asyncio.get_event_loop()loop.run_until_complete(proxy_examples())loop.close()

样式指南

对于一致的样式,所有代码都使用facebook样式在yapf中运行:

所有docstring都是google风格的。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java GridBagLayout不填充区域   java Memozied Fibonacci未运行与常规Fibonacci解决方案   Java Web启动未启动问题   Java中异常和if-then的区别   java从命令提示符运行批处理文件获取错误   socket在Java中验证SSL证书的公共名称   如何在JAVA中检查字符串数组中的相等字   用java语言将音频文件转换成文本文件的语音识别   java为什么foo(1,2,3)没有传递给varargs方法foo(对象…)作为整数[]   java通过蓝牙将奇怪的数据从Arduino传输到Android   java ContainerRequestFilter获取空entitystream   java如何从安卓 studio中删除不兼容类型错误   基本Java错误   在Spring引导中使用REST API时发生java错误   javascript通过从SQL查询派生的URL打开页面