在批处理模式下运行任务并在cli上跟踪进度的简单api。
batchcli的Python项目详细描述
这个小库提供了一种在cli上批量运行某些任务和跟踪进度的简单方法。
您可以获得的输出示例如下:
[ 1/7 ] Put oil in the pan [ ... ] ... [ 2/7 ] Turn fire on [ ... ] ... [ 3/7 ] Break the egg [ ... ] ... [ 4/7 ] Put the egg in the pan [ ... ] ... [ 5/7 ] Wait the egg is cooked [ ... ] ... [ 6/7 ] Put the egg in the dish [ ... ] ... [ 7/7 ] Add salt to the egg and eat it! [ ... ] ...
该模块提供一个api来定义任务并将其添加到任务引擎中:
cli = SimpleCli() engine = TaskEngine(cli) engine.addTask(Print("Put oil in the pan")) engine.addTask(Print("Turn fire on")) engine.addTask(Print("Break the egg")) engine.addTask(Print("Put the egg in the pan")) engine.addTask(Print("Wait the egg is cooked")) engine.addTask(Print("Put the egg in the dish")) engine.addTask(Print("Add salt to the egg and eat it!")) engine.run()
在上面的示例中,print是一个类扩展任务(在模块中定义):
class Print(Task): "Simple Task: do nothing more than printing ..." def run(self, cli): cli.newMessage
如果任务失败,任务引擎将立即停止并从方法运行返回。