]> granicus.if.org Git - php/commitdiff
* added "pear info" and "pear show-config" commands
authorStig Bakken <ssb@php.net>
Wed, 31 Oct 2001 05:39:11 +0000 (05:39 +0000)
committerStig Bakken <ssb@php.net>
Wed, 31 Oct 2001 05:39:11 +0000 (05:39 +0000)
* "pear install" now using the package registry

pear/PEAR/Installer.php
pear/PEAR/Packager.php
pear/PEAR/Registry.php
pear/scripts/pear.in

index 647d1bf499854bd3f06d4fb667fc02f823e819b4..0ad4278cb1ab5ca181db35764eef56adf0e0e5a2 100644 (file)
@@ -21,6 +21,7 @@
 // $Id$
 
 require_once 'PEAR/Common.php';
+require_once 'PEAR/Registry.php';
 
 /**
  * Administration class used to install PEAR packages and maintain the
@@ -90,6 +91,7 @@ class PEAR_Installer extends PEAR_Common
     {
         // XXX FIXME Add here code to manage packages database
         //$this->loadPackageList("$this->statedir/packages.lst");
+        $registry = new PEAR_Registry;
         $oldcwd = getcwd();
         $need_download = false;
         if (preg_match('#^(http|ftp)://#', $pkgfile)) {
@@ -149,7 +151,7 @@ class PEAR_Installer extends PEAR_Common
         // Assume the decompressed dir name
         if (($pos = strrpos($file, '.')) === false) {
             chdir($oldcwd);
-            return $this->raiseError('package doesn\'t follow the package name convention');
+            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';
@@ -166,6 +168,10 @@ class PEAR_Installer extends PEAR_Common
             return $pkginfo;
         }
 
+        if ($registry->packageExists($pkginfo['package'])) {
+            return $this->raiseError("package already installed");
+        }
+
         // Copy files to dest dir ---------------------------------------
         if (!is_dir($this->phpdir)) {
             chdir($oldcwd);
@@ -184,6 +190,7 @@ class PEAR_Installer extends PEAR_Common
             $fname = $tmp_path . DIRECTORY_SEPARATOR . $fname;
             $this->_installFile($fname, $dest_dir, $atts);
         }
+        $registry->addPackage($pkginfo['package'], $pkginfo);
         chdir($oldcwd);
         return true;
     }
index 8ad7ea19723e83efed0d9ecc82b1c4b28a46f117..44a88c6e62da0e7821ace138fd9c43429912b8ae 100644 (file)
@@ -114,6 +114,9 @@ class PEAR_Packager extends PEAR_Common
         }
         $pwd = getcwd();
         $pkgfile = basename($pkgfile);
+        if ($pkginfo['release_state'] == 'snapshot') {
+            $pkginfo['version'] = date('Ymd');
+        }
         // don't want strange characters
         $pkgname    = ereg_replace ('[^a-zA-Z0-9._]', '_', $pkginfo['package']);
         $pkgversion = ereg_replace ('[^a-zA-Z0-9._\-]', '_', $pkginfo['version']);
index d5319a45de4b074377f7cf7041eca5964db529e2..c0d42c9e108cdce73337f8c335f590737ebd912f 100644 (file)
@@ -92,7 +92,7 @@ class PEAR_Registry
     // }}}
     // {{{ addPackage()
 
-    function addPackage($package, $info)
+    function addPackage($package, &$info)
     {
         if ($this->packageExists($package)) {
             return false;
@@ -136,7 +136,7 @@ class PEAR_Registry
     // }}}
     // {{{ updatePackage()
 
-    function updatePackage($package, $info)
+    function updatePackage($package, &$info)
     {
         $oldinfo = $this->packageInfo($package);
         if (empty($oldinfo)) {
index bba3c62adc1c691e32e6b59f96c970e78a70f99f..89b3714b6835b8e4863b21eaa2bef434ed0d4bb1 100644 (file)
@@ -1,5 +1,5 @@
 #!@prefix@/bin/php -Cq
-<?php // -*- C++ -*-
+<?php // -*- PHP -*-
 //
 // +----------------------------------------------------------------------+
 // | PHP version 4.0                                                      |
@@ -19,6 +19,7 @@
 // +----------------------------------------------------------------------+
 //
 require_once 'PEAR.php';
+require_once 'PEAR/Common.php';
 require_once 'PEAR/Config.php';
 require_once 'PEAR/Remote.php';
 require_once 'PEAR/Registry.php';
@@ -30,7 +31,7 @@ PEAR::setErrorHandling(PEAR_ERROR_PRINT, "pear: %s\n");
 
 // {{{ config file and option parsing
 
-$options = Console_Getopt::getopt($argv, "c:C:d:D:h?sSqv");
+$options = Console_Getopt::getopt($argv, "c:C:d:D:h?sSqu:v");
 if (PEAR::isError($options)) {
     usage($options);
 }
@@ -78,6 +79,9 @@ foreach ($opts as $opt) {
         case 'S':
             $store_default_config = true;
             break;
+        case 'u':
+            $config->toDefault($param);
+            break;
         case 'v':
             $verbose++;
             break;
@@ -100,15 +104,18 @@ if ($store_user_config) {
 }
 
 $fallback_config = array(
-    'php_dir' => PEAR_INSTALL_DIR,
-    'ext_dir' => PEAR_EXTENSION_DIR,
-    'doc_dir' => '',
-    'verbose' => true,
+    'master_server' => 'pear.php.net',
+    'php_dir'       => PEAR_INSTALL_DIR,
+    'ext_dir'       => PEAR_EXTENSION_DIR,
+    'doc_dir'       => '',
+    'verbose'       => true,
 );
+$fallback_done = array();
 
 foreach ($fallback_config as $key => $value) {
     if (!$config->isDefined($key)) {
         $config->set($key, $value);
+        $fallback_done[$key] = true;
     }
 }
 
@@ -162,6 +169,7 @@ switch ($command) {
         include_once 'PEAR/Packager.php';
         $pkginfofile = $options[1][2];
         $packager =& new PEAR_Packager($script_dir, $ext_dir, $doc_dir);
+        $packager->setErrorHandling(PEAR_ERROR_DIE, "pear page: %s\n");
         $packager->debug = $verbose;
         if (PEAR::isError($packager->Package($pkginfofile))) {
             print "\npackage failed\n";
@@ -171,6 +179,18 @@ switch ($command) {
         break;
     }
 
+    // }}}
+    // {{{ info
+
+    case 'info': {
+        $parser = new PEAR_Common;
+        $parser->setErrorHandling(PEAR_ERROR_DIE, "pear info: %s\n");
+        $info = $parser->infoFromTgzFile($options[1][2]);
+        unset($info['filelist']);
+        present_array($info);
+        break;
+    }
+
     // }}}
     // {{{ list
 
@@ -221,6 +241,25 @@ switch ($command) {
         break;
     }
 
+    // }}}
+    // {{{ show-config
+
+    case 'show-config': {
+        $keys = $config->getKeys();
+        foreach ($keys as $key) {
+            $value = $config->get($key);
+            $xi = "";
+            if ($config->isDefaulted($key)) {
+                $xi .= " (default)";
+            }
+            if ($fallback_done[$key]) {
+                $xi .= " (fallback)";
+            }
+            printf("%s = %s%s\n", $key, $value, $xi);
+        }
+        break;
+    }
+
     // }}}
     default: {
         if (!$store_default_config && !$store_user_config) {
@@ -251,12 +290,14 @@ function usage($error = null)
           "     -D foo=bar set system config variable `foo' to `bar'\n".
           "     -s         store user configuration\n".
           "     -s         store system configuration\n".
+          "     -u foo     unset `foo' in the user 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".
+          "   show-config\n".
           "\n");
     fclose($stderr);
     exit;
@@ -264,4 +305,29 @@ function usage($error = null)
 
 // }}}
 
+function present_array(&$arr, $keys = null)
+{
+    if ($keys === null) {
+        $keys = array_keys($arr);
+    }
+    $longest_key = max(array_map("strlen", array_keys($arr)));
+    $format_string = "%{$longest_key}s : %s\n";
+    foreach ($keys as $k) {
+        if (is_array($arr[$k])) {
+            $v = implode(", ", $arr[$k]);
+        } else {
+            $v = $arr[$k];
+        }
+        printf($format_string, $k, $v);
+    }
+}
+
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
 ?>