From: Michael Wallner Date: Sat, 28 Mar 2015 12:57:46 +0000 (+0100) Subject: consistent verbosity X-Git-Tag: v3.0.0~7 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=337e76964be2ed6724633ac477affc3a28426c97;p=pharext%2Fpharext consistent verbosity --- diff --git a/bin/pharext b/bin/pharext index ae7170f..539504e 100755 Binary files a/bin/pharext and b/bin/pharext differ diff --git a/src/pharext/ExecCmd.php b/src/pharext/ExecCmd.php index 7e657f3..5a6ee81 100644 --- a/src/pharext/ExecCmd.php +++ b/src/pharext/ExecCmd.php @@ -94,7 +94,7 @@ class ExecCmd print $this->progress($data, 0); } else { if ($verbose) { - printf("%s\n", $data); + printf("%s", $data); } $this->output .= $data; } @@ -112,14 +112,18 @@ class ExecCmd * @return string */ private function progress($string, $flags) { - static $c = 0; - static $s = ["\\","|","/","-"]; + static $counter = 0; + static $symbols = ["\\","|","/","-"]; $this->output .= $string; + + if (false !== strpos($string, "\n")) { + ++$counter; + } return $flags & PHP_OUTPUT_HANDLER_FINAL ? " \r" - : sprintf(" %s\r", $s[$c++ % count($s)]); + : sprintf(" %s\r", $symbols[$counter % 4]); } /** diff --git a/src/pharext/Installer.php b/src/pharext/Installer.php index 60ca226..a90eb28 100644 --- a/src/pharext/Installer.php +++ b/src/pharext/Installer.php @@ -15,6 +15,12 @@ class Installer implements Command { use CliCommand; + /** + * Cleanups + * @var array + */ + private $cleanup = []; + /** * Create the command */ @@ -53,9 +59,19 @@ class Installer implements Command ]); } + /** + * Perform cleaniup + */ + function __destruct() { + foreach ($this->cleanup as $cleanup) { + $cleanup->run(); + } + } + private function extract(Phar $phar) { - $this->debug("Extracting %s ...\n", basename($phar->getPath())); - return (new Task\Extract($phar))->run($this->verbosity()); + $temp = (new Task\Extract($phar))->run($this->verbosity()); + $this->cleanup[] = new Task\Cleanup($temp); + return $temp; } private function hooks(SplObjectStorage $phars) { @@ -162,7 +178,6 @@ class Installer implements Command $this->info("Installing %s ...\n", basename($phar->getPath())); $this->install($list[$phar]); $this->activate($list[$phar]); - $this->cleanup($list[$phar]); $this->info("Successfully installed %s!\n", basename($phar->getPath())); } } catch (\Exception $e) { @@ -176,31 +191,23 @@ class Installer implements Command */ private function install($temp) { // phpize - $this->info("Running phpize ...\n"); $phpize = new Task\Phpize($temp, $this->args->prefix, $this->args->{"common-name"}); $phpize->run($this->verbosity()); // configure - $this->info("Running configure ...\n"); $configure = new Task\Configure($temp, $this->args->configure, $this->args->prefix, $this->args{"common-name"}); $configure->run($this->verbosity()); // make - $this->info("Running make ...\n"); $make = new Task\Make($temp); $make->run($this->verbosity()); // install - $this->info("Running make install ...\n"); $sudo = isset($this->args->sudo) ? $this->args->sudo : null; $install = new Task\Make($temp, ["install"], $sudo); $install->run($this->verbosity()); } - private function cleanup($temp) { - (new Task\Cleanup($temp))->run(); - } - private function activate($temp) { if ($this->args->ini) { $files = [realpath($this->args->ini)]; @@ -212,7 +219,6 @@ class Installer implements Command $sudo = isset($this->args->sudo) ? $this->args->sudo : null; $type = $this->metadata("type") ?: "extension"; - $this->info("Running INI activation ...\n"); $activate = new Task\Activate($temp, $files, $type, $this->args->prefix, $this->args{"common-name"}, $sudo); if (!$activate->run($this->verbosity())) { $this->info("Extension already activated ...\n"); diff --git a/src/pharext/Packager.php b/src/pharext/Packager.php index 9acb5eb..f5ccfb8 100644 --- a/src/pharext/Packager.php +++ b/src/pharext/Packager.php @@ -141,8 +141,6 @@ class Packager implements Command * @return string local source */ private function download($source) { - $this->info("Fetching remote source %s ...\n", $source); - if ($this->args->git) { $task = new Task\GitClone($source); } else { @@ -167,8 +165,6 @@ class Packager implements Command * @return string extracted directory */ private function extract($source) { - $this->debug("Extracting %s ...\n", $source); - $task = new Task\Extract($source); $dest = $task->run($this->verbosity()); @@ -192,7 +188,6 @@ class Packager implements Command $this->cleanup[] = new Task\Cleanup($source); if ($this->args->pecl) { - $this->debug("Sanitizing PECL dir ...\n"); $source = (new Task\PeclFixup($source))->run($this->verbosity()); } } diff --git a/src/pharext/Task/Activate.php b/src/pharext/Task/Activate.php index 1bbd9a8..3d7e05f 100644 --- a/src/pharext/Task/Activate.php +++ b/src/pharext/Task/Activate.php @@ -65,6 +65,9 @@ class Activate implements Task * @return boolean false, if extension was already activated */ public function run($verbose = false) { + if ($verbose !== false) { + printf("Running INI activation ...\n"); + } $extension = basename(current(glob("{$this->cwd}/modules/*.so"))); if ($this->type === "zend_extension") { @@ -74,6 +77,9 @@ class Activate implements Task } foreach ($this->inis as $file) { + if ($verbose) { + printf("Checking %s ...\n", $file); + } $temp = new Tempfile("phpini"); foreach (file($file) as $line) { if (preg_match("/^\s*{$this->type}\s*=\s*[\"']?{$pattern}[\"']?\s*(;.*)?\$/", $line)) { @@ -84,6 +90,9 @@ class Activate implements Task } /* not found; append to last processed file, which is the main by default */ + if ($verbose) { + printf("Activating in %s ...\n", $file); + } fprintf($temp->getStream(), $this->type . "=%s\n", $extension); $temp->closeStream(); @@ -112,6 +121,10 @@ class Activate implements Task $cmd->setSu($this->sudo); } $cmd->run([$path, $file]); + + if ($verbose) { + printf("Replaced %s ...\n", $file); + } return true; } diff --git a/src/pharext/Task/BundleGenerator.php b/src/pharext/Task/BundleGenerator.php index aabf9c8..28af627 100644 --- a/src/pharext/Task/BundleGenerator.php +++ b/src/pharext/Task/BundleGenerator.php @@ -17,6 +17,9 @@ class BundleGenerator implements Task * @return Generator */ public function run($verbose = false) { + if ($verbose) { + printf("Packaging pharext ... \n"); + } $rdi = new RecursiveDirectoryIterator(dirname(dirname(__DIR__))); $rii = new RecursiveIteratorIterator($rdi); for ($rii->rewind(); $rii->valid(); $rii->next()) { diff --git a/src/pharext/Task/Cleanup.php b/src/pharext/Task/Cleanup.php index c2cfefa..3684806 100644 --- a/src/pharext/Task/Cleanup.php +++ b/src/pharext/Task/Cleanup.php @@ -26,6 +26,9 @@ class Cleanup implements Task * @param bool $verbose */ public function run($verbose = false) { + if ($verbose) { + printf("Cleaning up %s ...\n", $this->rm); + } if ($this->rm instanceof Tempfile) { unset($this->rm); } elseif (is_dir($this->rm)) { diff --git a/src/pharext/Task/Configure.php b/src/pharext/Task/Configure.php index 3effbfb..28957e9 100644 --- a/src/pharext/Task/Configure.php +++ b/src/pharext/Task/Configure.php @@ -40,6 +40,9 @@ class Configure implements Task } public function run($verbose = false) { + if ($verbose !== false) { + printf("Running ./configure ...\n"); + } $pwd = getcwd(); if (!chdir($this->cwd)) { throw new Exception; diff --git a/src/pharext/Task/Extract.php b/src/pharext/Task/Extract.php index b2f954f..d68b426 100644 --- a/src/pharext/Task/Extract.php +++ b/src/pharext/Task/Extract.php @@ -34,6 +34,9 @@ class Extract implements Task * @return \pharext\Tempdir */ public function run($verbose = false) { + if ($verbose) { + printf("Extracting %s ...\n", basename($this->source->getPath())); + } $dest = new Tempdir("extract"); $this->source->extractTo($dest); return $dest; diff --git a/src/pharext/Task/GitClone.php b/src/pharext/Task/GitClone.php index 709a34a..7b84ca1 100644 --- a/src/pharext/Task/GitClone.php +++ b/src/pharext/Task/GitClone.php @@ -28,6 +28,9 @@ class GitClone implements Task * @return \pharext\Tempdir */ public function run($verbose = false) { + if ($verbose !== false) { + printf("Fetching %s ...\n", $this->source); + } $local = new Tempdir("gitclone"); $cmd = new ExecCmd("git", $verbose); $cmd->run(["clone", $this->source, $local]); diff --git a/src/pharext/Task/Make.php b/src/pharext/Task/Make.php index 9e71565..61dbf00 100644 --- a/src/pharext/Task/Make.php +++ b/src/pharext/Task/Make.php @@ -44,6 +44,15 @@ class Make implements Task * @throws \pharext\Exception */ public function run($verbose = false) { + if ($verbose !== false) { + printf("Running make"); + if ($this->args) { + foreach ($this->args as $arg) { + printf(" %s", $arg); + } + } + printf(" ...\n"); + } $pwd = getcwd(); if (!chdir($this->cwd)) { throw new Exception; diff --git a/src/pharext/Task/PeclFixup.php b/src/pharext/Task/PeclFixup.php index 08a1d94..b237771 100644 --- a/src/pharext/Task/PeclFixup.php +++ b/src/pharext/Task/PeclFixup.php @@ -28,6 +28,9 @@ class PeclFixup implements Task * @throws \pahrext\Exception */ public function run($verbose = false) { + if ($verbose !== false) { + printf("Sanitizing PECL dir ...\n"); + } $dirs = glob("{$this->source}/*", GLOB_ONLYDIR); $files = array_diff(glob("{$this->source}/*"), $dirs); @@ -38,6 +41,9 @@ class PeclFixup implements Task $dest = current($dirs); foreach ($files as $file) { + if ($verbose) { + printf("Moving %s into %s ...\n", basename($file), basename($dest)); + } if (!rename($file, "$dest/" . basename($file))) { throw new Exception; } diff --git a/src/pharext/Task/PharCompress.php b/src/pharext/Task/PharCompress.php index d090e28..ea0607f 100644 --- a/src/pharext/Task/PharCompress.php +++ b/src/pharext/Task/PharCompress.php @@ -55,6 +55,9 @@ class PharCompress implements Task * @return string */ public function run($verbose = false) { + if ($verbose) { + printf("Compressing %s ...\n", basename($this->package->getPath())); + } $phar = $this->package->compress($this->encoding); $meta = $phar->getMetadata(); if (isset($meta["stub"])) { diff --git a/src/pharext/Task/PharRename.php b/src/pharext/Task/PharRename.php index 19094c1..dc1bc4b 100644 --- a/src/pharext/Task/PharRename.php +++ b/src/pharext/Task/PharRename.php @@ -44,6 +44,10 @@ class PharRename implements Task public function run($verbose = false) { $extension = substr(strstr($this->phar, "-pharext.phar"), 8); $name = sprintf("%s/%s.ext%s", $this->dest, $this->name, $extension); + + if ($verbose) { + printf("Renaming %s to %s ...\n", basename($this->phar), basename($name)); + } if (!rename($this->phar, $name)) { throw new Exception; diff --git a/src/pharext/Task/PharSign.php b/src/pharext/Task/PharSign.php index 739c587..8fa1e46 100644 --- a/src/pharext/Task/PharSign.php +++ b/src/pharext/Task/PharSign.php @@ -42,6 +42,9 @@ class PharSign implements Task * @return \pharext\Openssl\PrivateKey */ public function run($verbose = false) { + if ($verbose) { + printf("Signing %s ...\n", basename($this->phar->getPath())); + } $this->pkey->sign($this->phar); return $this->pkey; } diff --git a/src/pharext/Task/Phpize.php b/src/pharext/Task/Phpize.php index ab70534..a1da2e7 100644 --- a/src/pharext/Task/Phpize.php +++ b/src/pharext/Task/Phpize.php @@ -41,6 +41,9 @@ class Phpize implements Task * @throws \pharext\Exception */ public function run($verbose = false) { + if ($verbose !== false) { + printf("Running %s ...\n", $this->phpize); + } $pwd = getcwd(); if (!chdir($this->cwd)) { throw new Exception; diff --git a/src/pharext/Task/StreamFetch.php b/src/pharext/Task/StreamFetch.php index 4f090ef..3b1fc29 100644 --- a/src/pharext/Task/StreamFetch.php +++ b/src/pharext/Task/StreamFetch.php @@ -55,6 +55,9 @@ class StreamFetch implements Task * @throws \pharext\Exception */ public function run($verbose = false) { + if ($verbose !== false) { + printf("Fetching %s ...\n", $this->source); + } $context = $this->createStreamContext(); if (!$remote = fopen($this->source, "r", false, $context)) {