/** * Run a terminal command * @param [array] $command [description] * @param [path] $directory [description] * @param OutputInterface $output [description] * @return [void] [description] */ private function runProcess($command, $directory, $output, $alias) { $output->writeln(''); if (is_array($command['line'])) { $commandLine = implode(' && ', $command['line']); } else { $commandLine = $command['line']; } $process = new Process($commandLine, $directory); $process->setTimeout(7600); $process->start(); if ($output->isVerbose()) { $process->wait(function ($type, $buffer) { echo $buffer; }); } else { $progress = new ProgressBar($output); $progress->setFormat("<comment>%message%</comment> [%bar%]"); $progress->setMessage($command['title']); $progress->start(); $progress->setRedrawFrequency(10000); while ($process->isRunning()) { $progress->advance(); } $progress->finish(); $progress->clear(); } $output->writeln(''); $output->write('<comment>' . $command['title'] . ' </comment><info>√ done</info>'); }
/** * Simple method for listing output * one column * * @param string $header * @param array $items * @param OutputInterface $output */ public static function renderList($header, $items, $output) { $output->writeln('<fg=yellow;options=underscore>' . ucfirst($header) . "</>\n"); if (count($items) > 0) { foreach ($items as $item) { $output->writeln(" - {$item}"); } } $output->writeln("\n" . self::tint('(' . count($items) . ' in set)', 'comment')); }
/** * Executa comando * * @param OutputInterface $oInput * @param InputInterface $oOutput * @access public * @return void */ public function execute($oInput, $oOutput) { $sArquivo = $oInput->getArgument('arquivo'); if (!file_exists($sArquivo)) { throw new Exception("Arquivo não existe: {$sArquivo}"); } /** * Lista informacoes do commit, sem as tags */ exec('cvs annotate ' . $sArquivo . ' 2> /tmp/cvsgit_last_error', $aRetornoComandoAnnotate, $iStatusComandoAnnotate); if ($iStatusComandoAnnotate > 0) { throw new Exception("Erro ao execurar cvs log -N {$sArquivo}" . PHP_EOL . $this->getApplication()->getLastError(), $iStatusComandoAnnotate); } $sDiretorioTemporario = '/tmp/cvs-annotate/'; $sArquivoPrograma = $sDiretorioTemporario . 'arquivo_' . basename($sArquivo); $sArquivoDados = $sDiretorioTemporario . 'dados_' . basename($sArquivo); $sConteudoArquivoPrograma = ''; $sConteudoArquivoDados = ''; $iColunasDados = 0; /** * Cria diretorio temporario */ if (!is_dir($sDiretorioTemporario) && !mkdir($sDiretorioTemporario, 0777, true)) { throw new Exception("Não foi possivel criar diretório temporario: {$sDiretorioTemporario}"); } foreach ($aRetornoComandoAnnotate as $sLinha) { $aLinha = explode(':', $sLinha); $aLinhaDados = explode(" ", $aLinha[0]); $sLinhaPrograma = $aLinha[1]; $sLinhaDados = ''; foreach ($aLinhaDados as $iIndiceLinhaDados => $sDadosLinhaDados) { if (empty($sDadosLinhaDados)) { continue; } $sDadosLinhaDados = str_replace(array('(', ')'), '', $sDadosLinhaDados); $sLinhaDados .= $sDadosLinhaDados . ' '; } $iLinhaDados = strlen($sLinhaDados); if ($iLinhaDados > $iColunasDados) { $iColunasDados = $iLinhaDados; } // $sConteudoArquivoPrograma .= $sLinhaPrograma . PHP_EOL; $sConteudoArquivoDados .= trim($sLinhaDados) . PHP_EOL; } // file_put_contents($sArquivoPrograma, $sConteudoArquivoPrograma); file_put_contents($sArquivoDados, $sConteudoArquivoDados); $this->binario($sArquivo, $sArquivoDados, $iColunasDados); }
protected function execute(InputInterface $input, OutputInterface $output) { $time_start = $this->microtime_float(); $output->writeln('<comment>START delete process</comment>'); if ($input->getOption('account')) { $output->writeln('<info>Safe accounts delete using ID</info>'); $ids = explode(",", $input->getOption('account')); foreach ($ids as $accountId) { $helper = new ImportAccountsHelper($this->getContainer()->get('doctrine')->getEntityManager()); $deleteResult = $helper->deleteAccount($accountId); $output->writeln($deleteResult); } } if ($input->getOption('file')) { $output->writeln('<info>Safe accounts delete using file: ' . $input->getOption('file') . '</info>'); $file = $input->getOption('file'); $parser = new AccountParser($file); $helper = new ImportAccountsHelper($this->getContainer()->get('doctrine')->getEntityManager()); while (count($accounts = $parser->getData()) > 0) { foreach ($accounts as $account) { $accountId = $account[1]; $deleteResult = $helper->deleteAccount($accountId); $output->writeln($deleteResult); } } } $time_end = $this->microtime_float(); $time = $time_end - $time_start; $output->writeln('<comment>END import process(' . $time . ' sec)</comment>'); }
protected function execute(InputInterface $input, OutputInterface $output) { $date = $input->getArgument("expiredDate"); $checkDate = $date instanceof \DateTime ? $date : new \DateTime($date); $checkDate->setTime(0, 0, 0); $em = $this->getContainer()->get('doctrine')->getEntityManager(); $entities = $em->getRepository('BraemCRMBundle:Lead')->deleteExpiredLeads($checkDate); if ($entities) { $count = count($entities); foreach ($entities as $entity) { $em->remove($entity); $output->writeln('Removed lead #' . $entity->getId()); } $em->flush(); $output->writeln($count . ' leads were successfully removing'); } else { $output->writeln('Nothing to remove'); } }
protected function listCommands(InputInterface $input, OutputInterface $output) { $filter = $input->getArgument(1, NULL); $message = $filter === NULL ? '' : ' in namespace [' . $filter . ']'; $output->writeLine("Available commands%s:", $message); $output->writeLine(''); foreach ($this->commands as $namespace => $cmd) { if ($filter !== NULL && $namespace != $filter) { continue; } $output->writeLine($namespace . ':'); foreach ($cmd as $name => $command) { $output->writeLine(' %s - %s', $name, $command->getDescription()); } $output->writeLine(''); } if ($filter === NULL) { $output->writeLine('help - List all available commands.'); $output->writeLine('exit - Terminate the K2 shell.'); } }
/** * @param string $message * @param string $scope * @return mixed */ private function output($message, $scope = Output::SCOPE_PRIVATE) { return $this->output->write($message, $scope); }
private function processarArquivo($sArquivo) { if (!file_exists($sArquivo)) { throw new Exception("Arquivo não existe: {$sArquivo}"); } $nPrimeiraVersao = $this->oInput->getArgument('primeira_versao'); $nSegundaVersao = $this->oInput->getArgument('segunda_versao'); /** * Nenhuma versao informada para usar diff */ if (empty($nPrimeiraVersao)) { /** * Lista informacoes do commit, sem as tags */ $oComando = $this->getApplication()->execute('cvs log -N ' . escapeshellarg($sArquivo)); $aRetornoComandoInformacoes = $oComando->output; $iStatusComandoInformacoes = $oComando->code; if ($iStatusComandoInformacoes > 0) { throw new Exception("Erro ao execurar cvs log -N " . escapeshellarg($sArquivo) . PHP_EOL . $this->getApplication()->getLastError(), $iStatusComandoInformacoes); } $iVersaoAtual = null; foreach ($aRetornoComandoInformacoes as $iIndice => $sLinhaRetorno) { if (strpos($sLinhaRetorno, 'head:') !== false) { $iVersaoAtual = trim(str_replace('head:', '', $sLinhaRetorno)); break; } } $nPrimeiraVersao = $iVersaoAtual; } if (!file_exists('CVS/Repository')) { throw new Exception('Diretório atual não é um repositorio CVS.'); } $sDiretorioRepositorio = trim(file_get_contents('CVS/Repository')); $aDiretorioRepositorio = explode('/', $sDiretorioRepositorio); $sProjeto = $aDiretorioRepositorio[0]; $sDiretorioCheckout = $sDiretorioRepositorio; $sDiretorioTemporario = '/tmp/cvs-diff/'; $sSeparador = '__'; $sComandoCheckout = "cvs checkout -r %s " . escapeshellarg("{$sDiretorioCheckout}/" . $sArquivo) . " 2> /tmp/cvsgit_last_error"; $sComandoMover = "mv " . escapeshellarg("{$sDiretorioCheckout}/" . $sArquivo) . " {$sDiretorioTemporario}[%s]\\ " . basename($sArquivo); $sComandoMoverProjeto = "cp -rf " . escapeshellarg($sProjeto) . " {$sDiretorioTemporario} && rm -rf " . escapeshellarg($sProjeto); /** * Cria diretorio temporario */ if (!is_dir($sDiretorioTemporario) && !mkdir($sDiretorioTemporario, 0777, true)) { throw new Exception("Não foi possivel criar diretório temporario: {$sDiretorioTemporario}"); } /** * Checkout - Primeira versao */ $oComando = $this->getApplication()->execute(sprintf($sComandoCheckout, $nPrimeiraVersao)); $aRetornoCheckout = $oComando->output; $iStatusCheckout = $oComando->code; /** * Erro - Primeira versao */ if ($iStatusCheckout > 0) { throw new Exception('Erro ao executar checkout da versão "' . $nPrimeiraVersao . '"' . PHP_EOL . $this->getApplication()->getLastError(), $iStatusCheckout); } /** * Mover primeria versao * - mover arquivo da primeira versao para diretorio temporario */ $oComando = $this->getApplication()->execute(sprintf($sComandoMover, $nPrimeiraVersao)); $aRetornoMover = $oComando->output; $iStatusMover = $oComando->code; if ($iStatusMover > 0) { throw new Exception('Erro ao executar: ' . sprintf($sComandoMover, $nPrimeiraVersao), $iStatusMover); } $sArquivoPrimeiraVersao = $sDiretorioTemporario . "[" . $nPrimeiraVersao . "] " . basename($sArquivo); /** * Vim diff - segunda versao nao inforamada */ if (empty($nSegundaVersao)) { exec('diff ' . escapeshellarg($sArquivo) . ' ' . escapeshellarg($sArquivoPrimeiraVersao) . ' > /tmp/cvsgit_diff'); $sDiffPrimeiraVersao = trim(file_get_contents('/tmp/cvsgit_diff')); if (empty($sDiffPrimeiraVersao)) { exec($sComandoMoverProjeto); throw new Exception('Nenhuma diferença com a versão ' . $nPrimeiraVersao); } exec($sComandoMoverProjeto); $this->binario($sArquivo, $sArquivoPrimeiraVersao); return 1; } /** * Checkout - Segunda versao */ exec(sprintf($sComandoCheckout, $nSegundaVersao), $aRetornoCheckout, $iStatusCheckout); if ($iStatusCheckout > 0) { exec($sComandoMoverProjeto); throw new Exception('Erro ao executar checkout da versão "' . $nSegundaVersao . '"' . PHP_EOL . $this->getApplication()->getLastError()); } /** * Mover segunda versao * - mover arquivo da primeira versao para diretorio temporario */ exec(sprintf($sComandoMover . ' 2> /tmp/cvsgit_last_error', $nSegundaVersao), $aRetornoMover, $iStatusMover); if ($iStatusMover > 0) { throw new Exception('Erro ao executar: ' . sprintf($sComandoMover, $nSegundaVersao)); } $sArquivoSegundaVersao = $sDiretorioTemporario . "[" . $nSegundaVersao . "] " . basename($sArquivo); exec('diff ' . escapeshellarg($sArquivoPrimeiraVersao) . ' ' . escapeshellarg($sArquivoSegundaVersao) . ' > /tmp/cvsgit_diff'); $sDiffDuasVersoes = trim(file_get_contents('/tmp/cvsgit_diff')); if (empty($sDiffDuasVersoes)) { throw new Exception('Nenhuma diferença entre as versões ' . $nPrimeiraVersao . ' e ' . $nSegundaVersao); } exec($sComandoMoverProjeto); $this->binario($sArquivoPrimeiraVersao, $sArquivoSegundaVersao); }
/** * @param OutputInterface $output */ public function add(OutputInterface $output) { foreach ($output->supports() as $support) { $this->outputs[$support] = $output; } }
/** * Stop * * @param OutputInterface $output * * @return void */ protected function stop(OutputInterface $output) { if (!file_exists($this->pidfile)) { $output->writeln('<error>PID file not found</error>'); } else { $output->writeln('Stopping daemon ... '); $pid = file_get_contents($this->pidfile); posix_kill($pid, SIGTERM); pcntl_waitpid($pid, $status); $output->writeln('Daemon stopped with PID ' . $pid); unlink($this->pidfile); } }
/** * @param $lat float * @param $lng float * @return mixed * * Gets weather */ public function getWeather($lat, $lng) { $info = $this->weatherProvider->getWeatherInfo($lat, $lng); $output = $this->outputter->outputJSON($info); return $output; }
/** * @param string $string * @param string $scope * @return void */ public function output($string, $scope = Output::SCOPE_PRIVATE) { $this->output->write($string, $scope); }
public function output($message) { $this->output->output($message); return $this; }
/** * Logs with an arbitrary level. * * @param mixed $level * @param string $message * @param array $context * @return null */ public function log($level, $message, array $context = array()) { $line = sprintf('<%s>[%s]</%s> %s', $level, $level, $level, strtr($message, $context)); $this->output->writeln($line); }