summaryrefslogtreecommitdiffstats
path: root/repo
diff options
context:
space:
mode:
Diffstat (limited to 'repo')
-rwxr-xr-xrepo33
1 files changed, 22 insertions, 11 deletions
diff --git a/repo b/repo
index 9643a225..1b809087 100755
--- a/repo
+++ b/repo
@@ -123,7 +123,18 @@ import re
123import stat 123import stat
124import subprocess 124import subprocess
125import sys 125import sys
126import urllib2 126try:
127 import urllib2
128except ImportError:
129 # For python3
130 import urllib.request
131 import urllib.error
132else:
133 # For python2
134 import imp
135 urllib = imp.new_module('urllib')
136 urllib.request = urllib2
137 urllib.error = urllib2
127 138
128home_dot_repo = os.path.expanduser('~/.repoconfig') 139home_dot_repo = os.path.expanduser('~/.repoconfig')
129gpg_dir = os.path.join(home_dot_repo, 'gnupg') 140gpg_dir = os.path.join(home_dot_repo, 'gnupg')
@@ -356,7 +367,7 @@ def _SetConfig(local, name, value):
356def _InitHttp(): 367def _InitHttp():
357 handlers = [] 368 handlers = []
358 369
359 mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() 370 mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
360 try: 371 try:
361 import netrc 372 import netrc
362 n = netrc.netrc() 373 n = netrc.netrc()
@@ -366,16 +377,16 @@ def _InitHttp():
366 mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2]) 377 mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2])
367 except: 378 except:
368 pass 379 pass
369 handlers.append(urllib2.HTTPBasicAuthHandler(mgr)) 380 handlers.append(urllib.request.HTTPBasicAuthHandler(mgr))
370 handlers.append(urllib2.HTTPDigestAuthHandler(mgr)) 381 handlers.append(urllib.request.HTTPDigestAuthHandler(mgr))
371 382
372 if 'http_proxy' in os.environ: 383 if 'http_proxy' in os.environ:
373 url = os.environ['http_proxy'] 384 url = os.environ['http_proxy']
374 handlers.append(urllib2.ProxyHandler({'http': url, 'https': url})) 385 handlers.append(urllib.request.ProxyHandler({'http': url, 'https': url}))
375 if 'REPO_CURL_VERBOSE' in os.environ: 386 if 'REPO_CURL_VERBOSE' in os.environ:
376 handlers.append(urllib2.HTTPHandler(debuglevel=1)) 387 handlers.append(urllib.request.HTTPHandler(debuglevel=1))
377 handlers.append(urllib2.HTTPSHandler(debuglevel=1)) 388 handlers.append(urllib.request.HTTPSHandler(debuglevel=1))
378 urllib2.install_opener(urllib2.build_opener(*handlers)) 389 urllib.request.install_opener(urllib.request.build_opener(*handlers))
379 390
380def _Fetch(url, local, src, quiet): 391def _Fetch(url, local, src, quiet):
381 if not quiet: 392 if not quiet:
@@ -424,14 +435,14 @@ def _DownloadBundle(url, local, quiet):
424 dest = open(os.path.join(local, '.git', 'clone.bundle'), 'w+b') 435 dest = open(os.path.join(local, '.git', 'clone.bundle'), 'w+b')
425 try: 436 try:
426 try: 437 try:
427 r = urllib2.urlopen(url) 438 r = urllib.request.urlopen(url)
428 except urllib2.HTTPError as e: 439 except urllib.error.HTTPError as e:
429 if e.code == 404: 440 if e.code == 404:
430 return False 441 return False
431 print >>sys.stderr, 'fatal: Cannot get %s' % url 442 print >>sys.stderr, 'fatal: Cannot get %s' % url
432 print >>sys.stderr, 'fatal: HTTP error %s' % e.code 443 print >>sys.stderr, 'fatal: HTTP error %s' % e.code
433 raise CloneFailure() 444 raise CloneFailure()
434 except urllib2.URLError as e: 445 except urllib.error.URLError as e:
435 print >>sys.stderr, 'fatal: Cannot get %s' % url 446 print >>sys.stderr, 'fatal: Cannot get %s' % url
436 print >>sys.stderr, 'fatal: error %s' % e.reason 447 print >>sys.stderr, 'fatal: error %s' % e.reason
437 raise CloneFailure() 448 raise CloneFailure()