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

print progress when execute download command

上级 7d6054ba
...@@ -64,13 +64,12 @@ class DownloadCommand(BaseCommand): ...@@ -64,13 +64,12 @@ class DownloadCommand(BaseCommand):
print(tips) print(tips)
return True return True
self.print_args()
if self.args.uncompress: if self.args.uncompress:
result, tips, file = default_downloader.download_file_and_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: else:
result, tips, file = default_downloader.download_file( 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) print(tips)
return True return True
......
...@@ -77,9 +77,13 @@ class Downloader: ...@@ -77,9 +77,13 @@ class Downloader:
f.write(data) f.write(data)
if print_progress: if print_progress:
done = int(50 * dl / total_length) done = int(50 * dl / total_length)
sys.stdout.write( sys.stdout.write("\r%s : [%-50s]%.2f%%" %
"\r[%s%s]" % ('=' * done, ' ' * (50 - done))) (save_name, '=' * done,
float(dl / total_length * 100)))
sys.stdout.flush() sys.stdout.flush()
if print_progress:
sys.stdout.write("\n")
sys.stdout.flush()
tips = "file %s download completed!" % (file_name) tips = "file %s download completed!" % (file_name)
return True, tips, file_name return True, tips, file_name
...@@ -102,12 +106,14 @@ class Downloader: ...@@ -102,12 +106,14 @@ class Downloader:
save_path, save_path,
save_name=None, save_name=None,
retry_limit=3, retry_limit=3,
delete_file=True): delete_file=True,
print_progress=False):
result, tips_1, file = self.download_file( result, tips_1, file = self.download_file(
url=url, url=url,
save_path=save_path, save_path=save_path,
save_name=save_name, save_name=save_name,
retry_limit=retry_limit) retry_limit=retry_limit,
print_progress=print_progress)
if not result: if not result:
return result, tips_1, file return result, tips_1, file
result, tips_2, file = self.uncompress(file, delete_file=delete_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.
先完成此消息的编辑!
想要评论请 注册