pclcmd.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:pclcmd 作者: abbat 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号