pygerrit Package

pygerrit Package

Module to interface with Gerrit.

class pygerrit.__init__.GerritReviewMessageFormatter(header=None, footer=None)[source]

Bases: object

Helper class to format review messages that are sent to Gerrit.

Parameters:
  • header (str) – (optional) If specified, will be prepended as the first paragraph of the output message.
  • footer (str) – (optional) If specified, will be appended as the last paragraph of the output message.
append(data)[source]

Append the given data to the output.

Parameters:data – If a list, it is formatted as a bullet list with each entry in the list being a separate bullet. Otherwise if it is a string, the string is added as a paragraph.
Raises :ValueError if data is not a list or a string.
format()[source]

Format the message parts to a string.

Returns :A string of all the message parts separated into paragraphs, with header and footer paragraphs if they were specified in the constructor.
is_empty()[source]

Check if the formatter is empty.

Returns :True if empty, i.e. no paragraphs have been added.
pygerrit.__init__.escape_string(string)[source]

Escape a string for use in Gerrit commands.

Parameters:string (str) – The string to escape.
Returns:The string with necessary escapes and surrounding double quotes so that it can be passed to any of the Gerrit commands that require double-quoted strings.
pygerrit.__init__.from_json(json_data, key)[source]

Helper method to extract values from JSON data.

Parameters:
  • json_data (dict) – The JSON data
  • key (str) – Key to get data for.
Returns :

The value of key from json_data, or None if json_data does not contain key.

client Module

Gerrit client interface.

class pygerrit.client.GerritClient(host, username=None, port=None, keepalive=None)[source]

Bases: object

Gerrit client interface.

Parameters:
  • host (str) – The hostname.
  • username (str) – (optional) The username to use when connecting.
  • port (str) – (optional) The port number to connect to.
  • keepalive (int) – (optional) Keepalive interval in seconds.
gerrit_info()[source]

Get connection information.

Returns :A tuple of the username, and version of Gerrit that is connected to.
gerrit_version()[source]

Get the Gerrit version.

Returns :The version of Gerrit that is connected to, as a string.
get_event(block=True, timeout=None)[source]

Get the next event from the queue.

Parameters:
  • block (boolean) – Set to True to block if no event is available.
  • timeout (seconds) – Timeout to wait if no event is available.
Returns :

The next event as a pygerrit.events.GerritEvent instance, or None if:

  • block is False and there is no event available in the queue, or
  • block is True and no event is available within the time specified by timeout.
put_event(data)[source]

Create event from data and add it to the queue.

Parameters:data (json) – The JSON data from which to create the event.
Raises :pygerrit.error.GerritError if the queue is full, or the factory could not create the event.
query(term)[source]

Run a query.

Parameters:term (str) – The query term to run.
Returns :A list of results as pygerrit.models.Change objects.
Raises :ValueError if term is not a string.
run_command(command)[source]

Run a command.

Parameters:command (str) – The command to run.
Return :The result as a string.
Raises :ValueError if command is not a string.
start_event_stream()[source]

Start streaming events from gerrit stream-events.

stop_event_stream()[source]

Stop streaming events from gerrit stream-events.

error Module

Error classes.

exception pygerrit.error.GerritError[source]

Bases: exceptions.Exception

Raised when something goes wrong in Gerrit handling.

events Module

Gerrit event classes.

class pygerrit.events.ChangeAbandonedEvent(json_data)[source]

Bases: pygerrit.events.GerritEvent

Gerrit “change-abandoned” event.

name = 'change-abandoned'
class pygerrit.events.ChangeMergedEvent(json_data)[source]

Bases: pygerrit.events.GerritEvent

Gerrit “change-merged” event.

name = 'change-merged'
class pygerrit.events.ChangeRestoredEvent(json_data)[source]

Bases: pygerrit.events.GerritEvent

Gerrit “change-restored” event.

name = 'change-restored'
class pygerrit.events.CommentAddedEvent(json_data)[source]

Bases: pygerrit.events.GerritEvent

Gerrit “comment-added” event.

name = 'comment-added'
class pygerrit.events.DraftPublishedEvent(json_data)[source]

Bases: pygerrit.events.GerritEvent

Gerrit “draft-published” event.

name = 'draft-published'
class pygerrit.events.ErrorEvent(json_data)[source]

Bases: pygerrit.events.GerritEvent

Error occurred when processing json data from Gerrit’s event stream.

classmethod error_json(error)[source]

Return a json string for the error.

name = 'error-event'
class pygerrit.events.GerritEvent(json_data)[source]

Bases: object

Gerrit event base class.

class pygerrit.events.GerritEventFactory[source]

Bases: object

Gerrit event factory.

classmethod create(data)[source]

Create a new event instance.

Return an instance of the GerritEvent subclass after converting data to json.

Raise GerritError if json parsed from data does not contain a type key.

classmethod register(name)[source]

Decorator to register the event identified by name.

Return the decorated class.

Raise GerritError if the event is already registered.

class pygerrit.events.MergeFailedEvent(json_data)[source]

Bases: pygerrit.events.GerritEvent

Gerrit “merge-failed” event.

name = 'merge-failed'
class pygerrit.events.PatchsetCreatedEvent(json_data)[source]

Bases: pygerrit.events.GerritEvent

Gerrit “patchset-created” event.

name = 'patchset-created'
class pygerrit.events.RefUpdatedEvent(json_data)[source]

Bases: pygerrit.events.GerritEvent

Gerrit “ref-updated” event.

name = 'ref-updated'
class pygerrit.events.ReviewerAddedEvent(json_data)[source]

Bases: pygerrit.events.GerritEvent

Gerrit “reviewer-added” event.

name = 'reviewer-added'
class pygerrit.events.TopicChangedEvent(json_data)[source]

Bases: pygerrit.events.GerritEvent

Gerrit “topic-changed” event.

name = 'topic-changed'
class pygerrit.events.UnhandledEvent(json_data)[source]

Bases: pygerrit.events.GerritEvent

Unknown event type received in json data from Gerrit’s event stream.

name = 'unhandled-event'

models Module

Models for Gerrit JSON data.

class pygerrit.models.Account(json_data)[source]

Bases: object

Gerrit user account (name and email address).

static from_json(json_data, key)[source]

Create an Account instance.

Return an instance of Account initialised with values from key in json_data, or None if json_data does not contain key.

class pygerrit.models.Approval(json_data)[source]

Bases: object

Gerrit approval (verified, code review, etc).

class pygerrit.models.Change(json_data)[source]

Bases: object

Gerrit change.

static from_json(json_data)[source]

Create a Change instance.

Return an instance of Change initialised with values from “change” in json_data, or None if json_data does not contain “change”.

class pygerrit.models.CurrentPatchset(json_data)[source]

Bases: pygerrit.models.Patchset

Gerrit current patch set.

static from_json(json_data)[source]

Create a CurrentPatchset instance.

Return an instance of CurrentPatchset initialised with values from “currentPatchSet” in json_data, or None if json_data does not contain “currentPatchSet”.

class pygerrit.models.Patchset(json_data)[source]

Bases: object

Gerrit patch set.

static from_json(json_data)[source]

Create a Patchset instance.

Return an instance of Patchset initialised with values from “patchSet” in json_data, or None if json_data does not contain “patchSet”.

class pygerrit.models.RefUpdate(json_data)[source]

Bases: object

Gerrit ref update.

ssh Module

Gerrit SSH Client.

class pygerrit.ssh.GerritSSHClient(hostname, username=None, port=None, keepalive=None)[source]

Bases: paramiko.client.SSHClient

Gerrit SSH Client, wrapping the paramiko SSH Client.

get_remote_info()[source]

Return the username, and version of the remote Gerrit server.

get_remote_version()[source]

Return the version of the remote Gerrit server.

run_gerrit_command(command)[source]

Run the given command.

Make sure we’re connected to the remote server, and run command.

Return the results as a GerritSSHCommandResult.

Raise ValueError if command is not a string, or GerritError if command execution fails.

class pygerrit.ssh.GerritSSHCommandResult(command, stdin, stdout, stderr)[source]

Bases: object

Represents the results of a Gerrit command run over SSH.

stream Module

Gerrit event stream interface.

Class to listen to the Gerrit event stream and dispatch events.

class pygerrit.stream.GerritStream(gerrit, ssh_client)[source]

Bases: threading.Thread

Gerrit events stream handler.

run()[source]

Listen to the stream and send events to the client.

stop()[source]

Stop the thread.

Table Of Contents

Previous topic

Welcome to Pygerrit’s documentation!

Next topic

rest Package

This Page