]> granicus.if.org Git - php/commitdiff
* started working on "pear list" command
authorStig Bakken <ssb@php.net>
Mon, 29 Oct 2001 14:15:43 +0000 (14:15 +0000)
committerStig Bakken <ssb@php.net>
Mon, 29 Oct 2001 14:15:43 +0000 (14:15 +0000)
pear/PEAR/Installer.php
pear/PEAR/Registry.php
pear/scripts/pear.in

index 1bd0eabc1b0cd3cafc42015b4c900f9077244160..0caf515f365be18dba96ddff9cfb71365ec2cc7a 100644 (file)
@@ -75,15 +75,6 @@ class PEAR_Installer extends PEAR_Common
         $this->statedir = "/var/lib/php"; // XXX FIXME Windows
     }
 
-    // }}}
-    // {{{ destructor
-
-    function _PEAR_Installer()
-    {
-        chdir($this->pwd);
-        $this->_PEAR_Common();
-    }
-
     // }}}
     // {{{ install()
 
@@ -99,7 +90,7 @@ class PEAR_Installer extends PEAR_Common
     {
         // XXX FIXME Add here code to manage packages database
         //$this->loadPackageList("$this->statedir/packages.lst");
-        $this->pwd = getcwd();
+        $oldcwd = getcwd();
         $need_download = false;
         if (preg_match('#^(http|ftp)://#', $pkgfile)) {
             $need_download = true;
@@ -144,34 +135,40 @@ class PEAR_Installer extends PEAR_Common
         $pkgfile = getcwd() . DIRECTORY_SEPARATOR . basename($pkgfile);
 
         if (PEAR::isError($tmpdir = $this->mkTempDir())) {
+            chdir($oldcwd);
             return $tmpdir;
         }
         $this->log(2, '+ tmp dir created at ' . $tmpdir);
 
         $tar = new Archive_Tar($pkgfile, true);
         if (!$tar->extract($tmpdir)) {
+            chdir($oldcwd);
             return $this->raiseError("Unable to unpack $pkgfile");
         }
         $file = basename($pkgfile);
         // Assume the decompressed dir name
         if (($pos = strrpos($file, '.')) === false) {
+            chdir($oldcwd);
             return $this->raiseError('package doesn\'t follow the package name convention');
         }
         $pkgdir = substr($file, 0, $pos);
         $descfile = $tmpdir . DIRECTORY_SEPARATOR . $pkgdir . DIRECTORY_SEPARATOR . 'package.xml';
 
         if (!is_file($descfile)) {
+            chdir($oldcwd);
             return $this->raiseError("No package.xml file after extracting the archive.");
         }
 
         // Parse xml file -----------------------------------------------
         $pkginfo = $this->infoFromDescriptionFile($descfile);
         if (PEAR::isError($pkginfo)) {
+            chdir($oldcwd);
             return $pkginfo;
         }
 
         // Copy files to dest dir ---------------------------------------
         if (!is_dir($this->phpdir)) {
+            chdir($oldcwd);
             return $this->raiseError("No script destination directory found\n",
                                      null, PEAR_ERROR_DIE);
         }
@@ -187,6 +184,7 @@ class PEAR_Installer extends PEAR_Common
             $fname = $tmp_path . DIRECTORY_SEPARATOR . $fname;
             $this->_installFile($fname, $dest_dir, $atts);
         }
+        chdir($oldcwd);
         return true;
     }
 
@@ -228,6 +226,8 @@ class PEAR_Installer extends PEAR_Common
         $this->log(1, "installed file $dest_file");
         return true;
     }
+
     // }}}
 }
+
 ?>
\ No newline at end of file
index 7055951654e4e8a84a05a30ba01121c350a23c24..d5319a45de4b074377f7cf7041eca5964db529e2 100644 (file)
@@ -156,8 +156,11 @@ class PEAR_Registry
 
     function listPackages()
     {
-        $dp = opendir($this->statedir);
         $pkglist = array();
+        $dp = @opendir($this->statedir);
+        if (!$dp) {
+            return $pkglist;
+        }
         while ($ent = readdir($dp)) {
             if ($ent{0} == "." || substr($ent, -4) != ".inf") {
                 continue;
index 6b0e5bbc9a2f31e3ee7c3ca36359e05987644763..bba3c62adc1c691e32e6b59f96c970e78a70f99f 100644 (file)
@@ -21,6 +21,7 @@
 require_once 'PEAR.php';
 require_once 'PEAR/Config.php';
 require_once 'PEAR/Remote.php';
+require_once 'PEAR/Registry.php';
 require_once 'Console/Getopt.php';
 
 error_reporting(E_ALL ^ E_NOTICE);
@@ -29,7 +30,7 @@ PEAR::setErrorHandling(PEAR_ERROR_PRINT, "pear: %s\n");
 
 // {{{ config file and option parsing
 
-$options = Console_Getopt::getopt($argv, "c:C:d:D:h?sS");
+$options = Console_Getopt::getopt($argv, "c:C:d:D:h?sSqv");
 if (PEAR::isError($options)) {
     usage($options);
 }
@@ -58,6 +59,7 @@ foreach ($opts as $opt) {
 $config = new PEAR_Config($pear_user_config, $pear_default_config);
 $store_user_config = false;
 $store_default_config = false;
+$verbose = 0;
 
 foreach ($opts as $opt) {
     $param = $opt[1];
@@ -76,6 +78,12 @@ foreach ($opts as $opt) {
         case 'S':
             $store_default_config = true;
             break;
+        case 'v':
+            $verbose++;
+            break;
+        case 'q':
+            $verbose--;
+            break;
     }
 }
 
@@ -109,9 +117,28 @@ $script_dir = $config->get("php_dir");
 $ext_dir    = $config->get("ext_dir");
 $doc_dir    = $config->get("doc_dir");
 
+$command = $options[1][1];
+$rest = array_slice($options[1], 2);
+
+$command_options = array(
+    "list" => "v",
+);
+
+if (isset($command_options[$command])) {
+    $tmp = Console_Getopt::getopt($rest, $command_options[$command]);
+    if (PEAR::isError($tmp)) {
+        usage($tmp);
+    }
+    $cmdopt = $tmp[0];
+    $cmdargs = $tmp[1];
+} else {
+    $cmdopt = array();
+    $cmdargs = $rest;
+}
+
+
 // }}}
 
-$command = $options[1][1];
 switch ($command) {
     // {{{ install
 
@@ -145,12 +172,38 @@ switch ($command) {
     }
 
     // }}}
-    // {{{ list-packages
+    // {{{ list
+
+    case 'list': {
+        $reg = new PEAR_Registry;
+        $installed = $reg->packageInfo();
+        $i = $j = 0;
+        print "Installed packages:\n===================\n";
+        foreach ($installed as $package) {
+            if ($i++ % 20 == 0) {
+                if ($j++ > 0) {
+                    print "\n";
+                }
+                printf("%-20s %-10s %-15s %s\n",
+                       "Package", "Stable", "Lead", "Category");
+                print str_repeat("=", 75)."\n";
+            }
+            $stable = $package['stable'];
+            printf("%-20s %-10s %-15s %s\n", $package['name'],
+                   $stable ? $stable : "???",
+                   $package['lead'], $package['category']);
+        }
+        break;
+    }
+
+    // }}}
+    // {{{ list-remote
 
-    case 'list-packages': {
+    case 'list-remote': {
         $remote = new PEAR_Remote($config);
         $result = $remote->call('package.listAll');
         $i = $j = 0;
+        print "Available packages:\n===================\n";
         foreach ($result as $package) {
             if ($i++ % 20 == 0) {
                 if ($j++ > 0) {
@@ -190,14 +243,20 @@ function usage($error = null)
     fputs($stderr,
           "Usage: pear [options] command <parameters>\n".
           "Options:\n".
-          "     -v        set verbosity level to <n> (0-2, default 1)\n".
-          "     -p <dir>  set script install dir (absolute path)\n".
-          "     -e <dir>  set extension install dir (absolute path)\n".
-          "     -d <dir>  set documentation dest dir (absolute path)\n".
-          "     -h, -?    display help/usage (this message)\n".
+          "     -v         increase verbosity level (default 1)\n".
+          "     -q         be quiet, decrease verbosity level\n".
+          "     -c file    find user configuration in `file'\n".
+          "     -C file    find system configuration in `file'\n".
+          "     -d foo=bar set user config variable `foo' to `bar'\n".
+          "     -D foo=bar set system config variable `foo' to `bar'\n".
+          "     -s         store user configuration\n".
+          "     -s         store system configuration\n".
+          "     -h, -?     display help/usage (this message)\n".
           "Commands:\n".
           "   install <package file>\n".
           "   package [package info file]\n".
+          "   list\n".
+          "   list-remote\n".
           "\n");
     fclose($stderr);
     exit;