/**
  * Prepare a command to run in the repo's directory
  *
  * @param $command
  * @return \Symfony\Component\Process\Process
  */
 public function cmd($command)
 {
     $process = new \Symfony\Component\Process\Process($command);
     $process->setWorkingDirectory($this->getPrjDir());
     $process->setTimeout(self::TIMEOUT);
     return $process;
 }
示例#2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$input->getOption('command')) {
         $output->writeln("<error>Missing required option: --command</error>");
         return 1;
     }
     $statusCode = 0;
     if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
         $output->writeln("<info>[[ Finding repositories ]]</info>");
     }
     $scanner = new \GitScan\GitRepoScanner();
     $gitRepos = $scanner->scan($input->getArgument('path'));
     foreach ($gitRepos as $gitRepo) {
         /** @var \GitScan\GitRepo $gitRepo */
         if (!$gitRepo->matchesStatus($input->getOption('status'))) {
             continue;
         }
         $topLevel = $this->fs->findFirstParent($gitRepo->getPath(), $input->getArgument('path'));
         if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
             $output->writeln("<info>[[ {$gitRepo->getPath()} ]]</info>");
         }
         $process = new \Symfony\Component\Process\Process($input->getOption('command'));
         $process->setWorkingDirectory($gitRepo->getPath());
         // $process->setEnv(...); sucks in Debian/Ubuntu
         putenv("path=" . $this->fs->makePathRelative($gitRepo->getPath(), $topLevel));
         putenv("toplevel=" . $topLevel);
         $errorOutput = $output;
         if (is_callable($output, 'getErrorOutput') && $output->getErrorOutput()) {
             $errorOutput = $output->getErrorOutput();
         }
         $process->run(function ($type, $buffer) use($output, $errorOutput) {
             if (\Symfony\Component\Process\Process::ERR === $type) {
                 if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
                     $errorOutput->write("<error>STDERR</error> ");
                 }
                 $errorOutput->write($buffer, FALSE, OutputInterface::OUTPUT_RAW);
             } else {
                 if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
                     $output->write("<comment>STDOUT</comment> ");
                 }
                 $output->write($buffer, FALSE, OutputInterface::OUTPUT_RAW);
             }
         });
         if (!$process->isSuccessful()) {
             $errorOutput->writeln("<error>[[ {$gitRepo->getPath()}: exit code = {$process->getExitCode()} ]]</error>");
             $statusCode = 2;
         }
     }
     putenv("path");
     putenv("toplevel");
     return $statusCode;
 }
示例#3
0
/**
 * Execute commands in parallel.
 *
 * @param array $cmds list of commands to be executed.
 * @param string $cwd absolute path of working directory.
 * @return array list of processes.
 */
function cli_execute_parallel($cmds, $cwd = null)
{
    require_once __DIR__ . "/../../vendor/autoload.php";
    $processes = array();
    // Create child process.
    foreach ($cmds as $name => $cmd) {
        $process = new Symfony\Component\Process\Process($cmd);
        $process->setWorkingDirectory($cwd);
        $process->setTimeout(null);
        $processes[$name] = $process;
        $processes[$name]->start();
        // If error creating process then exit.
        if ($processes[$name]->getStatus() !== 'started') {
            echo "Error starting process: {$name}";
            foreach ($processes[$name] as $process) {
                if ($process) {
                    $process->signal(SIGKILL);
                }
            }
            exit(1);
        }
    }
    return $processes;
}
示例#4
0
 /**
  * @param string $subdir absolute path, or path relative to $this->fixturePath
  * @param string $command
  */
 protected function command($subdir, $command)
 {
     $process = new \Symfony\Component\Process\Process($command);
     $process->setWorkingDirectory($subdir);
     return $process;
 }