MCPcopy Create free account
hub / github.com/pytorch/pytorch / downloadFromURLToFile

Function downloadFromURLToFile

caffe2/python/models/download.py:50–75  ·  view source on GitHub ↗
(url, filename, show_progress=True)

Source from the content-addressed store, hash-verified

48
49
50def downloadFromURLToFile(url, filename, show_progress=True):
51 try:
52 print("Downloading from {url}".format(url=url))
53 response = urllib.urlopen(url)
54 size = int(response.info().get('Content-Length').strip())
55 chunk = min(size, 8192)
56 print("Writing to {filename}".format(filename=filename))
57 if show_progress:
58 downloaded_size = 0
59 progressBar(0)
60 with open(filename, "wb") as local_file:
61 while True:
62 data_chunk = response.read(chunk)
63 if not data_chunk:
64 break
65 local_file.write(data_chunk)
66 if show_progress:
67 downloaded_size += len(data_chunk)
68 progressBar(int(100 * downloaded_size / size))
69 print("") # New line to fix for progress bar
70 except HTTPError as e:
71 raise Exception("Could not download model. [HTTP Error] {code}: {reason}."
72 .format(code=e.code, reason=e.reason)) from e
73 except URLError as e:
74 raise Exception("Could not download model. [URL Error] {reason}."
75 .format(reason=e.reason)) from e
76
77
78def getURLFromName(name, filename):

Callers 4

_downloadMethod · 0.90
download_caffe2_modelFunction · 0.90
downloadModelFunction · 0.85
_downloadMethod · 0.85

Calls 9

progressBarFunction · 0.85
ExceptionClass · 0.85
stripMethod · 0.80
infoMethod · 0.80
minFunction · 0.50
formatMethod · 0.45
getMethod · 0.45
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…