consistent verbosity
authorMichael Wallner <mike@php.net>
Sat, 28 Mar 2015 12:57:46 +0000 (13:57 +0100)
committerMichael Wallner <mike@php.net>
Sat, 28 Mar 2015 12:57:46 +0000 (13:57 +0100)
17 files changed:
bin/pharext
src/pharext/ExecCmd.php
src/pharext/Installer.php
src/pharext/Packager.php
src/pharext/Task/Activate.php
src/pharext/Task/BundleGenerator.php
src/pharext/Task/Cleanup.php
src/pharext/Task/Configure.php
src/pharext/Task/Extract.php
src/pharext/Task/GitClone.php
src/pharext/Task/Make.php
src/pharext/Task/PeclFixup.php
src/pharext/Task/PharCompress.php
src/pharext/Task/PharRename.php
src/pharext/Task/PharSign.php
src/pharext/Task/Phpize.php
src/pharext/Task/StreamFetch.php

index ae7170f4e6375a515a61afeabeaab3a48b765168..539504e897e1036c493df128fe5651d608594bf6 100755 (executable)
Binary files a/bin/pharext and b/bin/pharext differ
index 7e657f3d6f4bab3351988eb754d49c6639d7a032..5a6ee81f6fdad1be6b6eb4756d3c5cf966de58ae 100644 (file)
@@ -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]);
        }
 
        /**
index 60ca2262ce7316c76c1d911d283dec549fcfadd7..a90eb28e9acc97350465be252d22d20589568a3d 100644 (file)
@@ -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");
index 9acb5ebc848a229c62a7d0e7c74eec63bcbf13cc..f5ccfb80848667d63c38e98a323f94a28dfe5d48 100644 (file)
@@ -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());
                        }
                }
index 1bbd9a86fc6200a00bd6ac8c2e7fcc542b4049ca..3d7e05f017604863a469042634a5e362a7d249c5 100644 (file)
@@ -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;
        }
index aabf9c8627c991d4ee1e1f17f59e693a7c3cd8bc..28af6271eaf209b19ded2c1d70c35c703afec6ad 100644 (file)
@@ -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()) {
index c2cfefa8b768019dcc1c55202812e89460b99c72..3684806e62094c91f38a73ae8ad962d4510c7424 100644 (file)
@@ -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)) {
index 3effbfbb28b51c331bc71893e7d2b1933b12a78a..28957e9908712c1b8b42c7c15b53cc67ff90d8a4 100644 (file)
@@ -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;
index b2f954f0c44572957927f98e533739c6aad21565..d68b426dd129a4ac5d6956f33cf4a9ecbd4281b2 100644 (file)
@@ -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;
index 709a34a3af32aa2ebe7215d031420ff3c093820d..7b84ca1efa29abe34a543267ec1d436907d1c184 100644 (file)
@@ -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]);
index 9e7156561606af833e5241dc9682a2fbd905b5d1..61dbf00d46411b344b3254e5b1a5563702231b57 100644 (file)
@@ -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;
index 08a1d942eaa7c7aabb5c078d67f46f81fa6420f1..b237771055c51cf344d9397caa26591c0cf5ea56 100644 (file)
@@ -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;
                        }
index d090e2879c740fc93b51ae05038c87d8ea4c2e4d..ea0607f39a6e9291a91204b9cdcfa7a97d0a2e20 100644 (file)
@@ -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"])) {
index 19094c13f2b31270dbe387c626d9e70a3f89dd09..dc1bc4be7d3ea6f170a003d83defdea7519661a4 100644 (file)
@@ -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;
index 739c587582836610f2250720e2b3ca4c4f75ef46..8fa1e466f11c4d76c2ddabf91f8021bc42ad3950 100644 (file)
@@ -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;
        }
index ab70534322d269a2e773ec7655549f00f6f93543..a1da2e7a5870e42698a40b423f84e706f79a33d0 100644 (file)
@@ -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;
index 4f090efb74579b0b21970ca87ad7ee6f76a859cc..3b1fc29cb53b4db1ce44ff6261e91444e3c591e8 100644 (file)
@@ -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)) {