diff options
Diffstat (limited to 'git_config.py')
-rw-r--r-- | git_config.py | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/git_config.py b/git_config.py index ae288558..56cc6a24 100644 --- a/git_config.py +++ b/git_config.py | |||
@@ -13,6 +13,7 @@ | |||
13 | # See the License for the specific language governing permissions and | 13 | # See the License for the specific language governing permissions and |
14 | # limitations under the License. | 14 | # limitations under the License. |
15 | 15 | ||
16 | from __future__ import print_function | ||
16 | import cPickle | 17 | import cPickle |
17 | import os | 18 | import os |
18 | import re | 19 | import re |
@@ -23,7 +24,18 @@ try: | |||
23 | except ImportError: | 24 | except ImportError: |
24 | import dummy_threading as _threading | 25 | import dummy_threading as _threading |
25 | import time | 26 | import time |
26 | import urllib2 | 27 | try: |
28 | import urllib2 | ||
29 | except ImportError: | ||
30 | # For python3 | ||
31 | import urllib.request | ||
32 | import urllib.error | ||
33 | else: | ||
34 | # For python2 | ||
35 | import imp | ||
36 | urllib = imp.new_module('urllib') | ||
37 | urllib.request = urllib2 | ||
38 | urllib.error = urllib2 | ||
27 | 39 | ||
28 | from signal import SIGTERM | 40 | from signal import SIGTERM |
29 | from error import GitError, UploadError | 41 | from error import GitError, UploadError |
@@ -35,7 +47,7 @@ from git_command import terminate_ssh_clients | |||
35 | 47 | ||
36 | R_HEADS = 'refs/heads/' | 48 | R_HEADS = 'refs/heads/' |
37 | R_TAGS = 'refs/tags/' | 49 | R_TAGS = 'refs/tags/' |
38 | ID_RE = re.compile('^[0-9a-f]{40}$') | 50 | ID_RE = re.compile(r'^[0-9a-f]{40}$') |
39 | 51 | ||
40 | REVIEW_CACHE = dict() | 52 | REVIEW_CACHE = dict() |
41 | 53 | ||
@@ -157,7 +169,7 @@ class GitConfig(object): | |||
157 | elif old != value: | 169 | elif old != value: |
158 | self._cache[key] = list(value) | 170 | self._cache[key] = list(value) |
159 | self._do('--replace-all', name, value[0]) | 171 | self._do('--replace-all', name, value[0]) |
160 | for i in xrange(1, len(value)): | 172 | for i in range(1, len(value)): |
161 | self._do('--add', name, value[i]) | 173 | self._do('--add', name, value[i]) |
162 | 174 | ||
163 | elif len(old) != 1 or old[0] != value: | 175 | elif len(old) != 1 or old[0] != value: |
@@ -288,12 +300,13 @@ class GitConfig(object): | |||
288 | d = self._do('--null', '--list') | 300 | d = self._do('--null', '--list') |
289 | if d is None: | 301 | if d is None: |
290 | return c | 302 | return c |
291 | for line in d.rstrip('\0').split('\0'): | 303 | for line in d.rstrip('\0').split('\0'): # pylint: disable=W1401 |
304 | # Backslash is not anomalous | ||
292 | if '\n' in line: | 305 | if '\n' in line: |
293 | key, val = line.split('\n', 1) | 306 | key, val = line.split('\n', 1) |
294 | else: | 307 | else: |
295 | key = line | 308 | key = line |
296 | val = None | 309 | val = None |
297 | 310 | ||
298 | if key in c: | 311 | if key in c: |
299 | c[key].append(val) | 312 | c[key].append(val) |
@@ -418,7 +431,7 @@ def _open_ssh(host, port=None): | |||
418 | '-o','ControlPath %s' % ssh_sock(), | 431 | '-o','ControlPath %s' % ssh_sock(), |
419 | host] | 432 | host] |
420 | if port is not None: | 433 | if port is not None: |
421 | command_base[1:1] = ['-p',str(port)] | 434 | command_base[1:1] = ['-p', str(port)] |
422 | 435 | ||
423 | # Since the key wasn't in _master_keys, we think that master isn't running. | 436 | # Since the key wasn't in _master_keys, we think that master isn't running. |
424 | # ...but before actually starting a master, we'll double-check. This can | 437 | # ...but before actually starting a master, we'll double-check. This can |
@@ -451,9 +464,8 @@ def _open_ssh(host, port=None): | |||
451 | p = subprocess.Popen(command) | 464 | p = subprocess.Popen(command) |
452 | except Exception as e: | 465 | except Exception as e: |
453 | _ssh_master = False | 466 | _ssh_master = False |
454 | print >>sys.stderr, \ | 467 | print('\nwarn: cannot enable ssh control master for %s:%s\n%s' |
455 | '\nwarn: cannot enable ssh control master for %s:%s\n%s' \ | 468 | % (host,port, str(e)), file=sys.stderr) |
456 | % (host,port, str(e)) | ||
457 | return False | 469 | return False |
458 | 470 | ||
459 | _master_processes.append(p) | 471 | _master_processes.append(p) |
@@ -525,7 +537,7 @@ class Remote(object): | |||
525 | self.url = self._Get('url') | 537 | self.url = self._Get('url') |
526 | self.review = self._Get('review') | 538 | self.review = self._Get('review') |
527 | self.projectname = self._Get('projectname') | 539 | self.projectname = self._Get('projectname') |
528 | self.fetch = map(lambda x: RefSpec.FromString(x), | 540 | self.fetch = map(RefSpec.FromString, |
529 | self._Get('fetch', all_keys=True)) | 541 | self._Get('fetch', all_keys=True)) |
530 | self._review_url = None | 542 | self._review_url = None |
531 | 543 | ||
@@ -579,7 +591,7 @@ class Remote(object): | |||
579 | else: | 591 | else: |
580 | try: | 592 | try: |
581 | info_url = u + 'ssh_info' | 593 | info_url = u + 'ssh_info' |
582 | info = urllib2.urlopen(info_url).read() | 594 | info = urllib.request.urlopen(info_url).read() |
583 | if '<' in info: | 595 | if '<' in info: |
584 | # Assume the server gave us some sort of HTML | 596 | # Assume the server gave us some sort of HTML |
585 | # response back, like maybe a login page. | 597 | # response back, like maybe a login page. |
@@ -592,9 +604,9 @@ class Remote(object): | |||
592 | else: | 604 | else: |
593 | host, port = info.split() | 605 | host, port = info.split() |
594 | self._review_url = self._SshReviewUrl(userEmail, host, port) | 606 | self._review_url = self._SshReviewUrl(userEmail, host, port) |
595 | except urllib2.HTTPError as e: | 607 | except urllib.error.HTTPError as e: |
596 | raise UploadError('%s: %s' % (self.review, str(e))) | 608 | raise UploadError('%s: %s' % (self.review, str(e))) |
597 | except urllib2.URLError as e: | 609 | except urllib.error.URLError as e: |
598 | raise UploadError('%s: %s' % (self.review, str(e))) | 610 | raise UploadError('%s: %s' % (self.review, str(e))) |
599 | 611 | ||
600 | REVIEW_CACHE[u] = self._review_url | 612 | REVIEW_CACHE[u] = self._review_url |
@@ -645,7 +657,7 @@ class Remote(object): | |||
645 | self._Set('url', self.url) | 657 | self._Set('url', self.url) |
646 | self._Set('review', self.review) | 658 | self._Set('review', self.review) |
647 | self._Set('projectname', self.projectname) | 659 | self._Set('projectname', self.projectname) |
648 | self._Set('fetch', map(lambda x: str(x), self.fetch)) | 660 | self._Set('fetch', map(str, self.fetch)) |
649 | 661 | ||
650 | def _Set(self, key, value): | 662 | def _Set(self, key, value): |
651 | key = 'remote.%s.%s' % (self.name, key) | 663 | key = 'remote.%s.%s' % (self.name, key) |