V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
CivAx
V2EX  ›  Python

有办法可以把 progressbar2 和 tarfile 结合起来用吗?

  •  
  •   CivAx · Oct 25, 2019 · 2389 views
    This topic created in 2389 days ago, the information mentioned may be changed or developed.

    有一个约 19GB 的 tar.gz 零散文件包需要解压(解压后约 80G ),由于是有人值守,所以迫切需要一个进度条。

    tarfile 代码:

    import tarfile
    
    filepath ="/data/someWhere/2019"
    list = '(tarfile.open("/data/someWhere/2019.gz").getnames())'   # list
    for n in list:
      tar.extract(n. filepath)
    tar.close()
    

    progress2 代码:

    import progress
    
    size=len(list)  # int, e.g.127
    with progressbar.ProgressBar(
      widgets=[progressbar.SimpleProgress()],
      max_value=(size)) as bar:
      
      for i in range(size):
        bar.update(i+1)
      bar.finish()
    

    尝试了把 progress2 的方法插入到 tarfile 的 for 循环当中,由于是用的 extract 而不是 extractall,导致进度条完全没有效果,全部解压完毕后会从 0 直接到 100%(包内有 127 个文件)。

    如果反过来插入,会导致压缩包被重复解压 ${文件数量} 次。

    2 replies    2019-10-26 10:37:34 +08:00
    by73
        1
    by73  
       Oct 25, 2019
    照着你的代码合并了一次,没有任何问题啊 https://pastebin.com/rJRhQcnn
    CivAx
        2
    CivAx  
    OP
       Oct 26, 2019
    @by73 #1 您试一下在压缩包中打包多个目录与文件,应该会出现我描述的问题了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1021 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 18:30 · PVG 02:30 · LAX 11:30 · JFK 14:30
    ♥ Do have faith in what you're doing.