(url, filename, show_progress=True)
| 48 | |
| 49 | |
| 50 | def 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 | |
| 78 | def getURLFromName(name, filename): |
no test coverage detected
searching dependent graphs…