From: Vincent Vanwaelscappel Date: Thu, 20 Jun 2024 06:42:48 +0000 (+0200) Subject: wip #6968 @3 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=16730d5a71a6e4d8cc0e4a652cbb32b48b7e6878;p=cubist_util.git wip #6968 @3 --- diff --git a/src/CommandLine.php b/src/CommandLine.php index e27f668..ebbf377 100644 --- a/src/CommandLine.php +++ b/src/CommandLine.php @@ -122,15 +122,28 @@ class CommandLine public function execute($fonction = 'shell_exec') { + $startTime = microtime(true); $this->_preExecute(); if ($fonction instanceof SSH2) { $this->makeCommande(); + if (function_exists('start_measure')) { + start_measure('Exec CLI : ' . $this->commande); + } $o = $fonction->exec($this->commande); + if (function_exists('stop_measure')) { + stop_measure('Exec CLI : ' . $this->commande); + } file_put_contents($this->output, $o['output'] . "\n\n---\n\n" . $o['error']); } else if (null === $this->ssh) { $this->makeCommande($this->output, $this->error); + if (function_exists('start_measure')) { + start_measure('Exec CLI : ' . $this->commande); + } $fonction($this->commande); + if (function_exists('stop_measure')) { + stop_measure('Exec CLI : ' . $this->commande); + } } else { $this->makeCommande(); @@ -146,8 +159,13 @@ class CommandLine } $this->commande = $c; - + if (function_exists('start_measure')) { + start_measure('Exec CLI : ' . $this->commande); + } $fonction($c); + if (function_exists('stop_measure')) { + stop_measure('Exec CLI : ' . $this->commande); + } } $endTime = microtime(true); $this->execTime = $endTime - $startTime; @@ -177,13 +195,13 @@ class CommandLine $commande = $this->program; $commandes = array(); foreach ($this->args as $arg) { - if (strlen($arg[0]) == 1) { + if (null === $arg[0]) { + $commande .= ' ' . $arg[1]; + } else if (strlen($arg[0]) == 1) { $commande .= ' -' . $arg[0]; if (null !== $arg[1]) { $commande .= ' ' . $arg[1]; } - } elseif (null === $arg[0]) { - $commande .= ' ' . $arg[1]; } else { if (substr($arg[0], 0, 1) == '-') { $commande .= ' ' . $arg[0]; diff --git a/src/Files/Files.php b/src/Files/Files.php index 6f724cd..a7a0ae4 100644 --- a/src/Files/Files.php +++ b/src/Files/Files.php @@ -74,14 +74,31 @@ class Files * @param array $exclude * @return array|\RecursiveIteratorIterator */ - public static function getRecursiveDirectoryIterator($path, $mode = \RecursiveIteratorIterator::SELF_FIRST, $exclude = array()) + public static function getRecursiveDirectoryIterator($path, $mode = \RecursiveIteratorIterator::SELF_FIRST, $exclude = []) { $path = realpath($path); if (!file_exists($path)) { - return array(); + return []; + } + return new \RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, $exclude), $mode); + } + + public static function listFilesOfDirectory($path, &$res = []) + { + $files = scandir($path); + + foreach ($files as $key => $value) { + $path = realpath($path . DIRECTORY_SEPARATOR . $value); + if (!is_dir($path)) { + $res[] = $path; + } else if ($value != "." && $value != "..") { + static::listFilesOfDirectory($path, $res); + $res[] = $path; + } } - $res = new \RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, $exclude), $mode); + return $res; + } /** diff --git a/src/Files/VirtualDirectory.php b/src/Files/VirtualDirectory.php index ac2579d..9b81573 100644 --- a/src/Files/VirtualDirectory.php +++ b/src/Files/VirtualDirectory.php @@ -101,7 +101,8 @@ class VirtualDirectory Files::mkdir($from); } } - $this->_directories[$this->path($to)] = $from; + $to = $this->path($to); + $this->_directories[$to] = $from; return $this; } @@ -129,9 +130,7 @@ class VirtualDirectory Files::mkdir($dir); } - foreach ($this->_copy as $to => $from) { - if ($delete) { $existing[$to] = true; } @@ -144,8 +143,9 @@ class VirtualDirectory if (!$this->compare($from, $to)) { $to_esc = escapeshellarg($to); $from_esc = escapeshellarg($from); - `cp -p $from_esc $to_esc`; - $this->log('Copy file ' . $to); + $cpcmd = "cp -p $from_esc $to_esc"; + `$cpcmd`; + $this->log('Copy file ' . $to . ' : ' . $cpcmd); if (!file_exists($to)) { $this->throwError(sprintf('Failed to copy %s to %s', $from, $to)); } @@ -183,20 +183,30 @@ class VirtualDirectory protected function _addDirectory($from, $to) { $from = realpath($from); - $files = Files::getRecursiveDirectoryIterator($from); + Files::listFilesOfDirectory($from, $files); - foreach ($files as $file) { - /* @var $file SplFileInfo */ - if ($file->isDir()) { - continue; - } - $path = $file->getRealPath(); + + if (!count($files)) { + dddd(`ls -l $from`); + } + + $relativeTo = $this->relativePath($to); + + $total = 0; + $parsed = 0; + + foreach ($files as $path) { + $total++; $dest = str_replace($from, '', $path); if (!$path) { + $this->log('Skip file ' . $path . ' because no real path'); continue; } - $this->copy($path, $this->relativePath($to) . '/' . ltrim($dest, '/'), true); + $this->copy($path, $relativeTo . '/' . ltrim($dest, '/'), true); + $parsed++; } + + $this->log('parsed directory ' . $from . ' (' . $to . ') (' . $parsed . '/' . $total . ')'); } protected function _delete($existing = array()) diff --git a/src/Html.php b/src/Html.php index c7bc67c..f231faa 100644 --- a/src/Html.php +++ b/src/Html.php @@ -1,7 +1,9 @@ childNodes as $node) { + if ($node instanceof \DOMText) { + $res[] = $node->nodeValue; + } + if ($node->hasChildNodes()) { + $res = array_merge($res, static::_getTextNode($node)); + } + } + return $res; + } + + public static function getTextNodes($string) + { + if (!$string) { + return []; + } + try { + $doc = new DOMDocument('1.0', 'utf-8'); + $doc->loadHTML($string); + + $res= static::_getTextNode($doc); + return $res; + } catch (\Exception $e) { + return [$string]; + } + } + }