23261178 userland-fetch relies on pypi too much if the archive is in the mirror
authorDanek Duvall <danek.duvall@oracle.com>
Tue, 10 May 2016 11:58:11 -0700
changeset 5953 de8c30ca3eaa
parent 5952 0ff1d1b8de45
child 5954 110aa94bc082
23261178 userland-fetch relies on pypi too much if the archive is in the mirror
tools/userland-fetch
--- a/tools/userland-fetch	Mon May 09 19:47:00 2016 -0700
+++ b/tools/userland-fetch	Tue May 10 11:58:11 2016 -0700
@@ -226,7 +226,8 @@
 		jsurl = "http://%s/pypi/%s/json" % (host, name)
 
 	try:
-		f = urlopen(jsurl)
+		# Don't wait very long for the connection
+		f = urlopen(jsurl, None, 2)
 	except HTTPError as e:
 		if e.getcode() == 404:
 			print "Unknown component '%s'" % name
@@ -281,11 +282,7 @@
 
 	# command line url is a fallback, so it's last
 	if url != None and url not in urls:
-		scheme, path = splittype(url)
-		if scheme == "pypi":
-			url = pypi_url(url, filename)
-		if url != None and url not in urls:
-			urls.append(url)
+		urls.append(url)
 
 	return urls
 
@@ -328,6 +325,22 @@
 				if not quiet:
 					print "failed"
 				continue
+		elif scheme == "pypi":
+			nurl = pypi_url(url, file_arg)
+			if nurl:
+				if not quiet:
+					print "\n    translated %s to %s..." % (
+					    url, nurl),
+					print "\n    downloading...",
+			else:
+				if not quiet:
+					print "\n    unable to contact PyPI",
+				continue
+			name = download(nurl, timeout_arg, file_arg, quiet)
+			if name is None:
+				if not quiet:
+					print "failed"
+				continue
 
 		yield name