88 lines
2.0 KiB
PHP
88 lines
2.0 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace VfxApply\Plugin\Executor;
|
||
|
|
||
|
use VfxApply\Plugin;
|
||
|
use VfxApply\Input;
|
||
|
use VfxApply\Output;
|
||
|
use VfxApply\Preset;
|
||
|
|
||
|
class Operation
|
||
|
{
|
||
|
protected $name;
|
||
|
|
||
|
protected $info;
|
||
|
|
||
|
protected $parser;
|
||
|
|
||
|
protected $command;
|
||
|
|
||
|
protected $helper;
|
||
|
|
||
|
protected $script;
|
||
|
|
||
|
public function __construct($name, array $data)
|
||
|
{
|
||
|
$_ = function($a,$k,$d=null) { return empty($a[$k])?$d:$a[$k]; };
|
||
|
$this->name = $name;
|
||
|
$this->info = $_($data,'info');
|
||
|
$this->command = $_($data,'exec');
|
||
|
$this->helper = $_($data,'call');
|
||
|
$this->parser = new Parser($_($data,'parse'), $_($data,'extract'));
|
||
|
}
|
||
|
|
||
|
public function getName()
|
||
|
{
|
||
|
return $this->name;
|
||
|
}
|
||
|
|
||
|
public function getInfo()
|
||
|
{
|
||
|
return $this->info;
|
||
|
}
|
||
|
|
||
|
public function setScript(Script $script)
|
||
|
{
|
||
|
$this->script = $script;
|
||
|
}
|
||
|
|
||
|
public function execute(array $env, $dialog)
|
||
|
{
|
||
|
if ($this->helper) {
|
||
|
$helper = $this->script->getHelper($this->helper);
|
||
|
$helper->call($env);
|
||
|
}
|
||
|
|
||
|
if (!$this->command) {
|
||
|
return;
|
||
|
}
|
||
|
$cmdl = $this->script->parseVariable($this->command, $env);
|
||
|
//printf(" cmd: %s\n", $this->command);
|
||
|
//printf(" eval: %s\n", $cmdl);
|
||
|
|
||
|
$this->parser->prepareExtractors($this->script, $env);
|
||
|
|
||
|
$descr = [
|
||
|
0 => [ 'pipe', 'r' ],
|
||
|
1 => [ 'pipe', 'w' ],
|
||
|
2 => [ 'pipe', 'w' ]
|
||
|
];
|
||
|
echo "Exec: ".$cmdl."\n";
|
||
|
$proc = proc_open($cmdl, $descr, $pipes);
|
||
|
$tot = (int)$env['frames']-1;
|
||
|
printf("\r%s [%s]", $this->info, $this->name);
|
||
|
$this->parser->parse($pipes, function ($status) use ($tot, $dialog) {
|
||
|
$curr = (int)$status['frame'];
|
||
|
$pc = min(100,100/$tot*$curr);
|
||
|
$dialog->setProgress($pc);
|
||
|
$out = sprintf("%s [%s]: %.1f%%", $this->info, $this->name, $pc);
|
||
|
$dialog->setText($out);
|
||
|
echo "\r{$out}";
|
||
|
});
|
||
|
proc_close($proc);
|
||
|
printf("\n");
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|