Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """ | 5 """ |
| 6 Utilities for requesting information for a gerrit server via https. | 6 Utilities for requesting information for a gerrit server via https. |
| 7 | 7 |
| 8 https://gerrit-review.googlesource.com/Documentation/rest-api.html | 8 https://gerrit-review.googlesource.com/Documentation/rest-api.html |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import base64 | 11 import base64 |
| 12 import httplib | 12 import httplib |
| 13 import json | 13 import json |
| 14 import logging | 14 import logging |
| 15 import netrc | 15 import netrc |
| 16 import os | 16 import os |
| 17 import re | 17 import re |
| 18 import stat | |
| 19 import sys | |
| 18 import time | 20 import time |
| 19 import urllib | 21 import urllib |
| 20 from cStringIO import StringIO | 22 from cStringIO import StringIO |
| 21 | 23 |
| 24 _netrc_file = '_netrc' if sys.platform.startswith('win') else '.netrc' | |
| 25 _netrc_file = os.path.join(os.environ['HOME'], _netrc_file) | |
|
Michael Moss
2014/05/22 23:57:03
You mean the netrc module doesn't know how to do t
szager1
2014/05/23 08:52:18
I actually looked through the netrc.py code, on bo
| |
| 22 try: | 26 try: |
| 23 NETRC = netrc.netrc() | 27 NETRC = netrc.netrc(_netrc_file) |
| 24 except (IOError, netrc.NetrcParseError): | 28 except IOError: |
| 29 print >> sys.stderr, 'WARNING: Could not read netrc file %s' % _netrc_file | |
| 25 NETRC = netrc.netrc(os.devnull) | 30 NETRC = netrc.netrc(os.devnull) |
| 31 except netrc.NetrcParseError: | |
| 32 _netrc_stat = os.stat(_netrc_file) | |
|
Michael Moss
2014/05/22 23:57:03
FWIW, NetrcParseError.filename
szager1
2014/05/23 08:52:18
Done.
| |
| 33 if _netrc_stat.st_mode & (stat.S_IRWXG | stat.S_IRWXO): | |
| 34 print >> sys.stderr, ( | |
| 35 'WARNING: netrc file %s cannot be used because its file permissions ' | |
| 36 'are insecure. netrc file permissions should be 600.' % _netrc_file) | |
| 37 else: | |
| 38 print >> sys.stderr, ('WARNING: Cannot use netrc file %s due to a parsing ' | |
| 39 'error.' % _netrc_file) | |
|
Michael Moss
2014/05/22 23:57:03
If you print the exception, it will give a bit mor
szager1
2014/05/23 08:52:18
Actually, I think the right thing to do is to re-r
| |
| 40 del _netrc_stat | |
| 41 NETRC = netrc.netrc(os.devnull) | |
| 42 del _netrc_file | |
| 43 | |
| 26 LOGGER = logging.getLogger() | 44 LOGGER = logging.getLogger() |
| 27 TRY_LIMIT = 5 | 45 TRY_LIMIT = 5 |
| 28 | 46 |
| 29 # Controls the transport protocol used to communicate with gerrit. | 47 # Controls the transport protocol used to communicate with gerrit. |
| 30 # This is parameterized primarily to enable GerritTestCase. | 48 # This is parameterized primarily to enable GerritTestCase. |
| 31 GERRIT_PROTOCOL = 'https' | 49 GERRIT_PROTOCOL = 'https' |
| 32 | 50 |
| 33 | 51 |
| 34 class GerritError(Exception): | 52 class GerritError(Exception): |
| 35 """Exception class for errors commuicating with the gerrit-on-borg service.""" | 53 """Exception class for errors commuicating with the gerrit-on-borg service.""" |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 446 username = review.get('email', jmsg.get('name', '')) | 464 username = review.get('email', jmsg.get('name', '')) |
| 447 raise GerritError(200, 'Unable to set %s label for user "%s"' | 465 raise GerritError(200, 'Unable to set %s label for user "%s"' |
| 448 ' on change %s.' % (label, username, change)) | 466 ' on change %s.' % (label, username, change)) |
| 449 jmsg = GetChangeCurrentRevision(host, change) | 467 jmsg = GetChangeCurrentRevision(host, change) |
| 450 if not jmsg: | 468 if not jmsg: |
| 451 raise GerritError( | 469 raise GerritError( |
| 452 200, 'Could not get review information for change "%s"' % change) | 470 200, 'Could not get review information for change "%s"' % change) |
| 453 elif jmsg[0]['current_revision'] != revision: | 471 elif jmsg[0]['current_revision'] != revision: |
| 454 raise GerritError(200, 'While resetting labels on change "%s", ' | 472 raise GerritError(200, 'While resetting labels on change "%s", ' |
| 455 'a new patchset was uploaded.' % change) | 473 'a new patchset was uploaded.' % change) |
| OLD | NEW |