Index: gerrit_util.py |
diff --git a/gerrit_util.py b/gerrit_util.py |
index 7c44f03107468de934940bd1bf7646630818c53f..78998e7f547c871b3d74dea7175b73e51f65f201 100755 |
--- a/gerrit_util.py |
+++ b/gerrit_util.py |
@@ -65,11 +65,14 @@ def CreateHttpConn(host, path, reqtype='GET', headers=None, body=None): |
headers = headers or {} |
bare_host = host.partition(':')[0] |
auth = NETRC.authenticators(bare_host) |
+ |
if auth: |
headers.setdefault('Authorization', 'Basic %s' % ( |
base64.b64encode('%s:%s' % (auth[0], auth[2])))) |
+ url = '/a/%s' % path |
szager1
2013/10/31 18:15:45
It's always possible that the Authorization header
deymo
2013/10/31 20:42:12
Done.
|
else: |
LOGGER.debug('No authorization found') |
+ url = '/%s' % path |
if body: |
body = json.JSONEncoder().encode(body) |
headers.setdefault('Content-Type', 'application/json') |
@@ -84,7 +87,7 @@ def CreateHttpConn(host, path, reqtype='GET', headers=None, body=None): |
conn = GetConnectionClass()(host) |
conn.req_host = host |
conn.req_params = { |
- 'url': '/a/%s' % path, |
+ 'url': url, |
'method': reqtype, |
'headers': headers, |
'body': body, |
@@ -180,6 +183,42 @@ def QueryChanges(host, param_dict, first_param=None, limit=None, o_params=None, |
return ReadHttpJsonResponse(CreateHttpConn(host, path), ignore_404=False) |
+def QueryAllChanges(host, param_dict, first_param=None, limit=500, |
szager1
2013/10/31 18:15:45
This method name is not suggestive of what the cod
deymo
2013/10/31 20:42:12
The point of having the documentation here is that
|
+ o_params=None, sortkey=None): |
+ """ |
+ Queries a gerrit-on-borg server for all the changes matching the query terms. |
+ |
+ A single query to gerrit-on-borg is limited on the number of results by the |
+ limit parameter on the request (see QueryChanges) and the server maximum |
+ limit. This function uses the "_more_changes" and "_sortkey" attributes on |
+ the returned changes to iterate all of them making multiple queries to the |
+ server, regardless the query limit. |
+ |
+ Args: |
+ param_dict: A dictionary of search parameters, as documented here: |
+ http://gerrit-documentation.googlecode.com/svn/Documentation/2.6/user-search.html |
+ first_param: A change identifier. |
+ limit: Maximum number of requested changes per query. |
+ o_params: A list of additional output specifiers, as documented here: |
+ https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes |
+ sortkey: The value of the "_sortkey" attribute where starts from. None to |
+ start from the first change. |
+ |
+ Returns: |
+ A generator object to the list of returned changes, possibly unbound. |
+ """ |
+ more_changes = True |
+ while more_changes: |
+ page = QueryChanges(host, param_dict, first_param, limit, o_params, sortkey) |
+ for cl in page: |
+ yield cl |
+ |
+ more_changes = [cl for cl in page if '_more_changes' in cl] |
szager1
2013/10/31 18:15:45
This logic is a bit obscure, since '_more_changes'
deymo
2013/10/31 20:42:12
I try to avoid the "while True:" loops with breaks
|
+ sortkey = None |
+ if more_changes: |
+ sortkey = more_changes[0]['_sortkey'] |
+ |
+ |
def MultiQueryChanges(host, param_dict, change_list, limit=None, o_params=None, |
sortkey=None): |
"""Initiate a query composed of multiple sets of query parameters.""" |