tools/upip: Update to 1.1.5. Better and more user-friendly error handling.
This commit is contained in:
parent
e08395a35c
commit
aac2db9aaf
tools
|
@ -105,7 +105,10 @@ warn_ussl = True
|
||||||
def url_open(url):
|
def url_open(url):
|
||||||
global warn_ussl
|
global warn_ussl
|
||||||
proto, _, host, urlpath = url.split('/', 3)
|
proto, _, host, urlpath = url.split('/', 3)
|
||||||
ai = usocket.getaddrinfo(host, 443)
|
try:
|
||||||
|
ai = usocket.getaddrinfo(host, 443)
|
||||||
|
except OSError as e:
|
||||||
|
fatal("Unable to resolve %s (no Internet?)" % host, e)
|
||||||
#print("Address infos:", ai)
|
#print("Address infos:", ai)
|
||||||
addr = ai[0][4]
|
addr = ai[0][4]
|
||||||
|
|
||||||
|
@ -124,13 +127,16 @@ def url_open(url):
|
||||||
l = s.readline()
|
l = s.readline()
|
||||||
protover, status, msg = l.split(None, 2)
|
protover, status, msg = l.split(None, 2)
|
||||||
if status != b"200":
|
if status != b"200":
|
||||||
|
s.close()
|
||||||
|
exc = ValueError(status)
|
||||||
if status == b"404":
|
if status == b"404":
|
||||||
print("Package not found")
|
fatal("Package not found", exc)
|
||||||
raise ValueError(status)
|
fatal("Unexpected error querying for package", exc)
|
||||||
while 1:
|
while 1:
|
||||||
l = s.readline()
|
l = s.readline()
|
||||||
if not l:
|
if not l:
|
||||||
raise ValueError("Unexpected EOF")
|
s.close()
|
||||||
|
fatal("Unexpected EOF in HTTP headers", ValueError())
|
||||||
if l == b'\r\n':
|
if l == b'\r\n':
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -144,8 +150,10 @@ def get_pkg_metadata(name):
|
||||||
return json.loads(s)
|
return json.loads(s)
|
||||||
|
|
||||||
|
|
||||||
def fatal(msg):
|
def fatal(msg, exc=None):
|
||||||
print(msg)
|
print("Error:", msg)
|
||||||
|
if exc and debug:
|
||||||
|
raise exc
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def install_pkg(pkg_spec, install_path):
|
def install_pkg(pkg_spec, install_path):
|
||||||
|
|
Loading…
Reference in New Issue