setBarWidth() 공개 메소드

Sets the progress bar width.
public setBarWidth ( integer $size )
$size integer The progress bar size
 /**
  * @param string $type
  * @param string $buffer
  */
 public function __invoke(string $type, string $buffer)
 {
     if ($type === 'err' && preg_match('/^-n\\s*\\d+\\s*\\/\\s*(\\d+)\\s*\\((\\d+)\\)\\s*$/', $buffer, $matches)) {
         if ($this->progressBar === null) {
             $this->progressBar = new ProgressBar($this->output, (int) $matches[1]);
             $this->progressBar->setBarWidth(100);
             $this->progressBar->start();
         }
         $this->progressBar->advance();
         $this->updates = $matches[2];
     }
 }
예제 #2
0
 /**
  * @return \Symfony\Component\Console\Helper\ProgressBar
  */
 public function build()
 {
     $this->setupFormat();
     $progressBar = new ProgressBar($this->output, $this->count);
     $progressBar->setMessage($this->barTitle, 'barTitle');
     $progressBar->setBarWidth(20);
     if ($this->output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) {
         $progressBar->setBarCharacter("◼");
         $progressBar->setEmptyBarCharacter("◼");
         $progressBar->setProgressCharacter("▶");
         $progressBar->setBarWidth(50);
     }
     return $progressBar;
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $shopId = $input->getArgument('shopId');
     if (!empty($shopId)) {
         $shopIds[] = $shopId;
     } else {
         $shopIds = $this->container->get('db')->fetchCol('SELECT id FROM s_core_shops WHERE active = 1');
     }
     /** @var \Shopware\Components\HttpCache\CacheWarmer $cacheWarmer */
     $cacheWarmer = $this->container->get('http_cache_warmer');
     foreach ($shopIds as $shopId) {
         $limit = 10;
         $offset = 0;
         $totalUrlCount = $cacheWarmer->getAllSEOUrlCount($shopId);
         $output->writeln("\n Calling URLs for shop with id " . $shopId);
         $progressBar = new ProgressBar($output, $totalUrlCount);
         $progressBar->setBarWidth(100);
         $progressBar->start();
         while ($offset < $totalUrlCount) {
             $urls = $cacheWarmer->getAllSEOUrls($shopId, $limit, $offset);
             $cacheWarmer->callUrls($urls, $shopId);
             $progressBar->advance(count($urls));
             $offset += count($urls);
         }
         $progressBar->finish();
     }
     $output->writeln("\n The HttpCache is now warmed up");
 }
예제 #4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $startTime = microtime(true);
     $output->writeln("phplint {$this->getApplication()->getVersion()}");
     $output->writeln('');
     $phpBinary = PHP_BINARY;
     $path = $input->getArgument('path');
     $exclude = $input->getOption('exclude');
     $extensions = $input->getOption('extensions');
     $procLimit = $input->getOption('jobs');
     // $failOnFirst = $input->getOption('fail-on-first');
     if ($extensions) {
         $extensions = explode(',', $extensions);
     } else {
         $extensions = array('php');
     }
     $linter = new Linter($path, $exclude, $extensions);
     if ($procLimit) {
         $linter->setProcessLimit($procLimit);
     }
     $files = $linter->getFiles();
     $fileCount = count($files);
     $progress = new ProgressBar($output, $fileCount);
     $progress->setBarWidth(50);
     $progress->setMessage('', 'overview');
     $progress->setFormat(" %overview%\n %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%");
     $progress->start();
     $linter->setProcessCallback(function ($status, $filename) use($progress) {
         /*
         $overview = $progress->getMessage('overview');
         
         if ($status == 'ok') {
             $overview .= '.';
         } elseif ($status == 'error') {
             $overview .= 'F';
             // exit(1);
         }
         
         $progress->setMessage($overview, 'overview');
         */
         $progress->advance();
     });
     $result = $linter->lint($files);
     $progress->finish();
     $output->writeln('');
     $testTime = microtime(true) - $startTime;
     $code = 0;
     $errCount = count($result);
     $out = "<info>Checked {$fileCount} files in " . round($testTime, 1) . " seconds</info>";
     if ($errCount > 0) {
         $out .= "<info> and found syntax errors in </info><error>{$errCount}</error><info> files.</info>";
         $out .= "\n" . json_encode($result, JSON_PRETTY_PRINT);
         $code = 1;
     } else {
         $out .= '<info> a no syntax error were deteced.';
     }
     $output->writeln($out . PHP_EOL);
     return $code;
 }
예제 #5
0
 public static function create(OutputInterface $output)
 {
     $bar = new ProgressBar($output);
     $bar->setBarCharacter('<fg=green>=</>');
     $bar->setEmptyBarCharacter('<fg=red>=</>');
     $bar->setProgressCharacter('>');
     $bar->setBarWidth(40);
     $bar->setFormat("%message%\n [%bar%] %percent:3s%%\n%elapsed:6s%/%estimated:-6s% %memory:6s%\n");
     return $bar;
 }
예제 #6
0
 /**
  * @param OutputInterface $output
  *
  * @return \Symfony\Component\Console\Helper\ProgressBar
  */
 private function getProgressBar(OutputInterface $output)
 {
     $bar = new ProgressBar($output);
     $bar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %memory:6s%');
     $bar->setBarCharacter('<comment>=</comment>');
     $bar->setEmptyBarCharacter(' ');
     $bar->setProgressCharacter('|');
     $bar->setBarWidth(50);
     return $bar;
 }
예제 #7
0
 public function testCustomizations()
 {
     $bar = new ProgressBar($output = $this->getOutputStream(), 10);
     $bar->setBarWidth(10);
     $bar->setBarCharacter('_');
     $bar->setEmptyBarCharacter(' ');
     $bar->setProgressCharacter('/');
     $bar->setFormat(' %current%/%max% [%bar%] %percent:3s%%');
     $bar->start();
     $bar->advance();
     rewind($output->getStream());
     $this->assertEquals($this->generateOutput('  0/10 [/         ]   0%') . $this->generateOutput('  1/10 [_/        ]  10%'), stream_get_contents($output->getStream()));
 }
예제 #8
0
 /**
  * @param OutputInterface $output
  *
  * @return resource
  */
 protected function createStreamContext(OutputInterface $output)
 {
     $ctx = stream_context_create([], ['notification' => function ($code, $severity, $message, $message_code, $bytesTransferred, $bytesMax) use($output) {
         switch ($code) {
             case STREAM_NOTIFY_FILE_SIZE_IS:
                 $this->progress = new ProgressBar($output, $bytesMax);
                 $this->progress->setBarWidth(75);
                 $this->progress->start();
                 break;
             case STREAM_NOTIFY_PROGRESS:
                 $this->progress->setCurrent($bytesTransferred);
                 if ($bytesTransferred == $bytesMax) {
                     $this->progress->finish();
                     $output->writeln('');
                 }
                 break;
             case STREAM_NOTIFY_COMPLETED:
                 $this->progress->finish();
                 break;
         }
     }]);
     return $ctx;
 }
예제 #9
0
 public function __construct(InputInterface $input, OutputInterface $output)
 {
     if (!$input->getOption('no-progress-bar')) {
         $progressBar = new ProgressBar($output);
         $progressBar->setFormat('verbose');
         $progressBar->setBarWidth(58);
         if (!$output->isDecorated()) {
             $progressBar->setRedrawFrequency(60);
         }
         $this->progressBar = $progressBar;
     } else {
         $this->isDisabled = true;
     }
 }
예제 #10
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $rows = 100;
     $progressBar = new ProgressBar($output, $rows);
     $progressBar->setBarCharacter('<comment>=</comment>');
     $progressBar->setProgressCharacter('>');
     $progressBar->setBarWidth(77);
     $table = new Table($output);
     for ($i = 0; $i < $rows; $i++) {
         $table->addRow([sprintf('Row <info># %s</info>', $i), rand(0, 1000)]);
         usleep(50000);
         $progressBar->advance();
     }
     $progressBar->finish();
     $output->writeln('');
     $table->render();
 }
예제 #11
0
 /**
  * Download a file from the URL to the destination.
  *
  * @param string $url      Fully qualified URL to the file.
  * @param bool   $progress Show the progressbar when downloading.
  */
 public function downloadFile($url, $progress = true)
 {
     /** @var ProgressBar|null $progressBar */
     $progressBar = null;
     $downloadCallback = function ($size, $downloaded, $client, $request, Response $response) use(&$progressBar) {
         // Don't initialize the progress bar for redirects as the size is much smaller.
         if ($response->getStatusCode() >= 300) {
             return;
         }
         if (null === $progressBar) {
             ProgressBar::setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
                 return $this->formatSize($bar->getMaxSteps());
             });
             ProgressBar::setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
                 return str_pad($this->formatSize($bar->getProgress()), 11, ' ', STR_PAD_LEFT);
             });
             $progressBar = new ProgressBar($this->output, $size);
             $progressBar->setFormat('%current%/%max% %bar%  %percent:3s%%');
             $progressBar->setRedrawFrequency(max(1, floor($size / 1000)));
             $progressBar->setBarWidth(60);
             if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
                 $progressBar->setEmptyBarCharacter('░');
                 // light shade character \u2591
                 $progressBar->setProgressCharacter('');
                 $progressBar->setBarCharacter('▓');
                 // dark shade character \u2593
             }
             $progressBar->start();
         }
         $progressBar->setProgress($downloaded);
     };
     $client = $this->getGuzzleClient();
     if ($progress) {
         $this->output->writeln(sprintf("\n Downloading %s...\n", $url));
         $client->getEmitter()->attach(new Progress(null, $downloadCallback));
     }
     $response = $client->get($url);
     $tmpFile = $this->filesystemHelper->newTempFilename();
     $this->fs->dumpFile($tmpFile, $response->getBody());
     if (null !== $progressBar) {
         $progressBar->finish();
         $this->output->writeln("\n");
     }
     return $tmpFile;
 }
예제 #12
0
 /**
  * {@inheritdoc}
  */
 public function set_task_count($task_count, $restart = false)
 {
     parent::set_task_count($task_count, $restart);
     if ($this->output->getVerbosity() === OutputInterface::VERBOSITY_NORMAL) {
         $this->progress_bar = $this->io->createProgressBar($task_count);
         $this->progress_bar->setFormat("    %current:3s%/%max:-3s% %bar%  %percent:3s%%\n" . "             %message%\n");
         $this->progress_bar->setBarWidth(60);
         if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
             $this->progress_bar->setEmptyBarCharacter('░');
             // light shade character \u2591
             $this->progress_bar->setProgressCharacter('');
             $this->progress_bar->setBarCharacter('▓');
             // dark shade character \u2593
         }
         $this->progress_bar->setMessage('');
         $this->io->newLine(2);
         $this->progress_bar->start();
     }
 }
예제 #13
0
 /**
  * @param OutputInterface $output
  * @param int             $statementCount
  *
  * @return ProgressBar
  */
 private function createProgressBar(OutputInterface $output, int $statementCount) : ProgressBar
 {
     $progress = new ProgressBar($output);
     $progress->setRedrawFrequency(1);
     $progress->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s% %message%');
     $progress->setMessage('<info>starting</info>');
     $progress->start($statementCount);
     $progress->setBarWidth(min(4 * $statementCount + 2, 50));
     return $progress;
 }
예제 #14
0
 /**
  * Chooses the best compressed file format to download (ZIP or TGZ) depending upon the
  * available operating system uncompressing commands and the enabled PHP extensions
  * and it downloads the file.
  *
  * @throws \RuntimeException if the ProcessWire archive could not be downloaded
  */
 private function download()
 {
     $this->output->writeln("\n  Downloading ProcessWire Version " . $this->branch['version'] . "...");
     $distill = new Distill();
     $pwArchiveFile = $distill->getChooser()->setStrategy(new MinimumSize())->addFile($this->branch['zipURL'])->getPreferredFile();
     /** @var ProgressBar|null $progressBar */
     $progressBar = null;
     $downloadCallback = function ($size, $downloaded, $client, $request, Response $response) use(&$progressBar) {
         // Don't initialize the progress bar for redirects as the size is much smaller
         if ($response->getStatusCode() >= 300) {
             return;
         }
         if (null === $progressBar) {
             ProgressBar::setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
                 return $this->formatSize($bar->getMaxSteps());
             });
             ProgressBar::setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
                 return str_pad($this->formatSize($bar->getStep()), 11, ' ', STR_PAD_LEFT);
             });
             $progressBar = new ProgressBar($this->output, $size);
             $progressBar->setFormat('%current%/%max% %bar%  %percent:3s%%');
             $progressBar->setRedrawFrequency(max(1, floor($size / 1000)));
             $progressBar->setBarWidth(60);
             if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
                 $progressBar->setEmptyBarCharacter('░');
                 // light shade character \u2591
                 $progressBar->setProgressCharacter('');
                 $progressBar->setBarCharacter('▓');
                 // dark shade character \u2593
             }
             $progressBar->start();
         }
         $progressBar->setProgress($downloaded);
     };
     $client = new Client();
     $client->getEmitter()->attach(new Progress(null, $downloadCallback));
     // store the file in a temporary hidden directory with a random name
     $this->compressedFilePath = getcwd() . DIRECTORY_SEPARATOR . '.' . uniqid(time()) . DIRECTORY_SEPARATOR . 'pw.' . pathinfo($pwArchiveFile, PATHINFO_EXTENSION);
     try {
         $response = $client->get($pwArchiveFile);
     } catch (ClientException $e) {
         if ($e->getCode() === 403 || $e->getCode() === 404) {
             throw new \RuntimeException(sprintf("The selected version (%s) cannot be installed because it does not exist.\n" . "Try the special \"latest\" version to install the latest stable ProcessWire release:\n" . '%s %s %s latest', $this->version, $_SERVER['PHP_SELF'], $this->getName(), $this->projectDir));
         } else {
             throw new \RuntimeException(sprintf("The selected version (%s) couldn't be downloaded because of the following error:\n%s", $this->version, $e->getMessage()));
         }
     }
     $this->fs->dumpFile($this->compressedFilePath, $response->getBody());
     if (null !== $progressBar) {
         $progressBar->finish();
         $this->output->writeln("\n");
     }
     return $this;
 }
예제 #15
0
 /**
  * Chooses the best compressed file format to download (ZIP or TGZ) depending upon the
  * available operating system uncompressing commands and the enabled PHP extensions
  * and it downloads the file.
  *
  * @return $this
  *
  * @throws \RuntimeException If the Symfony archive could not be downloaded
  */
 protected function download()
 {
     $this->output->writeln(sprintf("\n Downloading %s...\n", $this->getDownloadedApplicationType()));
     // decide which is the best compressed version to download
     $distill = new Distill();
     $symfonyArchiveFile = $distill->getChooser()->setStrategy(new MinimumSize())->addFilesWithDifferentExtensions($this->getRemoteFileUrl(), ['tgz', 'zip'])->getPreferredFile();
     /** @var ProgressBar|null $progressBar */
     $progressBar = null;
     $downloadCallback = function (ProgressEvent $event) use(&$progressBar) {
         $downloadSize = $event->downloadSize;
         $downloaded = $event->downloaded;
         // progress bar is only displayed for files larger than 1MB
         if ($downloadSize < 1 * 1024 * 1024) {
             return;
         }
         if (null === $progressBar) {
             ProgressBar::setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
                 return $this->formatSize($bar->getMaxSteps());
             });
             ProgressBar::setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
                 return str_pad($this->formatSize($bar->getProgress()), 11, ' ', STR_PAD_LEFT);
             });
             $progressBar = new ProgressBar($this->output, $downloadSize);
             $progressBar->setFormat('%current%/%max% %bar%  %percent:3s%%');
             $progressBar->setRedrawFrequency(max(1, floor($downloadSize / 1000)));
             $progressBar->setBarWidth(60);
             if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
                 $progressBar->setEmptyBarCharacter('░');
                 // light shade character \u2591
                 $progressBar->setProgressCharacter('');
                 $progressBar->setBarCharacter('▓');
                 // dark shade character \u2593
             }
             $progressBar->start();
         }
         $progressBar->setProgress($downloaded);
     };
     $client = $this->getGuzzleClient();
     // store the file in a temporary hidden directory with a random name
     $this->downloadedFilePath = rtrim(getcwd(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '.' . uniqid(time()) . DIRECTORY_SEPARATOR . 'symfony.' . pathinfo($symfonyArchiveFile, PATHINFO_EXTENSION);
     try {
         $request = $client->createRequest('GET', $symfonyArchiveFile);
         $request->getEmitter()->on('progress', $downloadCallback);
         $response = $client->send($request);
     } catch (ClientException $e) {
         if ('new' === $this->getName() && ($e->getCode() === 403 || $e->getCode() === 404)) {
             throw new \RuntimeException(sprintf("The selected version (%s) cannot be installed because it does not exist.\n" . "Execute the following command to install the latest stable Symfony release:\n" . '%s new %s', $this->version, $_SERVER['PHP_SELF'], str_replace(getcwd() . DIRECTORY_SEPARATOR, '', $this->projectDir)));
         } else {
             throw new \RuntimeException(sprintf("There was an error downloading %s from symfony.com server:\n%s", $this->getDownloadedApplicationType(), $e->getMessage()), null, $e);
         }
     }
     $this->fs->dumpFile($this->downloadedFilePath, $response->getBody());
     if (null !== $progressBar) {
         $progressBar->finish();
         $this->output->writeln("\n");
     }
     return $this;
 }
예제 #16
0
 /**
  * Chooses the best compressed file format to download (ZIP or TGZ) depending upon the
  * available operating system uncompressing commands and the enabled PHP extensions
  * and it downloads the file.
  *
  * @param string $url
  * @param string $module
  * @param OutputInterface $output
  * @return NewCommand
  *
  * @throws \RuntimeException if the ProcessWire archive could not be downloaded
  */
 public function downloadModule($url, $module, $output)
 {
     $output->writeln(" Downloading module {$module}...");
     $distill = new Distill();
     $pwArchiveFile = $distill->getChooser()->setStrategy(new MinimumSize())->addFile($url)->getPreferredFile();
     /** @var ProgressBar|null $progressBar */
     $progressBar = null;
     $downloadCallback = function ($size, $downloaded, $client, $request, Response $response) use(&$progressBar, &$output) {
         // Don't initialize the progress bar for redirects as the size is much smaller
         if ($response->getStatusCode() >= 300) {
             return;
         }
         if (null === $progressBar) {
             ProgressBar::setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
                 return $this->formatSize($bar->getMaxSteps());
             });
             ProgressBar::setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
                 return str_pad($this->formatSize($bar->getStep()), 11, ' ', STR_PAD_LEFT);
             });
             $progressBar = new ProgressBar($output, $size);
             $progressBar->setFormat('%current%/%max% %bar%  %percent:3s%%');
             $progressBar->setRedrawFrequency(max(1, floor($size / 1000)));
             $progressBar->setBarWidth(60);
             if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
                 $progressBar->setEmptyBarCharacter('░');
                 // light shade character \u2591
                 $progressBar->setProgressCharacter('');
                 $progressBar->setBarCharacter('▓');
                 // dark shade character \u2593
             }
             $progressBar->start();
         }
         $progressBar->setProgress($downloaded);
     };
     $client = new Client();
     $client->getEmitter()->attach(new Progress(null, $downloadCallback));
     // store the file in a temporary hidden directory with a random name
     $this->compressedFilePath = \ProcessWire\wire('config')->paths->siteModules . '.' . uniqid(time()) . DIRECTORY_SEPARATOR . $module . '.' . pathinfo($pwArchiveFile, PATHINFO_EXTENSION);
     try {
         $response = $client->get($pwArchiveFile);
     } catch (ClientException $e) {
         if ($e->getCode() === 403 || $e->getCode() === 404) {
             throw new \RuntimeException("The selected module {$module} cannot be downloaded because it does not exist.\n");
         } else {
             throw new \RuntimeException(sprintf("The selected module (%s) couldn't be downloaded because of the following error:\n%s", $module, $e->getMessage()));
         }
     }
     $fs = new Filesystem();
     $fs->dumpFile($this->compressedFilePath, $response->getBody());
     if (null !== $progressBar) {
         $progressBar->finish();
         $output->writeln("\n");
     }
     return $this;
 }
예제 #17
0
 /**
  * @param InputInterface         $input
  * @param OutputInterface|Output $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->getLogger()->debug('Start', ['command_name' => $this->getName(), 'args' => $input->getArguments(), 'opts' => $input->getOptions()]);
     $action = $input->getArgument('action');
     if (!in_array($action, [self::ACTION_INIT, self::ACTION_DROP])) {
         throw new \RuntimeException(sprintf('Invalid argument action, must be "%s" or "%s"', self::ACTION_INIT, self::ACTION_DROP));
     }
     $optionDryRun = $input->getOption('dry-run');
     $prettyOutput = !$output->isQuiet() && !$output->isDebug();
     if ($prettyOutput) {
         $this->getSymfonyStyle()->title(sprintf('grumphp action "%s"', $input->getArgument('action')));
         $this->getSymfonyStyle()->writeln('');
     }
     $repositories = $this->getRepositoryModelList();
     $composerFilename = $repositories->getProjectModel()->getAbsolutePath() . DIRECTORY_SEPARATOR . 'composer.json';
     $composerData = json_decode(file_get_contents($composerFilename), true);
     if (!$composerData) {
         throw new \RuntimeException('Json decode error: ' . json_last_error_msg());
     }
     $configFilename = $repositories->getProjectModel()->getAbsolutePath() . DIRECTORY_SEPARATOR . 'grumphp.yml';
     if (!empty($composerData['config']['extra']['grumphp']['config-default-path'])) {
         $configFilename = $composerData['config']['extra']['grumphp']['config-default-path'];
     }
     if (!file_exists($configFilename)) {
         $this->getSymfonyStyle()->error(sprintf('File "%s" not found', $configFilename));
         return;
     }
     if ($prettyOutput) {
         $this->getSymfonyStyle()->write(sprintf('Work with GrumPhp file "%s"', $configFilename));
     }
     $grumpConfigData = Yaml::parse(file_get_contents($configFilename));
     $fileSystem = new Filesystem();
     $vendorModels = $repositories->getVendorModels();
     $vendorModelsCnt = count($vendorModels);
     $progress = null;
     if ($prettyOutput) {
         $progress = new ProgressBar($output, $vendorModelsCnt);
         $progress->setFormat("%filename% \n %current%/%max% [%bar%]\n");
         $progress->setBarCharacter('<comment>#</comment>');
         $progress->setEmptyBarCharacter(' ');
         $progress->setProgressCharacter('');
         $progress->setBarWidth(50);
     }
     foreach ($vendorModels as $model) {
         if ($prettyOutput) {
             $progress->setMessage('Working on ' . $model->getPath(), 'filename');
             $progress->advance();
         }
         $vendorPath = $model->getAbsolutePath();
         $gitPreCommitFilename = implode(DIRECTORY_SEPARATOR, [$vendorPath, '.git', 'hooks', 'pre-commit']);
         $gitCommitMsgFilename = implode(DIRECTORY_SEPARATOR, [$vendorPath, '.git', 'hooks', 'commit-msg']);
         $vendorConfigFilename = implode(DIRECTORY_SEPARATOR, [$vendorPath, '.git', 'grumphp.yml']);
         if (self::ACTION_INIT == $action) {
             $grumpConfigData['parameters']['bin_dir'] = '../../../bin';
             if (!empty($grumpConfigData['parameters']['tasks']['phpcs']['standard'])) {
                 $standard = $grumpConfigData['parameters']['tasks']['phpcs']['standard'];
                 if (0 === strpos($standard, 'vendor/') || 0 === strpos($standard, './vendor/')) {
                     $grumpConfigData['parameters']['tasks']['phpcs']['standard'] = implode(DIRECTORY_SEPARATOR, [$repositories->getProjectModel()->getAbsolutePath(), $grumpConfigData['parameters']['tasks']['phpcs']['standard']]);
                 }
             }
             if (!$optionDryRun) {
                 $grumpConfigYml = Yaml::dump($grumpConfigData);
                 $fileSystem->dumpFile($vendorConfigFilename, $grumpConfigYml);
                 $fileSystem->dumpFile($gitPreCommitFilename, $this->generatePreCommit($vendorConfigFilename));
                 $fileSystem->chmod($gitPreCommitFilename, 0755);
                 $fileSystem->dumpFile($gitCommitMsgFilename, $this->generateCommitMsg($vendorConfigFilename));
                 $fileSystem->chmod($gitCommitMsgFilename, 0755);
             }
             $this->getLogger()->debug('Config created', ['file' => $vendorConfigFilename]);
             $this->getLogger()->debug('Pre commit hook created', ['file' => $gitPreCommitFilename]);
             $this->getLogger()->debug('Commit msg hook created', ['file' => $gitCommitMsgFilename]);
         } elseif (self::ACTION_DROP == $action) {
             if (!$optionDryRun) {
                 $fileSystem->remove([$gitCommitMsgFilename, $gitPreCommitFilename, $vendorConfigFilename]);
             }
             $this->getLogger()->debug('Config removed', ['file' => $vendorConfigFilename]);
             $this->getLogger()->debug('Pre commit hook removed', ['file' => $gitPreCommitFilename]);
             $this->getLogger()->debug('Commit msg hook removed', ['file' => $gitCommitMsgFilename]);
         }
     }
     if ($prettyOutput) {
         $progress->setMessage('Done', 'filename');
         $progress->finish();
         if (self::ACTION_INIT == $action) {
             $this->getSymfonyStyle()->success('GrumPHP is sniffing your vendors code!');
         } elseif (self::ACTION_DROP == $action) {
             $this->getSymfonyStyle()->note('GrumPHP stopped sniffing your vendors commits! Too bad ...');
         }
     }
     $this->getLogger()->debug('Finish', ['command_name' => $this->getName()]);
 }
예제 #18
0
 /**
  * @param int $width
  *
  * @return ProgressBar
  */
 private function createProgressBar($width)
 {
     $progress = new ProgressBar($this->output, $width);
     $progress->setBarWidth(50);
     $progress->display();
     return $progress;
 }
예제 #19
0
 /**
  * Downloads the oxid archive
  *
  * @param OutputInterface $output
  * @param $url
  * @return string
  */
 protected function downloadOxid(OutputInterface $output, $version)
 {
     $file = sys_get_temp_dir() . '/oxrun-' . time() . '.zip';
     $progressBar = null;
     $client = new Client();
     try {
         $githubToken = getenv('GITHUB_TOKEN');
         if ($githubToken) {
             $request = $client->createRequest('GET', $version['zip'] . '?access_token=' . $githubToken, array('save_to' => $file));
         } else {
             $request = $client->createRequest('GET', $version['zip'], array('save_to' => $file));
         }
         $request->getEmitter()->on('progress', function (ProgressEvent $e) use(&$progressBar, $output) {
             if (null === $progressBar && $e->downloadSize !== 0) {
                 ProgressBar::setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
                     return $this->formatSize($bar->getMaxSteps());
                 });
                 ProgressBar::setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
                     return str_pad($this->formatSize($bar->getStep()), 11, ' ', STR_PAD_LEFT);
                 });
                 $progressBar = new ProgressBar($output, $e->downloadSize);
                 $progressBar->setFormat('%current%/%max% %bar%  %percent:3s%%');
                 $progressBar->setRedrawFrequency(max(1, floor($e->downloadSize / 1000)));
                 $progressBar->setBarWidth(60);
                 if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
                     $progressBar->setEmptyBarCharacter('░');
                     // light shade character \u2591
                     $progressBar->setProgressCharacter('');
                     $progressBar->setBarCharacter('▓');
                     // dark shade character \u2593
                 }
                 $progressBar->start();
             }
             if ($progressBar) {
                 $progressBar->setProgress($e->downloaded);
             }
         });
         $client->send($request);
     } catch (ClientException $e) {
         throw new \RuntimeException(sprintf("There was an error downloading:\n%s", $e->getMessage()), null, $e);
     }
     if (null !== $progressBar) {
         $progressBar->finish();
         $output->writeln("\n");
     }
     return $file;
 }
예제 #20
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     global $spip_racine;
     global $spip_loaded;
     global $spip_version_branche;
     $restart = $input->getOption('restart');
     $requalifier = $input->getOption('maj');
     include_spip("base/abstract_sql");
     if ($spip_loaded) {
         chdir($spip_racine);
         if (!function_exists('passthru')) {
             $output->writeln("<error>Votre installation de PHP doit pouvoir exécuter des commandes externes avec la fonction passthru().</error>");
         } else {
             // requalifier les types d'apres les fichier du repertoire a_ajouter ?
             if ($requalifier !== "non") {
                 passthru("clear");
                 $output->writeln("<info>Requalification des données</info>");
                 // recaler apres coup
                 // prevoir aussi des : update entites_nommees set entite='Pays basque', type_entite='Pays' where entite='Pays' and extrait like '%Pays basque%' and type_entite='INDETERMINE' ;
                 lire_fichier('plugins/entites_nommees/recaler.txt', $recale);
                 $entites_a_revoir = explode("\n", $recale);
                 if (sizeof($entites_a_revoir) > 1) {
                     foreach ($entites_a_revoir as $e) {
                         if (preg_match(",^//,", $e) or preg_match(",^\$,", $e)) {
                             /**/
                             continue;
                         }
                         list($entite_actuelle, $entite_dans_extrait, $type_entite, $entite) = explode("\t", $e);
                         //var_dump($entite_actuelle,$entite_dans_extrait, $type_entite, $entite);
                         $sel = "select * from entites_nommees where (type_entite = 'INDETERMINE' or type_entite='Personnalités' or type_entite='Institutions automatiques') and entite= " . sql_quote($entite_actuelle) . " and extrait like '%" . addslashes($entite_dans_extrait) . "%'";
                         $q = sql_query($sel);
                         $nb = sql_count($q);
                         if ($nb > 0) {
                             echo "{$nb} {$entite_actuelle} ({$entite_dans_extrait}) => {$entite}\n";
                             $up = "update entites_nommees set entite=" . sql_quote($entite) . ", type_entite=" . sql_quote($type_entite) . " where (type_entite = 'INDETERMINE' or type_entite='Personnalités' or type_entite='Institutions automatiques') and entite= " . sql_quote($entite_actuelle) . " and extrait like '%" . addslashes($entite_dans_extrait) . "%'";
                             echo $up . "\n";
                             sql_query($up);
                         }
                         echo "\n";
                     }
                 }
                 include_spip('iterateur/data');
                 $types_requalif = inc_ls_to_array_dist(_DIR_RACINE . 'plugins/entites_nommees/listes_lexicales/a_ajouter/*');
                 /**/
                 foreach ($types_requalif as $t) {
                     if ($t['filename'] == "a_ajouter") {
                         continue;
                     }
                     $entites_a_revoir = $freq = array();
                     lire_fichier($t['dirname'] . "/" . $t['file'], $freq);
                     //echo $t['file'] . "\n" ;
                     $entites_a_revoir = explode("\n", $freq);
                     if (sizeof($entites_a_revoir) > 1) {
                         foreach ($entites_a_revoir as $e) {
                             $ent = sql_query("select * from entites_nommees where (type_entite = 'INDETERMINE' or type_entite='Personnalités') and entite= " . sql_quote($e));
                             $nb = sql_count($ent);
                             if ($nb > 0) {
                                 echo $nb . " entites " . $e . " de statut INDETERMINE => " . $t['filename'] . "\n";
                                 $up = "update entites_nommees set type_entite=" . str_replace("_", " ", sql_quote($t['filename'])) . " where  (type_entite = 'INDETERMINE' or type_entite='Personnalités') and entite=" . sql_quote($e) . "\n";
                                 echo $up . "\n";
                                 sql_query($up);
                                 echo "\n\n";
                             }
                         }
                     }
                 }
                 exit;
             }
             if ($restart !== "non") {
                 $output->writeln("<info>On efface tout et on recommence.</info>");
                 sql_query("truncate table entites_nommees");
             }
             // articles deja faits
             $articles_faits = array("0");
             $articles_sql = sql_allfetsel("id_article", "entites_nommees", "", "id_article");
             foreach ($articles_sql as $a) {
                 $articles_faits[] = $a['id_article'];
             }
             // chopper les articles non déjà faits ;
             $articles = sql_query("select a.id_article from spip_articles a where a.statut !='prepa' and a.id_secteur=" . _SECTEUR_ENTITES . " and a.id_article not in(" . implode(",", $articles_faits) . ") order by a.date_redac desc limit 0,1000");
             $res = sql_fetch_all($articles);
             // start and displays the progress bar
             $progress = new ProgressBar($output, sizeof($res));
             $progress->setBarWidth(100);
             $progress->setRedrawFrequency(1);
             $progress->setMessage("Génération des entités nommées...", 'message');
             /**/
             $progress->start();
             foreach ($res as $a) {
                 $art = sql_fetsel("id_article, titre, chapo, texte, date_redac", "spip_articles", "id_article=" . $a['id_article']);
                 $m = substr(" Traitement de l'article " . $art['id_article'] . " (" . $art['date_redac'] . ")", 0, 100);
                 $progress->setMessage($m, 'message');
                 // Trouver et enregistrer les entites nommées
                 include_spip("entites_fonctions");
                 $texte = preparer_texte($art['titre'] . " // \n" . $art['chapo'] . " // \n" . $art['texte'] . "\n");
                 $fragments = trouver_entites($texte, $art['id_article']);
                 enregistrer_entites($fragments, $art['id_article']);
                 // Si tout s'est bien passé, on avance la barre
                 $progress->setFormat("<fg=white;bg=blue>%message%</>\n" . '%current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%' . "\n\n");
                 $progress->advance();
             }
             ## FIN
             $output->writeln("<info>Check des entités : done.</info>");
             $output->writeln("\n\nMerci bien.\n");
         }
     } else {
         $output->writeln('<error>Vous n’êtes pas dans une installation de SPIP. Impossible de convertir le texte.</error>');
     }
 }