Bugzilla的Twisted API
项目描述
使用Twisted框架异步(非阻塞)访问Bugzilla的XML-RPC API。
简单示例:获取一个bug
from txbugzilla import connect, BugzillaException
from twisted.internet import defer
from twisted.internet.task import react
@defer.inlineCallbacks
def example(reactor):
# connect() defaults to https://bugzilla.redhat.com/xmlrpc.cgi
bz = yield connect()
# fetch a bug
try:
bug = yield bz.get_bug_simple(10000)
print(bug.summary)
except BugzillaException as e:
print(e)
if __name__ == '__main__':
react(example)
示例:认证
默认情况下,连接到Bugzilla是匿名的,因此您无法执行像更新bug或查看私有bug或私有信息等有趣的事情。如果您希望认证您的Bugzilla连接,可以向connect()传递一个API密钥。connect()返回的deferred将触发一个带有认证连接的回调。
from txbugzilla import connect
from twisted.internet import defer
@defer.inlineCallbacks
def example():
# Authenticate with an API key
bz = yield connect(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 UI。
转到“首选项” -> “API密钥”。
生成新的API密钥。
在您的家目录中创建.config/python-bugzilla目录
mkdir -p ~/.config/python-bugzilla
在您的文本编辑器中编辑 bugzillarc 文件
cat ~/.config/python-bugzilla/bugzillarc [buzilla.example.com] api_key=YOUR_API_KEY
示例:分配错误
这肯定会赢得朋友。
from txbugzilla import connect, BugzillaException
from twisted.internet import defer
@defer.inlineCallbacks
def example():
bz = yield connect(api_key='123456abcdef')
try:
result = yield bz.assign(1234, 'someone@redhat.com')
if result:
print('assigned bz #1234 to someone@redhat.com')
else:
print('bz #1234 is already assigned to someone@redhat.com')
except BugzillaException as e:
print(e)
示例:使用上游错误搜索
快速找到“BZ与哪个外部跟踪器票据匹配?”
from txbugzilla import connect, BugzillaException
from twisted.internet import defer
@defer.inlineCallbacks
def example():
bz = yield connect()
try:
result = yield bz.find_by_external_tracker(
'http://tracker.ceph.com', '16673')
for b in result:
print(b.weburl + ' ' + b.summary)
except BugzillaException as e:
print(e)
示例:原始XML-RPC调用
想使用这里未提及的某些 API 调用? 使用 call() 方法进行原始XML-RPC调用。它还会为您处理API密钥认证。
例如,查看您是其中一员的全部组列表
from txbugzilla import connect, BugzillaException
from twisted.internet import defer
from pprint import pprint
@defer.inlineCallbacks
def example():
bz = yield connect(api_key='123456abcdef')
try:
result = yield bz.call('User.get', {'names': [bz.username],
'include_fields': ['groups']})
pprint(result['users'][0]['groups'])
except BugzillaException as e:
print(e)
许可证
MIT(参见 LICENSE)
使用此包的包
关闭
txbugzilla-2.1.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | b9b83459986a47066f5b9b1cd0645828f12fc6b899f380553352ad656db63075 |
|
MD5 | a9e9bb170dc21b5303ea90a578392085 |
|
BLAKE2b-256 | 7c9b686abcaa9f8df4a92a8abd38e2142ff93dc1fa9028bc0a926a90de493e09 |