Ryan10145 has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/401199 )
Change subject: Added Progress Bar for download_dump.py ...................................................................... Added Progress Bar for download_dump.py Bug: T183664 Change-Id: Iacfc4ffec3f7b928fa245879c154775a9f692b8a --- M scripts/maintenance/download_dump.py 1 file changed, 31 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/99/401199/1 diff --git a/scripts/maintenance/download_dump.py b/scripts/maintenance/download_dump.py index 853d33f..a9985d1 100644 --- a/scripts/maintenance/download_dump.py +++ b/scripts/maintenance/download_dump.py @@ -119,8 +119,39 @@ response = fetch(url, stream=True) if response.status == 200: with open(file_current_storepath, 'wb') as result_file: + total = int(response.response_headers.get( + 'content-length')) + downloaded = 0 + parts = 50 + B_IN_GB = 1073741824 + B_IN_MB = 1048576 + for data in response.data.iter_content(100 * 1024): result_file.write(data) + + if total is not None: + downloaded += len(data) + done = int(parts * downloaded / + total) + sys.stdout.write("\r|{0}{1}|".format( + '=' * done, '-' * (parts - done))) + + # Format the data size display with units + disp_total = ( + format(total / B_IN_MB, '.2f') + + 'M', + format(total / B_IN_GB, '.2f') + + 'G')[total > B_IN_GB] + disp_downloaded = ( + format(downloaded / B_IN_MB, '.2f') + + 'M', + format(downloaded / B_IN_GB, '.2f') + + 'G')[downloaded > B_IN_GB] + + sys.stdout.write('\t{0}/{1}'.format( + disp_downloaded, disp_total)) + sys.stdout.flush() + sys.stdout.write('\n') elif response.status == 404: pywikibot.output( 'File with name "{filename}", ' -- To view, visit https://gerrit.wikimedia.org/r/401199 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iacfc4ffec3f7b928fa245879c154775a9f692b8a Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Ryan10145 <chang.ryan10...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits