Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display download bar in all cases and make the timeout configurable via an env var #401

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions anaconda_project/internal/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, url, filename, hash_algorithm=None):
self._client = None
self._errors = []
self._progress = None
self._progress_kwargs = None

@gen.coroutine
def run(self):
Expand Down Expand Up @@ -94,15 +95,24 @@ def writer(chunk):
self._errors.append("Failed to write to %s: %s" % (tmp_filename, e))

def read_header(line):
if 'content-length' in line.lower():
file_size = int(line.split(':')[1]) / 1024 / 1024
self._progress = tqdm(unit='MiB',
total=file_size,
unit_scale=True,
desc=os.path.basename(self._filename))
# Display basic progress stats when the response has no Content-Length.
if self._progress_kwargs is None:
self._progress_kwargs = dict(
unit='MiB',
unit_scale=True,
desc=os.path.basename(self._filename),
)
elif 'content-length' in line.lower():
self._progress_kwargs['total'] = int(line.split(':')[1]) / 1024 / 1024
# Last line of the header
if line == "\r\n":
self._progress = tqdm(**self._progress_kwargs)

try:
timeout_in_seconds = 60 * 10 # pretty long because we could be dealing with huge files
timeout_in_seconds = int(os.getenv(
'ANACONDA_PROJECT_DOWNLOADS_TIMEOUT',
60 * 10 # pretty long because we could be dealing with huge files
))
request = httpclient.HTTPRequest(url=self._url,
header_callback=read_header,
streaming_callback=writer,
Expand Down
Loading