From: Stig Bakken Date: Wed, 31 Oct 2001 05:39:11 +0000 (+0000) Subject: * added "pear info" and "pear show-config" commands X-Git-Tag: ChangeLog~464 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f0df3f5f826e43073ba413e4492c1583e0292ead;p=php * added "pear info" and "pear show-config" commands * "pear install" now using the package registry --- diff --git a/pear/PEAR/Installer.php b/pear/PEAR/Installer.php index 647d1bf499..0ad4278cb1 100644 --- a/pear/PEAR/Installer.php +++ b/pear/PEAR/Installer.php @@ -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; } diff --git a/pear/PEAR/Packager.php b/pear/PEAR/Packager.php index 8ad7ea1972..44a88c6e62 100644 --- a/pear/PEAR/Packager.php +++ b/pear/PEAR/Packager.php @@ -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']); diff --git a/pear/PEAR/Registry.php b/pear/PEAR/Registry.php index d5319a45de..c0d42c9e10 100644 --- a/pear/PEAR/Registry.php +++ b/pear/PEAR/Registry.php @@ -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)) { diff --git a/pear/scripts/pear.in b/pear/scripts/pear.in index bba3c62adc..89b3714b68 100644 --- a/pear/scripts/pear.in +++ b/pear/scripts/pear.in @@ -1,5 +1,5 @@ #!@prefix@/bin/php -Cq -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 \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: + */ ?>