python助手库
assistant-lib的Python项目详细描述
辅助图书馆
这个python3.x库用于编写可以与助手交互的程序。在
助理:https://gitlab.com/goassistant/assistant
Pypi网页:https://pypi.org/project/assistant-lib
变更日志
1.0:新发现格式
改进:
- 处理Assistant>;0.3中设置的新对等发现协议
特点:
- (NEW)Helper从git获取版本。在
- 帮助程序正确初始化日志记录。在
- 帮助者向其他人显示组件(对等发现)。查看其他组件尚未实现。在
- 生成SSL证书的帮助程序。在
0.15:初始可用版本
第一个可用版本。在
特点:
- 帮助程序正确初始化日志记录。在
- 帮助者向其他人显示组件(对等发现)。查看其他组件尚未实现。在
- 生成SSL证书的帮助程序
许可证
选择这个项目的许可证。选择它而不是GPLv3是因为:
The license allows developers and companies to use and integrate a software component released under the LGPL into their own (even proprietary) software without being required by the terms of a strong copyleft license to release the source code of their own components. However, any developer who modifies an LGPL-covered component is required to make their modified version available under the same LGPL license.
有关详细信息,请参见Wikipedia。在
安装
pip3安装助手库
使用
下面是一个简单的测试:
$ python3
Python 3.7.4 (default, Jul 11 2019, 10:43:21)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from assistant_lib import assistant
>>> ac = assistant.AssistantClient()
Output redirected to the file : 'assistant.log'
>>> ac.get_hostname()
'ambre'
测井
当您使用以下命令初始化助理客户端时:
^{pr2}$它还将配置python日志引擎。您只需使用标准日志记录功能:
logging.debug("A debug message")
logging.info("An info message")
logging.warning("A warning message")
logging.error("An error message")
默认情况下,日志写入名为^{str 1}的日志文件中$助理.log在debug日志级别。日志是以json格式编写的,以供日志集中工具(如Elastic或Datalog)使用。在
如果要更改此行为,只需设置以下环境变量:
- 日志文件:文件的路径
- 日志级别:日志级别:调试、信息、警告、错误
应用程序示例foobar.py公司名称:
$ LOG_LEVEL=DEBUG LOG_FILE=/var/log/foobar.log /usr/bin/python3 foobar.py
$ LOG_LEVEL=WARNING /usr/bin/python3 foobar.py
如果您不想登录文件而希望登录控制台,请使用以下环境变量:
- LOG_输出:TTY用于登录控制台,其他任何内容用于登录文件。在
示例:
$ LOG_OUTPUT=TTY /usr/bin/python3 foobar.py
控制台中显示的日志不再是json格式。在
日志记录限制
json日志格式化程序不处理在字符串中包含变量的旧python方法,如下所示:
a = 8
logging.info("The number 8 will not be display : %d" % a)
您必须使用新方法:
a = 8
logging.info("The number 8 will be display : {0}".format(a))
本地测试
如果您计划进行一些升级并进行测试,以下是如何处理:
- 编辑代码中的更改
- 运行clean and build命令:
make
- 检查距离/文件夹
- 从dist/文件夹安装构建的包:
pip3 install dist/assistant_lib-<version>.tar.gz
释放
由于setuptools_scm库,版本号自动从git获取。所以在代码中没有设置版本。在
要创建新版本,只需创建一个标记并将其推送到Gitlab。CI/CD管道将生成一个版本并将其发布到Pypi。这只是魔术;)。你可以查看.gitlab-词yml文件以了解它是如何工作的。在
- 项目
标签: