https://github.com/sonyxperiadev/pygerrit
Pygerrit provides a simple interface for clients to interact with Gerrit Code Review via ssh or the REST API.
This repository is no longer actively maintained. Development has moved to pygerrit2.
Prerequisites
Pygerrit has been tested on Ubuntu 10.4 and Mac OSX 10.8.4, with Python 2.6.x and 2.7.x. Support for other platforms and Python versions is not guaranteed.
Pygerrit depends on the paramiko and requests libraries.
Installation
To install pygerrit, simply:
$ pip install pygerrit
Configuration
For easier connection to the review server over ssh, the ssh connection parameters (hostname, port, username) can be given in the user's .ssh/config
file:
Host review HostName review.example.net Port 29418 User username
For easier connection to the review server over the REST API, the user's HTTP username and password can be given in the user's .netrc
file:
machine review login MyUsername password MyPassword
For instructions on how to obtain the HTTP password, refer to Gerrit's HTTP upload settings documentation.
SSH Interface
The SSH interface can be used to run commands on the Gerrit server:
>>> from pygerrit.ssh import GerritSSHClient >>> client = GerritSSHClient("review") >>> result = client.run_gerrit_command("version") >>> result <GerritSSHCommandResult [version]> >>> result.stdout <paramiko.ChannelFile from <paramiko.Channel 2 (closed) -> <paramiko.Transport at 0xd2387d90L (cipher aes128-cbc, 128 bits) (active; 0 open channel(s))>>> >>> result.stdout.read() 'gerrit version 2.6.1\n' >>>
Event Stream
Gerrit offers a stream-events
command that is run over ssh, and returns back a stream of events (new change uploaded, change merged, comment added, etc) as JSON text.
This library handles the parsing of the JSON text from the event stream, encapsulating the data in event objects (Python classes), and allowing the client to fetch them from a queue. It also allows users to easily add handling of custom event types, for example if they are running a customised Gerrit installation with non-standard events:
>>> from pygerrit.client import GerritClient >>> client = GerritClient("review") >>> client.gerrit_version() '2.6.1' >>> client.start_event_stream() >>> client.get_event() <CommentAddedEvent>: <Change 12345, platform/packages/apps/Example, master> <Patchset 1, 5c4b2f76297f04fbab77eb8c3462e087bc4b6f90> <Account Bob Example (bob.example@example.com)> >>> client.get_event() <CommentAddedEvent>: <Change 67890, platform/frameworks/example, master> <Patchset 2, c7d4f9956c80b1df66a66d66dea3960e71de4910> <Account John Example (john.example@example.com)> >>> client.stop_event_stream() >>>
Refer to the example script for a more detailed example of how the SSH event stream interface works.
REST API
This simple example shows how to get the user's open changes, authenticating to Gerrit via HTTP Digest authentication using an explicitly given username and password:
>>> from requests.auth import HTTPDigestAuth >>> from pygerrit.rest import GerritRestAPI >>> auth = HTTPDigestAuth('username', 'password') >>> rest = GerritRestAPI(url='http://review.example.net', auth=auth) >>> changes = rest.get("/changes/?q=owner:self%20status:open")
Refer to the rest_example script for a more detailed example of how the REST API interface works.
Copyright and License
Copyright 2011 Sony Ericsson Mobile Communications. All rights reserved.
Copyright 2012 Sony Mobile Communications. All rights reserved.
Licensed under The MIT License. Please refer to the LICENSE file for full license details.
example:
#!/usr/bin/env python
import os
import sys
import re
# SSH Interface
"""
from pygerrit.ssh import GerritSSHClient
client = GerritSSHClient("hostname", username="gerrit", port=29418)
result = client.run_gerrit_command("version")
print result.stdout.read()
"""
# Event Stream
from pygerrit.client import GerritClient
client = GerritClient("hostname", username="gerrit", port=29418)
print client.gerrit_version()
#client.start_event_stream()
#print client.get_event()
#client.stop_event_stream()
"""
print dir(client)
print client.run_command('ls-groups').stdout.read()
print type(client.run_command('ls-groups').stdout.read())
"""
for x in client.query("owner:gerrit branch:testing"):
print dir(x)
print 'project:', x.project
print 'branch:', x.branch
print 'url:', x.url
print 'ChangeId:', x.change_id
print 'Revision:', x.current_patchset.revision
相关推荐
【应用】★★★★★-manzana-.NET API for interacting with the Apple iPhone【应用】★★★★★-manzana-.NET API for interacting with the Apple iPhone 1.适合学生学习研究参考 2.适合个人学习研究参考 3.适合...
《manzana-.NET API for interacting with the Apple iPhone》是一个专为与苹果iPhone进行交互而设计的.NET API库。这个源码包对于那些希望在iOS平台上构建应用的开发者来说,是一份宝贵的资源,特别是对.NET框架有...
【标题】"IOS应用源码之manzana-.NET API for interacting with the Apple iPhone" 提供了一种使用.NET框架与苹果iPhone进行交互的途径。manzana是一个.NET库,它为开发者提供了方便的API,使得在iOS应用开发过程中...
本文将深入探讨标题为“【应用】-manzana-.NET API for interacting with the Apple iPhone.7z”的压缩包,其中包含了一个名为“Manzana”的.NET库,它为开发者提供了一种与Apple iPhone进行交互的方式。 首先,...
Python library for interacting with FreeIPA network protocols
《苹果iPhone交互.NET API——Manzana库详解》 在当今移动开发领域,iOS系统以其稳定性和用户友好性获得了广大开发者和用户的喜爱。对于非Objective-C或Swift开发者来说,想要与苹果iPhone进行交互可能会遇到一些...
C++作为一款强大的系统编程语言,虽然原生不支持JSON解析和生成,但有许多第三方库可以帮助开发者处理JSON,其中之一就是这个"A C++ library for interacting with JSON"。 在C++中,与JSON交互的库通常提供了解析...
Golang client for interacting with Moov API server side
《ISO IEC TR 23187:2020 Information technology - Cloud computing - Interacting with cloud service partners (CSNs)》是国际标准化组织(ISO)和国际电工委员会(IEC)联合发布的一份技术报告,旨在为云计算...
Lesson 37 - A library for graphical user interfaces Lesson 38 - Capstone project: game of tag Appendix A - Answers to lesson exercises Appendix B - Python cheat sheet Appendix C - Interesting Python ...
An official Python module for interacting with the Blockchain.info API.
We're pleased to announce the release of Python Tools ... Our Machine Learning Pack contains some samples for the scikit-learn library and Python code generation for Azure Machine Learning web services.
开源项目-jszwedko-go-circleci.zip,go-circleci -- a Go library for interacting with CircleCI's HTTP API
Arduino 101 houses an Intel Curie module which offers a better performance at a lower...Perfect for students, teachers, and hobbyists who need just enough information to get started with the Arduino 101.
### A2J: Anchor-to-Joint Regression Network for 3D Articulated Pose Estimation #### 摘要 本文提出了一种名为A2J(Anchor-to-Joint Regression Network)的新型锚点基方法,用于从单个深度图像进行3D手部及...
The Python 3 Standard Library contains hundreds of modules for interacting with the operating system, interpreter, and Internet–all extensively tested and ready to jump-start application development....
Single-carrier receiver having a channel equalizer interacting with a Trellis decoder and a channel equalization method therefor Decision feedback equalizer and control method thereof Decision ...
The Python 3 Standard Library contains hundreds of modules for interacting with the operating system, interpreter, and Internet–all extensively tested and ready to jump-start application development....