libvirt_kvm.py 文件源码

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

项目:paws 作者: rhpit 项目源码 文件源码
def download(link, file_dst, label):
        """Create HTTP request to download a file"""
        # delimit labels to be at same size and a better visualization
        # when printing the progres bar
        fill_out = 20 - len(label)
        extra = " " * fill_out
        pbar_label = label + extra
        LOG.debug("Starting download %s" % link)
        try:
            req = urllib2.urlopen(link)
            remote_file_size = int(req.headers.get('content-length'))
            CHUNK = 16 * 1024
            with open(file_dst, 'wb') as fp:
                with progressbar(length=remote_file_size,
                                 fill_char=style('#', fg='green'),
                                 empty_char=' ',
                                 label=pbar_label,
                                 show_percent=True) as bar:
                    while True:
                        chunk = req.read(CHUNK)
                        if not chunk: break
                        fp.write(chunk)
                        bar.update(len(chunk))

            LOG.debug("Download complete, file %s saved locally" % file_dst)
        except (HTTPError, RequestException, Exception) as ex:
            raise ex
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号