def pcl_query_download(options, response, filename):
"""
???????? ????? ?? ?????????
?????????:
options (pclOptions) -- ????? ??????????
response (HTTPResponse) -- HTTP ?????
filename (str) -- ??? ?????????? ????? ??? ??????
"""
if options.progress:
read = 0
start = int(time.time())
bar = None
try:
total = int(response.info().get("Content-Length"))
if pclProgressBar:
try:
widgets = ["--> Download: ", pclProgressBar.Percentage(), " ", pclProgressBar.Bar(left = "[", marker = "=", right = "]"), " ", pclProgressBar.ETA(), " ", pclProgressBar.FileTransferSpeed()]
bar = pclProgressBar.ProgressBar(widgets = widgets, maxval = total).start()
except:
total = pcl_human(total)
else:
total = pcl_human(total)
except:
total = "-"
with open(filename, "wb") as fd:
while True:
part = response.read(options.chunk)
if not part:
break
fd.write(part)
if options.progress:
read += len(part)
if bar:
bar.update(read)
else:
delta = int(time.time()) - start
if delta > 0:
sys.stderr.write("--> Download: {0}/{1} ({2}/s){3}\r".format(pcl_human(read), total, pcl_human(read / delta), " " * 12))
if options.progress:
if bar:
bar.finish()
else:
sys.stderr.write("{0}\r".format(" " * 35))
评论列表
文章目录