Skip to content

Commit 32b9a33

Browse files
committed
Add progress bar to parity download
1 parent 95869af commit 32b9a33

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ before_script:
7676
- if [ -n "$GETH_VERSION" ] && [ ! -e "$GETH_BINARY" ]; then python -m geth.install $GETH_VERSION; fi
7777
- if [ -n "$GETH_VERSION" ]; then $GETH_BINARY version; fi
7878
- if [ -n "$GETH_VERSION" ]; then $GETH_BINARY makedag 0 $HOME/.ethash; fi
79+
- if [ -n "$PARITY_VERSION" ]; then python tests/integration/install_parity.py $PARITY_VERSION; fi
7980
- pip freeze
8081
script:
8182
- tox $TOX_POSARGS

requirements-dev.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ pytest-pythonpath>=0.3
88
pytest-watch==4.*
99
pytest-xdist==1.*
1010
tox>=1.8.0
11+
tqdm
1112
when-changed

tests/integration/install_parity.py

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import hashlib
22
import os
3+
import sys
34
import stat
5+
from tqdm import tqdm
46

57
from eth_utils import (
68
to_tuple,
@@ -66,13 +68,19 @@ def install_parity(version_string):
6668

6769

6870
def download_binary(path, uri, checksum):
69-
bin_stream = get_binary_stream(uri)
71+
r = get_binary_stream(uri)
72+
total_size = int(r.headers.get('content-length', 0));
7073
os.makedirs(os.path.dirname(path), exist_ok=True)
7174
digest = hashlib.md5()
7275
with open(path, 'wb') as f:
73-
for chunk in bin_stream:
74-
f.write(chunk)
75-
digest.update(chunk)
76+
with tqdm(total=total_size,
77+
unit='B',
78+
unit_scale=True,
79+
unit_divisor=1024) as pbar:
80+
for data in r.iter_content(32*1024):
81+
f.write(data);
82+
pbar.update(len(data))
83+
digest.update(data)
7684
assert digest.hexdigest() == checksum
7785
chmod_plus_x(path)
7886

@@ -85,6 +93,10 @@ def chmod_plus_x(executable_path):
8593
def get_binary_stream(uri):
8694
resp = requests.get(uri, stream=True)
8795
if resp.status_code == 200:
88-
return resp.raw
96+
return resp
8997
else:
9098
resp.raise_for_status()
99+
100+
101+
if __name__ == '__main__':
102+
install_parity(sys.argv[1])

0 commit comments

Comments
 (0)