cli: using PROGRESSFUNCTION before libcurl 7.32.0 in download_file

This commit is contained in:
Yuming Zhu 2017-08-03 17:29:43 +08:00 committed by Mike McLean
parent 5df1e3e6e6
commit ba087236dd
2 changed files with 36 additions and 2 deletions

View file

@ -487,8 +487,15 @@ def download_file(url, relpath, quiet=False, noprogress=False, size=None, num=No
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(c.WRITEDATA, open(relpath, 'wb'))
if not (quiet or noprogress):
c.setopt(c.NOPROGRESS, False)
c.setopt(c.XFERINFOFUNCTION, _download_progress)
proc_func_param = getattr(c, 'XFERINFOFUNCTION', None)
if proc_func_param is None:
proc_func_param = getattr(c, 'PROGRESSFUNCTION', None)
if proc_func_param is not None:
c.setopt(c.NOPROGRESS, False)
c.setopt(proc_func_param, _download_progress)
else:
c.close()
error(_('Error: XFERINFOFUNCTION and PROGRESSFUNCTION are not supported by pyCurl. Quit download progress'))
c.perform()
c.close()
if not (quiet or noprogress):