Skip to content

Commit

Permalink
Merge pull request #331 from AlbertDeFusco/project-download-progress
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertDeFusco committed Jul 9, 2021
2 parents a35a2f2 + 35774f5 commit 212256e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
7 changes: 6 additions & 1 deletion anaconda_project/archiver.py
Expand Up @@ -21,8 +21,9 @@
import zipfile
from io import BytesIO
from conda_pack._progress import progressbar
from tqdm import tqdm

from anaconda_project.frontend import _new_error_recorder
from anaconda_project.frontend import NullFrontend, _new_error_recorder
from anaconda_project.internal import logged_subprocess
from anaconda_project.internal.simple_status import SimpleStatus
from anaconda_project.internal.directory_contains import subdirectory_relative_to_directory
Expand Down Expand Up @@ -452,6 +453,8 @@ def _extract_files_zip(zip_path, src_and_dest, frontend):
try:
with zipfile.ZipFile(zip_path, mode='r') as zf:
_extractall_chmod(zf, tmpdir)
if isinstance(frontend.underlying, NullFrontend):
src_and_dest = tqdm(src_and_dest, desc='Extract ')
for (src, dest) in src_and_dest:
frontend.info("Unpacking %s to %s" % (src, dest))
src_path = os.path.join(tmpdir, src)
Expand All @@ -470,6 +473,8 @@ def _extract_files_zip(zip_path, src_and_dest, frontend):

def _extract_files_tar(tar_path, src_and_dest, frontend):
with tarfile.open(tar_path, mode='r') as tf:
if isinstance(frontend.underlying, NullFrontend):
src_and_dest = tqdm(src_and_dest, desc='Extract ')
for (src, dest) in src_and_dest:
frontend.info("Unpacking %s to %s" % (src, dest))
member = tf.getmember(src)
Expand Down
13 changes: 8 additions & 5 deletions anaconda_project/client.py
Expand Up @@ -13,6 +13,7 @@
import re
import tarfile
import zipfile
from tqdm import tqdm

import requests
import binstar_client.utils as binstar_utils
Expand Down Expand Up @@ -182,14 +183,16 @@ def download(self, project, project_dir=None, parent_dir=None):
filename = eval(re.findall("filename=(.+);", res.headers["Content-Disposition"])[0])
if parent_dir:
filename = os.path.join(parent_dir, filename)
print('Downloading {}'.format(project))
print('.', end='')
progress = tqdm(unit='KiB',
total=int(res.headers.get('Content-Length', None)) / 1024,
unit_scale=True,
desc='Download')
with open(filename, 'wb') as f:
for chunk in res.iter_content(chunk_size=4096):
for chunk in res.iter_content(chunk_size=1024):
if chunk:
print('.', end='')
progress.update(len(chunk) / 1024)
f.write(chunk)
print()
progress.close()
self._check_response(res)
return os.path.abspath(filename)

Expand Down

0 comments on commit 212256e

Please sign in to comment.