Bugzilla的Twisted API

txbugzilla的Python项目详细描述


使用Twisted异步(非阻塞)访问Bugzilla的XML-RPCAPI 框架。

https://travis-ci.org/ktdreyer/txbugzilla.svg?branch=masterhttps://badge.fury.io/py/txbugzilla.svg

简单示例:获取错误

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文件:

  1. 使用浏览器登录Bugzilla的Web用户界面。

  2. 转到“首选项”->;“API Keys”。

  3. 生成新的api密钥。

  4. 在主目录中创建.config/python-bugzilla目录:

    mkdir -p ~/.config/python-bugzilla
    
  5. 在文本编辑器中编辑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

使用此软件包的软件包

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

推荐PyPI第三方库


热门话题
当使用RequestDispatcher时,servlets Java最终没有被调用   java生成对具有可变参数数的方法的调用   java如何使用select子句中的参数化列映射iBATIS的查询?   java无法创建类型为org的插件。阿帕奇。登录中。log4j。果心阿佩德。元素RollingFile的RollingFileAppender   java当子实体和父实体之间存在OneTONE JPA关系时,是否可以将其与父实体一起持久化?   Android上的java Facebook集成fbconnect断开链接   获取方法调用方的java机制   从列表创建Oracle阵列时出现java问题   添加和检索元素的ArrayList的java ArrayList   在java中从字符串中删除无效的XML字符   java如何构建完整生成的maven模块   java如何准确地改变播放所有分辨率midi文件的速度?   shell javac:无效标志:/src/中位_度。ubuntu中的java   java使用从其他类的方法检索到的信息