Add better progress information output for long operation.
Checking sha256sum and downloading file can be pretty long. Let's print few information to the user.
This commit is contained in:
parent
7d62d16154
commit
c8f5acb41f
|
@ -15,6 +15,7 @@ from utils import (
|
||||||
remove_duplicates,
|
remove_duplicates,
|
||||||
add_execution_right,
|
add_execution_right,
|
||||||
get_sha256,
|
get_sha256,
|
||||||
|
print_status,
|
||||||
StopBuild,
|
StopBuild,
|
||||||
SkipCommand,
|
SkipCommand,
|
||||||
Defaultdict,
|
Defaultdict,
|
||||||
|
@ -440,11 +441,22 @@ class BuildEnv:
|
||||||
context = None
|
context = None
|
||||||
batch_size = 1024 * 8
|
batch_size = 1024 * 8
|
||||||
extra_args = {'context':context} if sys.version_info >= (3, 4, 3) else {}
|
extra_args = {'context':context} if sys.version_info >= (3, 4, 3) else {}
|
||||||
|
progress_chars = "/-\|"
|
||||||
with urllib.request.urlopen(file_url, **extra_args) as resource, open(file_path, 'wb') as file:
|
with urllib.request.urlopen(file_url, **extra_args) as resource, open(file_path, 'wb') as file:
|
||||||
|
tsize = resource.getheader('Content-Length', None)
|
||||||
|
if tsize is not None:
|
||||||
|
tsize = int(tsize)
|
||||||
|
current = 0
|
||||||
while True:
|
while True:
|
||||||
batch = resource.read(batch_size)
|
batch = resource.read(batch_size)
|
||||||
if not batch:
|
if not batch:
|
||||||
break
|
break
|
||||||
|
if tsize:
|
||||||
|
current += batch_size
|
||||||
|
print_status("{:.2%}".format(current/tsize))
|
||||||
|
else:
|
||||||
|
print_status(progress_chars[current])
|
||||||
|
current = (current+1)%4
|
||||||
file.write(batch)
|
file.write(batch)
|
||||||
|
|
||||||
if not what.sha256:
|
if not what.sha256:
|
||||||
|
|
14
utils.py
14
utils.py
|
@ -27,11 +27,23 @@ def remove_duplicates(iterable, key_function=None):
|
||||||
|
|
||||||
|
|
||||||
def get_sha256(path):
|
def get_sha256(path):
|
||||||
|
progress_chars = "/-\|"
|
||||||
|
current = 0
|
||||||
|
batch_size = 1024 * 8
|
||||||
sha256 = hashlib.sha256()
|
sha256 = hashlib.sha256()
|
||||||
with open(path, 'br') as f:
|
with open(path, 'br') as f:
|
||||||
sha256.update(f.read())
|
while True:
|
||||||
|
batch = f.read(batch_size)
|
||||||
|
if not batch:
|
||||||
|
break
|
||||||
|
sha256.update(batch)
|
||||||
|
print_status(progress_chars[current])
|
||||||
|
current = (current+1)%4
|
||||||
return sha256.hexdigest()
|
return sha256.hexdigest()
|
||||||
|
|
||||||
|
def print_status(status):
|
||||||
|
text = "{}\033[{}D".format(status, len(status))
|
||||||
|
print(text, end="")
|
||||||
|
|
||||||
def add_execution_right(file_path):
|
def add_execution_right(file_path):
|
||||||
current_permissions = stat.S_IMODE(os.lstat(file_path).st_mode)
|
current_permissions = stat.S_IMODE(os.lstat(file_path).st_mode)
|
||||||
|
|
Loading…
Reference in New Issue