|
13 | 13 | # limitations under the License. |
14 | 14 | from __future__ import absolute_import, unicode_literals, print_function |
15 | 15 |
|
16 | | -from clint.textui.progress import Bar as ProgressBar |
| 16 | +from tqdm import tqdm as tqdm |
17 | 17 |
|
18 | 18 | import requests |
19 | 19 | from requests import adapters |
|
33 | 33 | OLD_WAREHOUSE = 'https://upload.pypi.io/' |
34 | 34 |
|
35 | 35 |
|
| 36 | +class ProgressBar(tqdm): |
| 37 | + |
| 38 | + def update_to(self, n): |
| 39 | + """ |
| 40 | + identical to update, except `n` should be current value and not delta. |
| 41 | + """ |
| 42 | + self.update(n - self.n) |
| 43 | + |
| 44 | + |
36 | 45 | class Repository(object): |
37 | 46 | def __init__(self, repository_url, username, password): |
38 | 47 | self.url = repository_url |
@@ -121,18 +130,18 @@ def _upload(self, package): |
121 | 130 | (package.basefilename, fp, "application/octet-stream"), |
122 | 131 | )) |
123 | 132 | encoder = MultipartEncoder(data_to_send) |
124 | | - bar = ProgressBar(expected_size=encoder.len, filled_char='=') |
125 | | - monitor = MultipartEncoderMonitor( |
126 | | - encoder, lambda monitor: bar.show(monitor.bytes_read) |
127 | | - ) |
128 | | - |
129 | | - resp = self.session.post( |
130 | | - self.url, |
131 | | - data=monitor, |
132 | | - allow_redirects=False, |
133 | | - headers={'Content-Type': monitor.content_type}, |
134 | | - ) |
135 | | - bar.done() |
| 133 | + with ProgressBar(total=encoder.len, unit='bytes', |
| 134 | + unit_scale=True, leave=False) as bar: |
| 135 | + monitor = MultipartEncoderMonitor( |
| 136 | + encoder, lambda monitor: bar.update_to(monitor.bytes_read) |
| 137 | + ) |
| 138 | + |
| 139 | + resp = self.session.post( |
| 140 | + self.url, |
| 141 | + data=monitor, |
| 142 | + allow_redirects=False, |
| 143 | + headers={'Content-Type': monitor.content_type}, |
| 144 | + ) |
136 | 145 |
|
137 | 146 | return resp |
138 | 147 |
|
|
0 commit comments