跳转到主要内容

执行输出完成百分比的cmd,解释这些百分比并执行带有增加和总百分比的回调。

项目描述

在解释cmd完成百分比的同时执行cmd。

cmd的完成百分比存储在一个名为percentage的属性中,用户可以通过执行increment或在初始化时传递一个回调来获取百分比增加。

此类适用于在子线程中使用,因此子线程执行cmd,阻塞并更新增加和百分比到父线程,父线程可以在同时做其他事情。

示例

Badblocks

def my_callback(increment, total):
   print(f'Update: +{increment}% / {total}%.')

def child_thread():
  progress = ProgressiveCmd('badblocks', '-st', 'random', '-w', 'dev/sda1', digits=ProgressiveCmd.DECIMALS, decimal_digits=2, read=35, callback=my_callback)
  progress.run()

t = threading.Thread(target=child_thread)
t.start()

Shred

def my_callback(increment, total):
   print(f'Update: +{increment} / {total}%.')

def child_thread():
  progress = ProgressiveCmd('shred', '-vn 1', 'dev/sda1', callback=my_callback)
  progress.run()

t = threading.Thread(target=child_thread)
t.start()

fsarchiver

def my_callback(increment, total):
   print(f'Update: +{increment} / {total}%.')

def child_thread():
  progress = ProgressiveCmd('fsarchiver', 'restfs', '-v', 'foo/bar/', 'id=0,dest=dev/sda1', callback=my_callback)
  progress.run()

t = threading.Thread(target=child_thread)
t.start()

使用tqdm

您可以使用increment值来更新tqdm

t = tqdm(total=100)

def my_callback(increment, total):
    t.update(increment)

def child_thread():
  progress = ProgressiveCmd('a-program', callback=my_callback)
  progress.run()

thread = threading.Thread(target=child_thread)
thread.start()

测试

  1. git clone此项目。

  2. 在项目文件夹中执行python setup.py test

贡献

是否有缺失或错误的代码?在问题中提出!欢迎贡献。

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于安装软件包的信息。

源分布

progressive-cmd-0.1.1.tar.gz (5.3 kB 查看哈希值)

上传于 源代码

由以下支持