| 339 | zipfile.close() |
| 340 | |
| 341 | def download(self, file, url): |
| 342 | AppLog.debug('start download {}'.format(url)) |
| 343 | with closing(requests.get(url, stream=True)) as response: |
| 344 | # 单次请求最大值 |
| 345 | chunk_size = 1024 |
| 346 | # 内容体总大小 |
| 347 | content_size = int(response.headers['content-length']) |
| 348 | data_count = 0 |
| 349 | Signals.updateProgressChanged.emit(0, 0, content_size) |
| 350 | AppLog.debug('content_size: {}'.format(content_size)) |
| 351 | with open(file, 'wb') as fp: |
| 352 | for data in response.iter_content(chunk_size=chunk_size): |
| 353 | fp.write(data) |
| 354 | data_count = data_count + len(data) |
| 355 | if content_size > 0: |
| 356 | Signals.updateProgressChanged.emit( |
| 357 | data_count, 0, content_size) |
| 358 | # 解压 |
| 359 | self.unzip(file) |
| 360 | AppLog.debug('download {} end'.format(file)) |
| 361 | |
| 362 | def run(self): |
| 363 | for url_ver, url_zip in self.UpdateUrl: |