getErrorOutput() public method

Returns the current error output of the process (STDERR).
public getErrorOutput ( ) : string
return string The process error output
 /**
  * @param GitLocaleCloneAction $action
  */
 public function perform(GitLocaleCloneAction $action)
 {
     $content = $action->getData()['content'];
     if (true === $action->getData()['debug']) {
         $url = sprintf('https://github.com/%s/test-hook.git', $this->login);
         $content['pull_request']['head']['repo']['clone_url'] = $url;
     }
     $cmd = [];
     $cmd[] = 'cd analyze';
     $cmd[] = 'mkdir -p ' . $content['pull_request']['head']['sha'];
     $cmd[] = 'cd ' . $content['pull_request']['head']['sha'];
     $cmd[] = sprintf('git clone -b %s %s', $content['pull_request']['head']['ref'], $content['pull_request']['head']['repo']['clone_url']);
     if (null !== $this->logger) {
         $this->logger->debug(sprintf('Start command %s', implode(' && ', $cmd)));
     }
     $process = new Process(implode(' && ', $cmd));
     $process->setTimeout(360);
     $process->run();
     if (!$process->isSuccessful()) {
         if (null !== $this->logger) {
             $this->logger->error($process->getErrorOutput());
         }
         throw new \RuntimeException($process->getErrorOutput());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function check()
 {
     if (!$this->isSuccessful()) {
         // on some systems stderr is used, but on others, it's not
         throw new LintingException($this->process->getErrorOutput() ?: $this->process->getOutput(), $this->process->getExitCode());
     }
 }
示例#3
0
 public function testControlledExit()
 {
     if (!extension_loaded('pcntl')) {
         $this->markTestSkipped('PCNTL extension is not loaded.');
     }
     $proc = new Process('exec ' . PHP_BINARY . ' ' . escapeshellarg(__DIR__ . '/console') . ' jms-job-queue:run --worker-name=test --verbose --max-runtime=999999');
     $proc->start();
     usleep(500000.0);
     $this->assertTrue($proc->isRunning(), 'Process exited prematurely: ' . $proc->getOutput() . $proc->getErrorOutput());
     $this->assertTrueWithin(3, function () use($proc) {
         return false !== strpos($proc->getOutput(), 'Signal Handlers have been installed');
     }, function () use($proc) {
         $this->fail('Signal handlers were not installed: ' . $proc->getOutput() . $proc->getErrorOutput());
     });
     $proc->signal(SIGTERM);
     $this->assertTrueWithin(3, function () use($proc) {
         return false !== strpos($proc->getOutput(), 'Received SIGTERM');
     }, function () use($proc) {
         $this->fail('Signal was not received by process within 3 seconds: ' . $proc->getOutput() . $proc->getErrorOutput());
     });
     $this->assertTrueWithin(3, function () use($proc) {
         return !$proc->isRunning();
     }, function () use($proc) {
         $this->fail('Process did not terminate within 3 seconds: ' . $proc->getOutput() . $proc->getErrorOutput());
     });
     $this->assertContains('All jobs finished, exiting.', $proc->getOutput());
 }
示例#4
0
 /**
  * @return string
  */
 public function compile()
 {
     $this->stopwatch->start('webpack.total');
     $this->stopwatch->start('webpack.prepare');
     // Recompile twig templates where its needed.
     $this->addSplitPoints();
     $this->addResolveConfig();
     // Write the webpack configuration file.
     file_put_contents($this->cache_dir . DIRECTORY_SEPARATOR . 'webpack.config.js', $this->generator->getConfiguration());
     $this->profiler->set('compiler.performance.prepare', $this->stopwatch->stop('webpack.prepare')->getDuration());
     $this->stopwatch->start('webpack.compiler');
     $this->process->run();
     $output = $this->process->getOutput() . $this->process->getErrorOutput();
     $this->profiler->set('compiler.executed', true);
     $this->profiler->set('compiler.successful', strpos($output, 'Error:') === false);
     $this->profiler->set('compiler.last_output', $output);
     if ($this->profiler->get('compiler.successful')) {
         $this->tracker->rebuild();
     }
     // Finally, write some logging for later use.
     file_put_contents($this->cache_dir . DIRECTORY_SEPARATOR . 'webpack.compiler.log', $output);
     $this->profiler->set('compiler.performance.compiler', $this->stopwatch->stop('webpack.compiler')->getDuration());
     $this->profiler->set('compiler.performance.total', $this->stopwatch->stop('webpack.total')->getDuration());
     return $output;
 }
示例#5
0
 /**
  * @dataProvider getTestFiles
  */
 public function testIntegration(\SplFileInfo $testFile)
 {
     $testData = $this->parseTestFile($testFile);
     $cmd = 'php ' . __DIR__ . '/../../../bin/composer --no-ansi ' . $testData['RUN'];
     $proc = new Process($cmd);
     $exitcode = $proc->run();
     if (isset($testData['EXPECT'])) {
         $this->assertEquals($testData['EXPECT'], $this->cleanOutput($proc->getOutput()), 'Error Output: ' . $proc->getErrorOutput());
     }
     if (isset($testData['EXPECT-REGEX'])) {
         $this->assertRegExp($testData['EXPECT-REGEX'], $this->cleanOutput($proc->getOutput()), 'Error Output: ' . $proc->getErrorOutput());
     }
     if (isset($testData['EXPECT-ERROR'])) {
         $this->assertEquals($testData['EXPECT-ERROR'], $this->cleanOutput($proc->getErrorOutput()));
     }
     if (isset($testData['EXPECT-ERROR-REGEX'])) {
         $this->assertRegExp($testData['EXPECT-ERROR-REGEX'], $this->cleanOutput($proc->getErrorOutput()));
     }
     if (isset($testData['EXPECT-EXIT-CODE'])) {
         $this->assertSame($testData['EXPECT-EXIT-CODE'], $exitcode);
     }
     // Clean up.
     $fs = new Filesystem();
     if (isset($testData['test_dir']) && is_dir($testData['test_dir'])) {
         $fs->removeDirectory($testData['test_dir']);
     }
 }
示例#6
0
 function render($context = null, $vars = array())
 {
     $finder = new ExecutableFinder();
     $bin = @$this->options["tsc_bin"] ?: self::DEFAULT_TSC;
     $cmd = $finder->find($bin);
     if ($cmd === null) {
         throw new \UnexpectedValueException("'{$bin}' executable was not found. Make sure it's installed.");
     }
     $inputFile = sys_get_temp_dir() . '/pipe_typescript_input_' . uniqid() . '.ts';
     file_put_contents($inputFile, $this->getData());
     $outputFile = tempnam(sys_get_temp_dir(), 'pipe_typescript_output_') . '.js';
     $cmd .= " --out " . escapeshellarg($outputFile) . ' ' . escapeshellarg($inputFile);
     $process = new Process($cmd);
     $process->setEnv(array('PATH' => @$_SERVER['PATH'] ?: join(PATH_SEPARATOR, array("/bin", "/sbin", "/usr/bin", "/usr/local/bin", "/usr/local/share/npm/bin"))));
     if ($this->isFile()) {
         $process->setWorkingDirectory(dirname($this->source));
     }
     $process->run();
     unlink($inputFile);
     if ($process->getErrorOutput()) {
         throw new \RuntimeException("tsc({$this->source}) returned an error:\n {$process->getErrorOutput()}");
     }
     $data = file_get_contents($outputFile);
     unlink($outputFile);
     return $data;
 }
示例#7
0
 /**
  * Validate that a run process was successful.
  *
  * @throws \RuntimeException
  * @return void
  */
 protected function validateRun()
 {
     $status = $this->process->getExitCode();
     $error = $this->process->getErrorOutput();
     if ($status !== 0 and $error !== '') {
         throw new \RuntimeException(sprintf("The exit status code %s says something went wrong:\n stderr: %s\n stdout: %s\ncommand: %s.", $status, $error, $this->process->getOutput(), $this->command));
     }
 }
示例#8
0
 /**
  * Executes the backup command.
  */
 public function archive()
 {
     $this->process->setCommandLine($this->getCommand());
     $this->process->run();
     if ($this->process->getErrorOutput()) {
         throw new \RuntimeException($this->process->getErrorOutput());
     }
 }
示例#9
0
 /**
  * Executes a shell command.
  *
  * @param string $command
  *
  * @return $this
  */
 public function runShellCommand($command)
 {
     $this->process = new Process($command);
     $this->exitCode = $this->process->run();
     $this->stdOutput = $this->process->getOutput();
     $this->stdError = $this->process->getErrorOutput();
     return $this;
 }
 public function process()
 {
     $gammuPath = $this->container->getParameter('symfonian_id.gammu.gammu_path');
     $process = new Process(sprintf('%s -c %s --%s', $gammuPath, $this->config, $this->command));
     $process->run();
     if (!$process->isSuccessful() && $process->getErrorOutput()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
     return $process->getOutput();
 }
示例#11
0
 public function run($sourcePath, Report $report)
 {
     $commandLine = $this->getParameter('command_line');
     $process = new Process($commandLine, $sourcePath);
     $process->run();
     $output = $process->getOutput();
     if ($errorOutput = $process->getErrorOutput()) {
         $output .= 'Error output' . PHP_EOL . PHP_EOL . $process->getErrorOutput();
     }
     $report->addActionData($this, $process->isSuccessful(), $output);
 }
示例#12
0
 /**
  * @param $command
  * @throws ShellProcessFailed
  * @throws \Symfony\Component\Process\Exception\LogicException
  */
 public function process($command)
 {
     if (empty($command)) {
         return;
     }
     $this->process->setCommandLine($command);
     $this->process->run();
     if (!$this->process->isSuccessful()) {
         throw new ShellProcessFailed($this->process->getErrorOutput());
     }
 }
 private function waitForServerToSTart()
 {
     $timeout = microtime(true) + 5;
     while (!$this->isStarted()) {
         if (microtime(true) < $timeout) {
             sleep(0.1);
             continue;
         }
         throw new \RuntimeException('Webserver did not start within 5 seconds: ' . $this->process->getErrorOutput());
     }
 }
示例#14
0
 /**
  * Executes a Process and throws a consistent exception
  *
  * @param Process $process
  * @param bool $throwExceptionOnFailure
  * @param null $extraMessage
  * @throws GitException
  */
 private function executeProcess(Process $process, $throwExceptionOnFailure = true, $extraMessage = null)
 {
     $process->run();
     if (!$process->isSuccessful() && $throwExceptionOnFailure) {
         // sometimes an unsuccessful command will still render output, instead of error output
         // this happens, for example, when merging and having a conflict
         $output = $process->getErrorOutput() ? $process->getErrorOutput() : $process->getOutput();
         $msg = sprintf('Error executing "%s": %s', $process->getCommandLine(), $output);
         if ($extraMessage) {
             $msg = $extraMessage . ' ' . $msg;
         }
         throw new GitException($msg);
     }
 }
 /**
  * @param  string $bin
  * @param  array  $args
  * @return string
  */
 public function run($bin, $args)
 {
     if (!is_file($bin)) {
         throw new \InvalidArgumentException(sprintf('Binary %s not found', $bin));
     }
     $process = new Process(sprintf('"%s" %s', $bin, escapeshellcmd($this->arrayToArgsString($args))));
     $process->run();
     if (!$process->isSuccessful()) {
         $this->logger->critical($process->getErrorOutput());
         throw new \RuntimeException($process->getErrorOutput());
     }
     $this->logger->debug(sprintf('SIPS Request output: %s', $process->getOutput()));
     return $process->getOutput();
 }
示例#16
0
 /**
  * @param $command
  * @param $option
  */
 public function process($command, array $option = null)
 {
     if (true === is_array($command)) {
         $command = implode(' ', $command);
     }
     if (true === isset($option['timeout'])) {
         $timeout = $option['timeout'];
     } else {
         $timeout = null;
     }
     if (true === isset($option['tty'])) {
         $tty = $option['tty'];
     } else {
         $tty = false;
     }
     if ($this->verbose) {
         $print = true;
         $this->message('IN >> ' . $command);
     } else {
         if (true === isset($option['print'])) {
             $print = $option['print'];
         } else {
             $print = true;
             $this->message($command);
         }
     }
     $process = new Process($command);
     $process->setTty($tty);
     $process->setTimeout($timeout);
     $process->run(function ($type, $buf) use($print) {
         if (true == $print) {
             $buffers = explode(PHP_EOL, trim($buf, PHP_EOL));
             foreach ($buffers as $buffer) {
                 if (Process::ERR === $type) {
                     echo 'ERR > ' . $buffer . PHP_EOL;
                 } else {
                     if ('reach it successfully.' == $buffer) {
                         print_r($command);
                     }
                     echo \Peanut\Console\Color::text('OUT > ', 'black') . $buffer . PHP_EOL;
                 }
             }
         }
     });
     if (!$process->isSuccessful() && $process->getErrorOutput()) {
         throw new \Peanut\Console\Exception(trim($process->getErrorOutput()));
     }
     return new \Peanut\Console\Result($process->getErrorOutput() . $process->getOutput());
 }
示例#17
0
 /**
  * Execute command
  *
  * @param InputInterface  $input  Input
  * @param OutputInterface $output Output
  *
  * @return null|integer null or 0 if everything went fine, or an error code
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $queueDb = $this->getQueueDatabase();
     $logger = $this->getLogger();
     // Load job
     $jobId = $input->getArgument(self::ARG_ID);
     $job = $queueDb->getJob($jobId);
     $jobCmd = $job->getCommand();
     if (!in_array($job->getStatus(), array(QueueModel::STATUS_WAITING, QueueModel::STATUS_STARTING))) {
         $logContext = array('ID' => $jobId, 'status' => $job->getStatus(), 'cmd' => $job->getCommand());
         $logger->warning('Running job, that already ran', $logContext);
     }
     // Mark job running
     $queueDb->markJobRunning($jobId, getmypid());
     // Log status
     $logger->notice(sprintf('Started Job "%s" (ID %d)', $jobCmd, $jobId));
     // Send a short signal to the parent, so main worker can push us into the background and continue looking for free slots.
     $output->writeln('Marked job running');
     // Prepare command to run
     $consolePath = $this->getContainer()->getParameter('kuborgh_queue.console_path');
     $cmd = sprintf('php %s %s', $consolePath, $jobCmd);
     $process = new Process($cmd);
     try {
         $process->setTimeout(null);
         $process->run();
     } catch (\Exception $exc) {
         // The command failed. Log full output
         $msg = sprintf("Job \"%s\" (ID %d) failed with exception: %s\n%s\n%s", $jobCmd, $jobId, $exc->getMessage(), $process->getErrorOutput(), $process->getOutput());
         $this->getLogger()->error($msg);
         $queueDb->markJobFailed($jobId);
         return -1;
     }
     $logger->notice(sprintf('Job Ended "%s" (ID %d)', $jobCmd, $jobId));
     // Mark job according to the exit code
     $exitCode = $process->getExitCode();
     if (!$exitCode) {
         $logger->notice(sprintf('Finished Job "%s" (ID %d)', $jobCmd, $jobId));
         // log output
         $ctx = array('Output' => $process->getOutput());
         $logger->debug(sprintf('Output of Job "%s" (ID %d)', $jobCmd, $jobId), $ctx);
         $queueDb->markJobDone($jobId);
     } else {
         // log output + error output
         $ctx = array('Output' => $process->getOutput(), 'Error' => $process->getErrorOutput());
         $logger->warning(sprintf('Job Failed "%s" (ID %d)', $jobCmd, $jobId), $ctx);
         $queueDb->markJobFailed($jobId);
     }
     return $exitCode;
 }
示例#18
0
 public function execute()
 {
     $logger = $this->getRunConfig()->getLogger();
     $this->process = new Process($this->command);
     $logger->info('Start command:' . $this->command);
     $this->process->setTimeout($this->timeout);
     $this->process->setWorkingDirectory($this->getRunConfig()->getRepositoryDirectory());
     $this->process->run();
     $output = trim($this->process->getOutput());
     $logger->info($output);
     if (!$this->process->isSuccessful()) {
         $logger->emergency($this->process->getErrorOutput());
         throw new \RuntimeException('Command not successful:' . $this->command);
     }
 }
示例#19
0
 /**
  * {@inheritdoc}
  */
 public function execute(\SplFileInfo $path, Request $request, array $env = [])
 {
     $bin = dirname(PHP_BINARY) . '/php-cgi';
     $process = new Process($bin . ' -f ' . $path->getRealPath(), null, $this->createEnvVars($path, $request, $env), $request->getBody());
     $process->run();
     if (!$process->isSuccessful()) {
         throw new BadCgiCallException($process->getErrorOutput());
     }
     $response = $this->parseOutput($process->getOutput(), $process->getErrorOutput());
     if ($response->getHeader('Status')) {
         list($code, ) = explode(' ', $response->getHeader('Status'), 2);
         $response->setCode($code);
     }
     return $response;
 }
示例#20
0
 public function download($in_dir)
 {
     $repo = $in_dir . '/' . $this->package . ".git";
     if (is_dir($repo)) {
         return;
     }
     $cmd = 'git clone --mirror %s %s';
     $process = new Process(sprintf($cmd, $this->url, $repo));
     $process->setTimeout(3600);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \Exception($process->getErrorOutput());
     }
     $cmd = 'cd %s && git update-server-info -f';
     $process = new Process(sprintf($cmd, $repo));
     $process->setTimeout(3600);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \Exception($process->getErrorOutput());
     }
     $cmd = 'cd %s && git fsck';
     $process = new Process(sprintf($cmd, $repo));
     $process->setTimeout(3600);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \Exception($process->getErrorOutput());
     }
 }
示例#21
0
 public function __construct(\Symfony\Component\Process\Process $process)
 {
     $this->process = $process;
     $code = 0;
     $message = '';
     // Not all of the ansible errors have output in stderr. Therefore, if
     // stderr is empty we will use the stdout output instead to get clues
     // on what the actual error was.
     $error = $process->getErrorOutput();
     if (is_null($error)) {
         $error = $process->getOutput();
     }
     // Figure out the specific error that occured
     if (false !== strpos($error, 'the playbook') && false !== strpos($error, 'could not be found')) {
         $code = self::NOT_FOUND;
         $message = self::NOT_FOUND_MSG;
     } else {
         if (false !== strpos($error, 'Syntax Error while loading YAML script')) {
             $code = self::SYNTAX_ERROR;
             $message = self::SYNTAX_ERROR_MSG;
         } else {
             if (false !== strpos($error, 'One or more undefined variables')) {
                 $code = self::UNDEFINED_VARIABLE;
                 $message = self::UNDEFINED_VARIABLE_MSG;
             } else {
                 $code = self::GENERAL_ERROR;
                 $message = self::GENERAL_ERROR_MSG;
             }
         }
     }
     parent::__construct($message, $code);
 }
示例#22
0
文件: Git.php 项目: cpass78/liferaft
 /**
  * Checkout the given branch.
  *
  * @param  string  $branch
  * @return void
  */
 public function checkoutNew($branch)
 {
     with($process = new Process('git checkout -b ' . $branch, getcwd()))->run();
     if ($process->getExitCode() > 0) {
         throw new \Exception($process->getErrorOutput());
     }
 }
 private function install(OutputInterface $output, $targetFolder, $symlinkName, $forceDownload, HttpSource $source)
 {
     $version = $source->getVersion();
     $extractedFolder = 'PhpStorm-' . $version;
     if (is_dir($targetFolder . '/' . $extractedFolder) && false === $forceDownload) {
         $output->writeln(sprintf('<comment>Phpstorm <info>%s</info> already exists, skipping download..</comment>', $version));
     } else {
         $output->write(sprintf('<comment>Download %s </comment><info>%s</info><comment>...</comment>', $source->getName(), $version));
         $downloadProcess = new Process(sprintf("wget %s -O phpstorm.tar.gz", escapeshellarg($source->getUrl())));
         $downloadProcess->setTimeout(3600);
         $downloadProcess->run();
         $output->writeln(' <info>OK</info>');
         if (!$downloadProcess->isSuccessful()) {
             throw new \RuntimeException($downloadProcess->getErrorOutput());
         }
         $output->write('<comment>Extracting...</comment>');
         $extractProcess = new Process(sprintf('tar xfz phpstorm.tar.gz; rm phpstorm.tar.gz; mv %1$s %2$s', escapeshellarg($extractedFolder), escapeshellarg($targetFolder)));
         $extractProcess->run();
         $output->writeln(' <info>OK</info>');
         if (!$extractProcess->isSuccessful()) {
             throw new \RuntimeException($extractProcess->getErrorOutput());
         }
     }
     $output->write('<comment>Linking...</comment>');
     $command = sprintf('cd %2$s && ln -s -f -T %1$s %3$s', escapeshellarg($extractedFolder), escapeshellarg($targetFolder), escapeshellarg($symlinkName));
     $linkProcess = new Process($command);
     $linkProcess->run();
     $output->writeln(' <info>OK</info>');
     if (!$linkProcess->isSuccessful()) {
         throw new \RuntimeException($linkProcess->getErrorOutput());
     }
 }
示例#24
0
文件: Util.php 项目: fbone/mediboard4
 /**
  * Execute an SVN command
  *
  * @param string  $cmd       Command name (update, info, etc)
  * @param array   $arguments An array of argument (path, url, etc)
  * @param array   $options   An array of options
  * @param string  $path      Working directory
  * @param integer $timeout   Timeout
  *
  * @return string
  * @throws \Exception
  */
 public static function exec($cmd, $arguments = array(), $options = array(), $path = null, $output = false, $timeout = null)
 {
     if (!is_array($arguments)) {
         $arguments = array($arguments);
     }
     $arguments = array_map("escapeshellarg", $arguments);
     $new_options = array();
     foreach ($options as $key => $value) {
         $new_options[] = preg_replace("/[^-\\w]/", "", $key);
         if ($value !== true) {
             $new_options[] = escapeshellarg($value);
         }
     }
     $cmdline = "svn {$cmd} " . implode(" ", $arguments) . " " . implode(" ", $new_options);
     $process = new Process($cmdline, $path, null, null, $timeout);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new RuntimeException($process->getErrorOutput());
     }
     if ($output) {
         echo $process->getOutput();
         return null;
     }
     return $process->getOutput();
 }
示例#25
0
 /**
  * @dataProvider getTestFiles
  * @depends testBuildPhar
  */
 public function testIntegration(\SplFileInfo $testFile)
 {
     $testData = $this->parseTestFile($testFile);
     $this->oldenv = getenv('COMPOSER_HOME');
     $_SERVER['COMPOSER_HOME'] = $this->testDir . 'home';
     putenv('COMPOSER_HOME=' . $_SERVER['COMPOSER_HOME']);
     $cmd = 'php ' . escapeshellarg(self::$pharPath) . ' --no-ansi ' . $testData['RUN'];
     $proc = new Process($cmd, __DIR__ . '/Fixtures/functional', null, null, 300);
     $exitcode = $proc->run();
     if (isset($testData['EXPECT'])) {
         $this->assertEquals($testData['EXPECT'], $this->cleanOutput($proc->getOutput()), 'Error Output: ' . $proc->getErrorOutput());
     }
     if (isset($testData['EXPECT-REGEX'])) {
         $this->assertRegExp($testData['EXPECT-REGEX'], $this->cleanOutput($proc->getOutput()), 'Error Output: ' . $proc->getErrorOutput());
     }
     if (isset($testData['EXPECT-ERROR'])) {
         $this->assertEquals($testData['EXPECT-ERROR'], $this->cleanOutput($proc->getErrorOutput()));
     }
     if (isset($testData['EXPECT-ERROR-REGEX'])) {
         $this->assertRegExp($testData['EXPECT-ERROR-REGEX'], $this->cleanOutput($proc->getErrorOutput()));
     }
     if (isset($testData['EXPECT-EXIT-CODE'])) {
         $this->assertSame($testData['EXPECT-EXIT-CODE'], $exitcode);
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configCommand = $this->getApplication()->find('oro:requirejs:generate-config');
     $configCommand->run(new ArrayInput(['command' => 'oro:requirejs:generate-config']), $output);
     $webRoot = $this->getContainer()->getParameter('oro_require_js.web_root');
     $config = $this->getContainer()->getParameter('oro_require_js');
     $configProvider = $this->getContainer()->get('oro_requirejs_config_provider');
     $output->writeln('Generating require.js build config');
     $buildConfigContent = $configProvider->generateBuildConfig(self::MAIN_CONFIG_FILE_NAME);
     $buildConfigContent = '(' . json_encode($buildConfigContent) . ')';
     $buildConfigFilePath = $webRoot . DIRECTORY_SEPARATOR . self::BUILD_CONFIG_FILE_NAME;
     if (false === @file_put_contents($buildConfigFilePath, $buildConfigContent)) {
         throw new \RuntimeException('Unable to write file ' . $buildConfigFilePath);
     }
     if (isset($config['js_engine']) && $config['js_engine']) {
         $output->writeln('Running code optimizer');
         $command = $config['js_engine'] . ' ' . self::OPTIMIZER_FILE_PATH . ' -o ' . basename($buildConfigFilePath) . ' 1>&2';
         $process = new Process($command, $webRoot);
         $process->setTimeout($config['building_timeout']);
         $process->run();
         if (!$process->isSuccessful()) {
             throw new \RuntimeException($process->getErrorOutput());
         }
         $output->writeln('Cleaning up');
         if (false === @unlink($buildConfigFilePath)) {
             throw new \RuntimeException('Unable to remove file ' . $buildConfigFilePath);
         }
         $output->writeln(sprintf('<comment>%s</comment> <info>[file+]</info> %s', date('H:i:s'), realpath($webRoot . DIRECTORY_SEPARATOR . $config['build_path'])));
     }
 }
 /**
  * @return SystemData Process output.
  */
 public function execute()
 {
     $process = new Process($this->command);
     isset($this->input) && $process->setInput($this->input);
     $process->run();
     return new SystemData($process->getOutput(), $process->getErrorOutput(), $process->getExitCode());
 }
示例#28
0
 public function generate($url, $width, $height, $name)
 {
     $hash = md5($url);
     $thumbnail = new Thumbnail();
     $thumbnail->url = $url;
     $thumbnail->width = $width;
     $thumbnail->height = $height;
     $thumbnail->relativePath = $this->compilePattern($width, $height, $name);
     $thumbnail->absolutePath = $this->documentRoot . '/' . $thumbnail->relativePath;
     if ($this->fs->exists($thumbnail->absolutePath)) {
         return $thumbnail;
     }
     $tmpFile = $this->cacheDir . '/' . $hash;
     if (!$this->fs->exists($this->cacheDir)) {
         $this->fs->mkdir($this->cacheDir);
     }
     if (!$this->fs->exists($tmpFile)) {
         $this->getImageForUrl($url, $tmpFile);
     }
     if (!$this->fs->exists(dirname($thumbnail->absolutePath))) {
         $this->fs->mkdir(dirname($thumbnail->absolutePath));
     }
     $cmd = "convert %s[0] -resize '%dx%d^' -gravity center -crop %dx%d+0+0 +repage %s";
     $process = new Process(sprintf($cmd, $tmpFile, $width, $height, $width, $height, $thumbnail->absolutePath));
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \Exception($process->getErrorOutput());
     }
     return $thumbnail;
 }
示例#29
0
 /**
  * Check if linting process was successful and raise LintingException if not.
  *
  * @param Process $process
  */
 private function checkProcess(Process $process)
 {
     if (!$process->isSuccessful()) {
         // on some systems stderr is used, but on others, it's not
         throw new LintingException($process->getErrorOutput() ?: $process->getOutput(), $process->getExitCode());
     }
 }
示例#30
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('<info>Defining crontab task...</info>');
     $output->writeln('<info>Please enter the frequency of data aggregating</info> <comment>(frequency must be equal "pinba_stats_history" of the pinba engine config)</comment>.');
     $dialog = $this->getHelperSet()->get('dialog');
     $frequency = $dialog->askAndValidate($output, 'Frequency (in minutes, default "15"): ', function ($answer) {
         if (intval($answer) <= 0) {
             throw new \RunTimeException('You must enter positive integer value');
         }
         return $answer;
     }, false, '15');
     $process = new Process('crontab -l');
     $process->setTimeout(20);
     $process->run();
     $crontabString = $process->isSuccessful() ? $process->getOutput() : '';
     $path = realpath(__DIR__ . '/../../../console');
     $command = '*/' . $frequency . ' * * * * ' . $path . ' aggregate';
     if (strpos($crontabString, $command) === false) {
         $crontabString .= "\n" . $command . "\n";
     }
     $file = tempnam(sys_get_temp_dir(), 'ipm');
     file_put_contents($file, $crontabString);
     $process = new Process('crontab ' . $file);
     $process->setTimeout(20);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
     $output->writeln('<info>Crontab task are defined successfully</info>');
     $output->writeln('<info>Please set parameter "aggregation_period" to value "PT' . $frequency . 'M" in config/parameters.yml</info>');
 }