提交 124b289a 编写于 作者: W wuzewu

print progress when execute download command

上级 7d6054ba
......@@ -64,13 +64,12 @@ class DownloadCommand(BaseCommand):
print(tips)
return True
self.print_args()
if self.args.uncompress:
result, tips, file = default_downloader.download_file_and_uncompress(
url=url, save_path=self.args.output_path)
url=url, save_path=self.args.output_path, print_progress=True)
else:
result, tips, file = default_downloader.download_file(
url=url, save_path=self.args.output_path)
url=url, save_path=self.args.output_path, print_progress=True)
print(tips)
return True
......
......@@ -77,9 +77,13 @@ class Downloader:
f.write(data)
if print_progress:
done = int(50 * dl / total_length)
sys.stdout.write(
"\r[%s%s]" % ('=' * done, ' ' * (50 - done)))
sys.stdout.write("\r%s : [%-50s]%.2f%%" %
(save_name, '=' * done,
float(dl / total_length * 100)))
sys.stdout.flush()
if print_progress:
sys.stdout.write("\n")
sys.stdout.flush()
tips = "file %s download completed!" % (file_name)
return True, tips, file_name
......@@ -102,12 +106,14 @@ class Downloader:
save_path,
save_name=None,
retry_limit=3,
delete_file=True):
delete_file=True,
print_progress=False):
result, tips_1, file = self.download_file(
url=url,
save_path=save_path,
save_name=save_name,
retry_limit=retry_limit)
retry_limit=retry_limit,
print_progress=print_progress)
if not result:
return result, tips_1, file
result, tips_2, file = self.uncompress(file, delete_file=delete_file)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册