Exemple #1
0
 /**
  * {@inheritDoc}
  */
 public function run(OutputInterface $output)
 {
     /** @type DebugFormatterHelper $debugFormatter */
     $debugFormatter = $this->getHelperSet()->get('debug_formatter');
     $arguments = $this->resolveProcessArgs();
     $builder = new ProcessBuilder($arguments);
     $process = $builder->getProcess();
     if (null !== ($dispatcher = $this->getEventDispatcher())) {
         $event = new PreExecuteEvent($this, $process);
         $dispatcher->dispatch(Event::PRE_EXECUTE, $event);
         if ($event->isPropagationStopped()) {
             return true;
         }
     }
     if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERY_VERBOSE) {
         $output->writeln(sprintf('        // Setting timeout for %d seconds.', $this->getParameter('timeout')));
     }
     $process->setTimeout($this->getParameter('timeout') !== 0 ? $this->getParameter('timeout') : null);
     if ($this->hasParameter('cwd')) {
         $process->setWorkingDirectory($this->getParameter('cwd'));
     }
     if (get_class($this) === 'Bldr\\Block\\Execute\\Task\\ExecuteTask') {
         $output->writeln(['', sprintf('    <info>[%s]</info> - <comment>Starting</comment>', $this->getName()), '']);
     }
     if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE || $this->getParameter('dry_run')) {
         $output->writeln('        // ' . $process->getCommandLine());
     }
     if ($this->getParameter('dry_run')) {
         return true;
     }
     if ($this->hasParameter('output')) {
         $append = $this->hasParameter('append') && $this->getParameter('append') ? 'a' : 'w';
         $stream = fopen($this->getParameter('output'), $append);
         $output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, true);
     }
     $output->writeln("<fg=blue>==============================\n</fg=blue>");
     $output->writeln($debugFormatter->start(spl_object_hash($process), $process->getCommandLine()));
     $process->run(function ($type, $buffer) use($output, $debugFormatter, $process) {
         if ($this->getParameter('raw')) {
             $output->write($buffer, false, OutputInterface::OUTPUT_RAW);
             return;
         }
         $output->write($debugFormatter->progress(spl_object_hash($process), $buffer, Process::ERR === $type));
     });
     $output->writeln($debugFormatter->stop(spl_object_hash($process), $process->getCommandLine(), $process->isSuccessful()));
     $output->writeln("<fg=blue>==============================</fg=blue>");
     if (null !== $dispatcher) {
         $event = new PostExecuteEvent($this, $process);
         $dispatcher->dispatch(Event::POST_EXECUTE, $event);
     }
     if (!in_array($process->getExitCode(), $this->getParameter('successCodes'))) {
         throw new TaskRuntimeException($this->getName(), $process->getErrorOutput());
     }
 }
 public function printLegend()
 {
     $symbols = array();
     foreach (self::$eventStatusMap as $status) {
         $symbol = $status['symbol'];
         if ('' === $symbol || isset($symbols[$symbol])) {
             continue;
         }
         $symbols[$symbol] = sprintf('%s-%s', $this->output->isDecorated() ? sprintf($status['format'], $symbol) : $symbol, $status['description']);
     }
     $this->output->write(sprintf("\nLegend: %s\n", implode(', ', $symbols)));
 }
Exemple #3
0
 /**
  * Creates the given process
  *
  * @throws \Exception
  */
 private function startProcess(OutputInterface $output)
 {
     $arguments = $this->resolveProcessArgs();
     $name = sha1(serialize($arguments));
     if ($this->background->hasProcess($name)) {
         throw new \RuntimeException("Service is already running.");
     }
     $builder = new ProcessBuilder($arguments);
     if ($this->hasParameter('cwd')) {
         $builder->setWorkingDirectory($this->getParameter('cwd'));
     }
     $process = $builder->getProcess();
     if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) {
         $output->writeln($process->getCommandLine());
     }
     if ($this->hasParameter('output')) {
         $append = $this->hasParameter('append') && $this->getParameter('append') ? 'a' : 'w';
         $stream = fopen($this->getParameter('output'), $append);
         $output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, true);
     }
     $process->start(function ($type, $buffer) use($output) {
         $output->write($buffer);
     });
     $this->background->addProcess($name, $process);
     if (!in_array($process->getExitCode(), $this->getParameter('successCodes'))) {
         throw new TaskRuntimeException($this->getName(), $process->getErrorOutput());
     }
 }
Exemple #4
0
 /**
  * @inheritdoc
  */
 public function execute(ResultCollection $collection, ResultCollection $aggregatedResults)
 {
     if (!$this->destination) {
         return;
     }
     $dir = dirname($this->destination);
     if (!file_exists($dir)) {
         mkdir($dir, 0777, true);
     }
     $this->output->writeln(sprintf('Generating %s Report...', $this->formater->getName()));
     $handle = fopen($this->destination, 'w');
     $stream = new StreamOutput($handle);
     $stream->write($this->formater->terminate($collection, $aggregatedResults));
     fclose($handle);
 }
Exemple #5
0
 /**
  * {@inheritDoc}
  */
 public function run(OutputInterface $output)
 {
     $arguments = $this->resolveProcessArgs();
     $builder = new ProcessBuilder($arguments);
     if (null !== ($dispatcher = $this->getEventDispatcher())) {
         $event = new PreExecuteEvent($this, $builder);
         $dispatcher->dispatch(Event::PRE_EXECUTE, $event);
         if ($event->isPropagationStopped()) {
             return true;
         }
     }
     if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERY_VERBOSE) {
         $output->writeln(sprintf('        // Setting timeout for %d seconds.', $this->getParameter('timeout')));
     }
     $builder->setTimeout($this->getParameter('timeout') !== 0 ? $this->getParameter('timeout') : null);
     if ($this->hasParameter('cwd')) {
         $builder->setWorkingDirectory($this->getParameter('cwd'));
     }
     $process = $builder->getProcess();
     if (get_class($this) === 'Bldr\\Block\\Execute\\Task\\ExecuteTask') {
         $output->writeln(['', sprintf('    <info>[%s]</info> - <comment>Starting</comment>', $this->getName()), '']);
     }
     if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE || $this->getParameter('dry_run')) {
         $output->writeln('        // ' . $process->getCommandLine());
     }
     if ($this->getParameter('dry_run')) {
         return true;
     }
     if ($this->hasParameter('output')) {
         $append = $this->hasParameter('append') && $this->getParameter('append') ? 'a' : 'w';
         $stream = fopen($this->getParameter('output'), $append);
         $output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, true);
     }
     $process->start(function ($type, $buffer) use($output) {
         $output->write("\r        " . str_replace("\n", "\n        ", $buffer));
     });
     while ($process->isRunning()) {
     }
     if (null !== $dispatcher) {
         $event = new PostExecuteEvent($this, $process);
         $dispatcher->dispatch(Event::POST_EXECUTE, $event);
     }
     if (!in_array($process->getExitCode(), $this->getParameter('successCodes'))) {
         throw new TaskRuntimeException($this->getName(), $process->getErrorOutput());
     }
 }
Exemple #6
0
 /**
  * @Request(csrf=true)
  */
 public function updateAction()
 {
     if (!($file = App::session()->get('system.update'))) {
         App::abort(400, __('You may not call this step directly.'));
     }
     App::session()->remove('system.update');
     return App::response()->stream(function () use($file) {
         $output = new StreamOutput(fopen('php://output', 'w'));
         try {
             if (!file_exists($file) || !is_file($file)) {
                 throw new \RuntimeException('File does not exist.');
             }
             $updater = new SelfUpdater($output);
             $updater->update($file);
         } catch (\Exception $e) {
             $output->writeln(sprintf("\n<error>%s</error>", $e->getMessage()));
             $output->write("status=error");
         }
     });
 }
Exemple #7
0
 /**
  * Write to output
  *
  * @param array|string $messages Messages
  * @param bool         $newline  Whether to append a newline
  * @param int          $type     The output type
  *
  * @return void
  */
 public function write($messages, $newline = false, $type = \Symfony\Component\Console\Output\Output::OUTPUT_NORMAL)
 {
     $messages = (array) $messages;
     foreach ($messages as &$message) {
         $l = strlen($message) - 1;
         if ($l >= 0) {
             if ($message[$l] === "\n") {
                 $message = substr($message, 0, $l);
                 $l--;
                 $newline = true;
             }
             if ($this->previousWasNewLine && $l >= 0 && $message[0] !== "\n") {
                 $message = $this->getIndention() . $message;
             }
             if (strpos($message, "\n") !== false) {
                 $message = str_replace("\n", "\n" . $this->getIndention(), $message);
             }
             // TODO: Indent wrapped lines - that's just not that easy because of the ANSI color escape codes
         }
     }
     parent::write($messages, $newline, $type);
     $this->previousWasNewLine = $newline;
 }