Bugzilla的Twisted API
txbugzilla的Python项目详细描述
使用Twisted异步(非阻塞)访问Bugzilla的XML-RPCAPI 框架。
简单示例:获取错误
fromtxbugzillaimportconnect,BugzillaExceptionfromtwisted.internetimportdeferfromtwisted.internet.taskimportreact@defer.inlineCallbacksdefexample(reactor):# connect() defaults to https://bugzilla.redhat.com/xmlrpc.cgibz=yieldconnect()# fetch a bugtry:bug=yieldbz.get_bug_simple(10000)print(bug.summary)exceptBugzillaExceptionase:print(e)if__name__=='__main__':react(example)
示例:身份验证
默认情况下,到Bugzilla的连接是匿名的,因此您不能做有趣的事情 比如更新bug或者查看私有bug或者私有信息。如果你愿意 验证到Bugzilla的连接,可以将API密钥传递给 connect()。延迟的connect()返回将触发回调 通过身份验证的连接。
fromtxbugzillaimportconnectfromtwisted.internetimportdefer@defer.inlineCallbacksdefexample():# Authenticate via username and passwordbz=yieldconnect(api_key='123456abcdef')# Do something as this logged-in user, for example:# bug = yield bz.getbugsimple(...)
(以前版本的txbugzilla支持旧的用户名/密码和 用于身份验证的令牌方法。Bugzilla 5中不推荐使用这些方法 最新版本的txbugzilla不再支持这些功能。你必须使用 现在是API键。)
旁注:bugzillarc
如果没有向connect()传递任何参数,则生成的连接将是 匿名,除非您有一个特殊的.config/python-bugzilla/bugzillarc 文件在主目录中。此文件应该如下所示:
$ cat ~/.config/python-bugzilla/bugzillarc [bugzilla.redhat.com] api_key=ABCDEFGHIJK
txbugzilla将查找此文件并尝试在其中使用api密钥 存在。
构造这个bugzillarc文件:
使用浏览器登录Bugzilla的Web用户界面。
转到“首选项”->;“API Keys”。
生成新的api密钥。
在主目录中创建.config/python-bugzilla目录:
mkdir -p ~/.config/python-bugzilla
在文本编辑器中编辑bugzillarc文件:
cat ~/.config/python-bugzilla/bugzillarc [buzilla.example.com] api_key=YOUR_API_KEY
示例:分配错误
这肯定会让你交到朋友。
fromtxbugzillaimportconnect,BugzillaExceptionfromtwisted.internetimportdefer@defer.inlineCallbacksdefexample():bz=yieldconnect(username='user@example.com',password='foo')try:result=yieldbz.assign(1234,'someone@redhat.com')ifresult:print('assigned bz #1234 to someone@redhat.com')else:print('bz #1234 is already assigned to someone@redhat.com')exceptBugzillaExceptionase:print(e)
示例:使用上游错误进行搜索
快速找出“哪个BZ匹配这个外部跟踪票据?“
fromtxbugzillaimportconnect,BugzillaExceptionfromtwisted.internetimportdefer@defer.inlineCallbacksdefexample():bz=yieldconnect()try:result=yieldbz.find_by_external_tracker('http://tracker.ceph.com','16673')forbinresult:print(b.weburl+' '+b.summary)exceptBugzillaExceptionase:print(e)
示例:原始XML-RPC调用
想做一些这里没有提到的API call吗? 使用call()方法进行原始xml-rpc调用。它会处理api 你也需要密钥验证。
例如,要查看您所属的所有组的列表:
fromtxbugzillaimportconnect,BugzillaExceptionfromtwisted.internetimportdeferfrompprintimportpprint@defer.inlineCallbacksdefexample():bz=yieldconnect(username='user@example.com',password='foo')try:result=yieldbz.call('User.get',{'names':[bz.username],'include_fields':['groups']})pprint(result['users'][0]['groups'])exceptBugzillaExceptionase:print(e)
许可证
麻省理工学院(见LICENSE)