cvs: pear /PEAR_Frontend_Web/Command Auth.php Common.php Config.php Install.php Package.php Registry.php Remote.php

From: Date: Mon, 27 May 2002 11:52:37 +0000
Subject: cvs: pear /PEAR_Frontend_Web/Command Auth.php Common.php Config.php Install.php Package.php Registry.php Remote.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-4139@lists.php.net to get a copy of this message
dickmann Mon May 27 07:52:37 2002 EDT Added files: /pear/PEAR_Frontend_Web/Command Auth.php Common.php Config.php Install.php Package.php Registry.php Remote.php Log: added basic files

Index: pear/PEAR_Frontend_Web/Command/Auth.php +++ pear/PEAR_Frontend_Web/Command/Auth.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Stig Bakken <ssb@fast.no> | // +----------------------------------------------------------------------+ // // $Id: Auth.php,v 1.1 2002/05/27 11:52:36 dickmann Exp $ require_once "PEAR/Command/Common.php"; require_once "PEAR/Remote.php"; require_once "PEAR/Config.php"; /** * PEAR commands for managing configuration data. * */ class PEAR_Command_Auth extends PEAR_Command_Common { var $commands = array( 'login' => array( 'summary' => 'Connects and authenticates to remote server', 'shortcut' => 'li', 'function' => 'doLogin', 'options' => array(), 'doc' => ' Log in to the remote server. To use remote functions in the installer that require any kind of privileges, you need to log in first. The username and password you enter here will be stored in your per-user PEAR configuration (~/.pearrc on Unix-like systems). After logging in, your username and password will be sent along in subsequent operations on the remote server.', ), 'logout' => array( 'summary' => 'Logs out from the remote server', 'shortcut' => 'lo', 'function' => 'doLogout', 'options' => array(), 'doc' => ' Logs out from the remote server. This command does not actually connect to the remote server, it only deletes the stored username and password from your user configuration.', ) ); /** * PEAR_Command_Auth constructor. * * @access public */ function PEAR_Command_Auth(&$ui, &$config) { parent::PEAR_Command_Common($ui, $config); } /** * Execute the 'login' command. * * @param string $command command name * * @param array $options option_name => value * * @param array $params list of additional parameters * * @return bool TRUE on success, FALSE for unknown commands, or * a PEAR error on failure * * @access public */ function doLogin($command, $options, $params) { $server = $this->config->get('master_server'); $remote = new PEAR_Remote($this->config); $username = $this->config->get('username'); if (empty($username)) { $username = @$_ENV['USER']; } $this->ui->displayLine("Logging in to $server."); list($username, $password) = $this->ui->userDialog( $command, array('Username', 'Password'), array('text', 'password'), array($username, '') ); $username = trim($username); $password = trim($password); $this->config->set('username', $username); $this->config->set('password', $password); $remote->expectError(401); $ok = $remote->call('logintest'); $remote->popExpect(); if ($ok === true) { $this->ui->displayLine("Logged in."); $this->config->store(); } else { $this->ui->displayLine("Login failed!"); } } /** * Execute the 'logout' command. * * @param string $command command name * * @param array $options option_name => value * * @param array $params list of additional parameters * * @return bool TRUE on success, FALSE for unknown commands, or * a PEAR error on failure * * @access public */ function doLogout($command, $options, $params) { $server = $this->config->get('master_server'); $this->ui->displayLine("Logging out from $server."); $this->config->remove('username'); $this->config->remove('password'); $this->config->store(); } } ?> Index: pear/PEAR_Frontend_Web/Command/Common.php +++ pear/PEAR_Frontend_Web/Command/Common.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Stig Sæther Bakken <ssb@fast.no> | // +----------------------------------------------------------------------+ // // $Id: Common.php,v 1.1 2002/05/27 11:52:36 dickmann Exp $ require_once "PEAR.php"; class PEAR_Command_Common extends PEAR { // {{{ properties /** * PEAR_Config object used to pass user system and configuration * on when executing commands * * @var object */ var $config; /** * User Interface object, for all interaction with the user. * @var object */ var $ui; // }}} // {{{ constructor /** * PEAR_Command_Common constructor. * * @access public */ function PEAR_Command_Common(&$ui, &$config) { parent::PEAR(); $this->config = &$config; $this->ui = &$ui; } // }}} // {{{ getCommands() /** * Return a list of all the commands defined by this class. * @return array list of commands * @access public */ function getCommands() { $ret = array(); foreach (array_keys($this->commands) as $command) { $ret[$command] = $this->commands[$command]['summary']; } return $ret; } // }}} // {{{ getShortcuts() /** * Return a list of all the command shortcuts defined by this class. * @return array shortcut => command * @access public */ function getShortcuts() { $ret = array(); foreach (array_keys($this->commands) as $command) { if (isset($this->commands[$command]['shortcut'])) { $ret[$this->commands[$command]['shortcut']] = $command; } } return $ret; } // }}} // {{{ getOptions() function getOptions($command) { return @$this->commands[$command]['options']; } // }}} // {{{ getGetoptArgs() function getGetoptArgs($command, &$short_args, &$long_args) { $short_args = ""; $long_args = array(); if (empty($this->commands[$command])) { return; } reset($this->commands[$command]); while (list($option, $info) = each($this->commands[$command]['options'])) { $larg = $sarg = ''; if (isset($info['arg'])) { if ($info['arg']{0} == '(') { $larg = '=='; $sarg = '::'; $arg = substr($info['arg'], 1, -1); } else { $larg = '='; $sarg = ':'; $arg = $info['arg']; } } if (isset($info['shortopt'])) { $short_args .= $info['shortopt'] . $sarg; } $long_args[] = $option . $larg; } } // }}} // {{{ getHelp() /** * Returns the help message for the given command * * @param string $command The command * @return mixed A fail string if the command does not have help or * a two elements array containing [0]=>help string, * [1]=> help string for the accepted cmd args */ function getHelp($command) { $config = &PEAR_Config::singleton(); $help = @$this->commands[$command]['doc']; if (empty($help)) { // XXX (cox) Fallback to summary if there is no doc (show both?) if (!$help = @$this->commands[$command]['summary']) { return "No help for command \"$command\""; } } if (preg_match_all('/{config\s+([^\}]+)}/e', $help, $matches)) { foreach($matches[0] as $k => $v) { $help = preg_replace("/$v/", $config->get($matches[1][$k]), $help); } } return array($help, $this->getHelpArgs($command)); } // }}} // {{{ getHelpArgs() /** * Returns the help for the accepted arguments of a command * * @param string $command * @return string The help string */ function getHelpArgs($command) { if (isset($this->commands[$command]['options']) && count($this->commands[$command]['options'])) { $help = "Options:\n"; foreach ($this->commands[$command]['options'] as $k => $v) { if (isset($v['shortopt'])) { $s = $v['shortopt']; if (@$s{1} == ':') { $argname = ''; $optional = false; if (@$s{2} == ':') { $optional = true; $argname = substr($s, 3); } else { $argname = substr($s, 2); } if (empty($argname)) { $argname = 'arg'; } if ($optional) { $help .= " -$s [$argname], --{$k}[=$argname]\n"; } else { $help .= " -$s $argname, --$k=$argname\n"; } } else { $help .= " -$s, --$k\n"; } } else { $help .= " --$k\n"; } $help .= " $v[doc]\n"; } return $help; } return null; } // }}} // {{{ run() function run($command, $options, $params) { $func = @$this->commands[$command]['function']; if (empty($func)) { // look for shortcuts foreach (array_keys($this->commands) as $cmd) { if (@$this->commands[$cmd]['shortcut'] == $command) { $command = $cmd; $func = @$this->commands[$command]['function']; if (empty($func)) { return $this->raiseError("unknown command `$command'"); } break; } } } return $this->$func($command, $options, $params); } // }}} } ?> Index: pear/PEAR_Frontend_Web/Command/Config.php +++ pear/PEAR_Frontend_Web/Command/Config.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Stig Bakken <ssb@fast.no> | // | Tomas V.V.Cox <cox@idecnet.com> | // | | // +----------------------------------------------------------------------+ // // $Id: Config.php,v 1.1 2002/05/27 11:52:36 dickmann Exp $ require_once "PEAR/Command/Common.php"; require_once "PEAR/Config.php"; /** * PEAR commands for managing configuration data. * */ class PEAR_Command_Config extends PEAR_Command_Common { var $commands = array( 'config-show' => array( 'summary' => 'Show All Settings', 'function' => 'doConfigShow', 'shortcut' => 'csh', 'options' => array(), 'doc' => ' Displays all configuration values. An optional argument may be used to tell which configuration layer to display. Valid configuration layers are "user", "system" and "default". ', ), 'config-get' => array( 'summary' => 'Show One Setting', 'function' => 'doConfigGet', 'shortcut' => 'cg', 'options' => array(), 'doc' => 'Displays the value of one configuration parameter. The first argument is the name of the parameter, an optional second argument may be used to tell which configuration layer to look in. Valid configuration layers are "user", "system" and "default". If no layer is specified, a value will be picked from the first layer that defines the parameter, in the order just specified. ', ), 'config-set' => array( 'summary' => 'Change Setting', 'function' => 'doConfigSet', 'shortcut' => 'cs', 'options' => array(), 'doc' => 'Sets the value of one configuration parameter. The first argument is the name of the parameter, the second argument is the new value. Some parameters are be subject to validation, and the command will fail with an error message if the new value does not make sense. An optional third argument may be used to specify which layer to set the configuration parameter in. The default layer is "user". ', ), ); /** * PEAR_Command_Config constructor. * * @access public */ function PEAR_Command_Config(&$ui, &$config) { parent::PEAR_Command_Common($ui, $config); } function doConfigShow($command, $options, $params) { // $params[0] -> the layer if ($error = $this->_checkLayer(@$params[0])) { $failmsg .= $error; break; } $keys = $this->config->getKeys(); sort($keys); $this->ui->startTable(array('caption' => 'Configuration:')); foreach ($keys as $key) { $type = $this->config->getType($key); $value = $this->config->get($key, @$params[0]); if ($type == 'password' && $value) { $value = '********'; } elseif ($key == 'umask') { $value = sprintf("%03o", $value); } if ($value === null || $value === '') { $value = '<not set>'; } elseif ($value === false) { $value = 'false'; } elseif ($value === true) { $value = 'true'; } $this->ui->tableRow(array($key, $value)); } $this->ui->endTable(); return true; } function doConfigGet($command, $options, $params) { // $params[0] -> the parameter // $params[1] -> the layer if ($error = $this->_checkLayer(@$params[1])) { $failmsg .= $error; break; } if (sizeof($params) < 1 || sizeof($params) > 2) { $failmsg .= "config-get expects 1 or 2 parameters"; } elseif (sizeof($params) == 1) { $this->ui->displayLine("$params[0] = " . $this->config->get($params[0])); } else { $this->ui->displayLine("($params[1])$params[0] = " . $this->config->get($params[0], $params[1])); } return true; } function doConfigSet($command, $options, $params) { // $param[0] -> a parameter to set // $param[1] -> the value for the parameter // $param[2] -> the layer $failmsg = ''; if (sizeof($params) < 2 || sizeof($params) > 3) { $failmsg .= "config-set expects 2 or 3 parameters"; break; } if ($error = $this->_checkLayer(@$params[2])) { $failmsg .= $error; break; } if (!call_user_func_array(array(&$this->config, 'set'), $params)) { $failmsg = "config-set (" . implode(", ", $params) . ") failed"; } else { $this->config->store(); } if ($failmsg) { return $this->raiseError($failmsg); } return true; } /** * Checks if a layer is defined or not * * @param string $layer The layer to search for * @return mixed False on no error or the error message */ function _checkLayer($layer = null) { if (!empty($layer)) { $layers = $this->config->getLayers(); if (!in_array($layer, $layers)) { return " only the layers: \"" . implode('" or "', $layers) . "\" are supported"; } } return false; } } ?> Index: pear/PEAR_Frontend_Web/Command/Install.php +++ pear/PEAR_Frontend_Web/Command/Install.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Stig Sæther Bakken <ssb@fast.no> | // +----------------------------------------------------------------------+ // // $Id: Install.php,v 1.1 2002/05/27 11:52:36 dickmann Exp $ require_once "PEAR/Command/Common.php"; require_once "PEAR/Installer.php"; require_once "Console/Getopt.php"; /** * PEAR commands for installation or deinstallation/upgrading of * packages. * */ class PEAR_Command_Install extends PEAR_Command_Common { // {{{ command definitions var $commands = array( 'install' => array( 'summary' => 'Install Package', 'function' => 'doInstall', 'shortcut' => 'i', 'options' => array( 'force' => array( 'shortopt' => 'f', 'doc' => 'will overwrite newer installed packages', ), 'nodeps' => array( 'shortopt' => 'n', 'doc' => 'ignore dependencies, install anyway', ), 'register-only' => array( 'shortopt' => 'r', 'doc' => 'do not install files, only register the package as installed', ), 'soft' => array( 'shortopt' => 's', 'doc' => 'soft install, fail silently, or upgrade if already installed', ), 'nocompress' => array( 'shortopt' => 'Z', 'doc' => 'request uncompressed files when downloading', ), ), 'doc' => '<package> ... Installs one or more PEAR packages. You can specify a package to install in four ways: "Package-1.0.tgz" : installs from a local file "http://example.com/Package-1.0.tgz" : installs from anywhere on the net. "package.xml" : installs the package described in package.xml. Useful for testing, or for wrapping a PEAR package in another package manager such as RPM. "Package" : queries your configured server ({config master_server}) and downloads the newest package with the preferred quality/state ({config preferred_state}). More than one package may be specified at once. It is ok to mix these four ways of specifying packages. '), 'upgrade' => array( 'summary' => 'Upgrade Package', 'function' => 'doInstall', 'shortcut' => 'up', 'options' => array( 'force' => array( 'shortopt' => 'f', 'doc' => 'overwrite newer installed packages', ), 'nodeps' => array( 'shortopt' => 'n', 'doc' => 'ignore dependencies, upgrade anyway', ), 'register-only' => array( 'shortopt' => 'r', 'doc' => 'do not install files, only register the package as upgraded', ), 'nocompress' => array( 'shortopt' => 'Z', 'doc' => 'request uncompressed files when downloading', ), ), 'doc' => '<package> ... Upgrades one or more PEAR packages. See documentation for the "install" command for ways to specify a package. When upgrading, your package will be updated if the provided new package has a higher version number (use the -f option if you need to upgrade anyway). More than one package may be specified at once. '), 'uninstall' => array( 'summary' => 'Un-install Package', 'function' => 'doUninstall', 'shortcut' => 'un', 'options' => array( 'nodeps' => array( 'shortopt' => 'n', 'doc' => 'ignore dependencies, uninstall anyway', ), 'register-only' => array( 'shortopt' => 'r', 'doc' => 'do not remove files, only register the packages as not installed', ), ), 'doc' => '<package> ... Uninstalls one or more PEAR packages. More than one package may be specified at once. '), ); // }}} // {{{ constructor /** * PEAR_Command_Install constructor. * * @access public */ function PEAR_Command_Install(&$ui, &$config) { parent::PEAR_Command_Common($ui, $config); } // }}} function doInstall($command, $options, $params) { if (empty($this->installer)) { $this->installer = &new PEAR_Installer($ui); } if ($command == 'upgrade') { $options[$command] = true; } foreach ($params as $pkg) { $bn = basename($pkg); $info = $this->installer->install($pkg, $options, $this->config); if (is_array($info)) { if ($this->config->get('verbose') > 0) { $label = "$info[package] $info[version]"; $this->ui->displayLine("$command ok: $label"); } } else { return $this->raiseError("$command failed"); } } } function doUninstall($command, $options, $params) { if (empty($this->installer)) { $this->installer = &new PEAR_Installer($ui); } foreach ($params as $pkg) { if ($this->installer->uninstall($pkg, $options)) { if ($this->config->get('verbose') > 0) { $this->ui->displayLine("uninstall ok"); } } else { return $this->raiseError("uninstall failed"); } } return true; } } ?> Index: pear/PEAR_Frontend_Web/Command/Package.php +++ pear/PEAR_Frontend_Web/Command/Package.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Stig Bakken <ssb@fast.no> | // | Martin Jansen <mj@php.net> | // +----------------------------------------------------------------------+ // // $Id: Package.php,v 1.1 2002/05/27 11:52:36 dickmann Exp $ require_once 'PEAR/Common.php'; require_once 'PEAR/Command/Common.php'; class PEAR_Command_Package extends PEAR_Command_Common { var $_deps_rel_trans = array( 'lt' => '<', 'le' => '<=', 'eq' => '=', 'ne' => '!=', 'gt' => '>', 'ge' => '>=', ); var $_deps_type_trans = array( 'pkg' => 'package', 'extension' => 'extension', 'php' => 'PHP', 'prog' => 'external program', 'ldlib' => 'external library for linking', 'rtlib' => 'external runtime library', 'os' => 'operating system', 'websrv' => 'web server', 'sapi' => 'SAPI backend' ); var $commands = array( 'package' => array( 'summary' => 'Build Package', 'function' => 'doPackage', 'shortcut' => 'p', 'options' => array( 'nocompress' => array( 'shortopt' => 'Z', 'doc' => 'Do not gzip the package file' ), 'showname' => array( 'shortopt' => 'n', 'doc' => 'Print the name of the packaged file.', ), ), 'doc' => '[descfile] Creates a PEAR package from its description file (usually called package.xml). ' ), 'package-info' => array( 'summary' => 'Display information about a package file', 'function' => 'doPackageInfo', 'shortcut' => 'pi', 'options' => array(), 'doc' => ' Extracts information from a package file and displays it. ', ), 'package-validate' => array( 'summary' => 'Validate Package Consistency', 'function' => 'doPackageValidate', 'shortcut' => 'pv', 'options' => array(), 'doc' => ' ', ), 'cvstag' => array( 'summary' => 'Set CVS Release Tag', 'function' => 'doCvsTag', 'shortcut' => 'ct', 'options' => array( 'quiet' => array( 'shortopt' => 'q', 'doc' => 'Be quiet', ), 'reallyquiet' => array( 'shortopt' => 'Q', 'doc' => 'Be really quiet', ), 'slide' => array( 'shortopt' => 'F', 'doc' => 'Move (slide) tag if it exists', ), 'delete' => array( 'shortopt' => 'd', 'doc' => 'Remove tag', ), ), 'doc' => ' Sets a CVS tag on all files in a package. Use this command after you have packaged a distribution tarball with the "package" command to tag what revisions of what files were in that release. If need to fix something after running cvstag once, but before the tarball is released to the public, use the "slide" option to move the release tag. ', ), 'run-tests' => array( 'summary' => 'Run Regression Tests', 'function' => 'doRunTests', 'shortcut' => 'rt', 'options' => array(), 'doc' => '[testfile|dir ...] Run regression tests with PHP\'s regression testing script (run-tests.php).', ), 'package-dependencies' => array( 'summary' => 'Show package dependencies', 'function' => 'doPackageDependencies', 'shortcut' => 'pd', 'options' => array(), 'doc' => ' List all depencies the package has.' ), ); /** * PEAR_Command_Package constructor. * * @access public */ function PEAR_Command_Package(&$ui, &$config) { parent::PEAR_Command_Common($ui, $config); } function _displayValidationResults($err, $warn, $strict = false) { foreach ($err as $e) { $this->ui->displayLine("Error: $e"); } foreach ($warn as $w) { $this->ui->displayLine("Warning: $w"); } $this->ui->displayLine(sprintf('Validation: %d error(s), %d warning(s)', sizeof($err), sizeof($warn))); if ($strict && sizeof($err) > 0) { $this->ui->displayLine("Fix these errors and try again."); return false; } return true; } function doPackage($command, $options, $params) { include_once 'PEAR/Packager.php'; $pkginfofile = isset($params[0]) ? $params[0] : 'package.xml'; ob_start(); $packager =& new PEAR_Packager($this->config->get('php_dir'), $this->config->get('ext_dir'), $this->config->get('doc_dir')); $packager->debug = $this->config->get('verbose'); $err = $warn = array(); $packager->validatePackageInfo($pkginfofile, $err, $warn); if (!$this->_displayValidationResults($err, $warn, true)) { return; } $compress = empty($options['Z']) ? true : false; $result = $packager->Package($pkginfofile, $compress); $output = ob_get_contents(); ob_end_clean(); if (PEAR::isError($result)) { return $this->raiseError($result); } // Don't want output, only the package file name just created if (isset($options['n'])) { $this->ui->displayLine($result); return; } $lines = explode("\n", $output); foreach ($lines as $line) { $this->ui->displayLine($line); } if (PEAR::isError($result)) { $this->ui->displayLine("Package failed: ".$result->getMessage()); } return true; } function doPackageInfo($command, $options, $params) { // $params[0] -> the PEAR package to list its information if (sizeof($params) != 1) { return $this->raiseError("bad parameter(s), try \"help $command\""); } $obj = new PEAR_Common(); if (PEAR::isError($info = $obj->infoFromTgzFile($params[0]))) { return $info; } unset($info['filelist']); unset($info['changelog']); $keys = array_keys($info); $longtext = array('description', 'summary'); foreach ($keys as $key) { if (is_array($info[$key])) { switch ($key) { case 'maintainers': { $i = 0; $mstr = ''; foreach ($info[$key] as $m) { if ($i++ > 0) { $mstr .= "\n"; } $mstr .= $m['name'] . " <"; if (isset($m['email'])) { $mstr .= $m['email']; } else { $mstr .= $m['handle'] . '@php.net'; } $mstr .= "> ($m[role])"; } $info[$key] = $mstr; break; } case 'release_deps': { $i = 0; $dstr = ''; foreach ($info[$key] as $d) { if ($i++ > 0) { $dstr .= ", "; } if (isset($this->_deps_rel_trans[$d['rel']])) { $d['rel'] = $this->_deps_rel_trans[$d['rel']]; } $dstr .= "$d[type] $d[rel]"; if (isset($d['version'])) { $dstr .= " $d[version]"; } } $info[$key] = $dstr; break; } default: { $info[$key] = implode(", ", $info[$key]); break; } } } $info[$key] = trim($info[$key]); if (in_array($key, $longtext)) { $info[$key] = preg_replace('/ +/', ' ', $info[$key]); } } $caption = 'About ' . basename($params[0]); $this->ui->startTable(array('caption' => $caption, 'border' => true)); foreach ($info as $key => $value) { $key = ucwords(str_replace('_', ' ', $key)); $this->ui->tableRow(array($key, $value), null, array(1 => array('wrap' => 55))); } $this->ui->endTable(); return true; } function doPackageValidate($command, $options, $params) { if (sizeof($params) < 1) { $params[0] = "package.xml"; } $obj = new PEAR_Common; $info = null; if ($fp = @fopen($params[0], "r")) { $test = fread($fp, 5); fclose($fp); if ($test == "<?xml") { $info = $obj->infoFromDescriptionFile($params[0]); } } if (empty($info)) { $info = $obj->infoFromTgzFile($params[0]); } if (PEAR::isError($info)) { return $this->raiseError($info); } $obj->validatePackageInfo($info, $err, $warn); $this->_displayValidationResults($err, $warn); return true; } function doCvsTag($command, $options, $params) { if (sizeof($params) < 1) { $help = $this->getHelp($command); return $this->raiseError("$command: missing parameter: $help[0]"); } $obj = new PEAR_Common; $info = $obj->infoFromDescriptionFile($params[0]); if (PEAR::isError($info)) { return $this->raiseError($info); } $err = $warn = array(); $obj->validatePackageInfo($info, $err, $warn); if (!$this->_displayValidationResults($err, $warn, true)) { break; } $version = $info['version']; $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $version); $cvstag = "RELEASE_$cvsversion"; $files = array_keys($info['filelist']); $command = "cvs"; if (isset($options['quiet'])) { $command .= ' -q'; } if (isset($options['reallyquiet'])) { $command .= ' -Q'; } $command .= ' tag'; if (isset($options['slide'])) { $command .= ' -F'; } if (isset($options['delete'])) { $command .= ' -d'; } $command .= ' ' . $cvstag . ' ' . escapeshellarg($params[0]); foreach ($files as $file) { $command .= ' ' . escapeshellarg($file); } $this->ui->displayLine("+ $command"); if (empty($options['n'])) { $fp = popen($command, "r"); while ($line = fgets($fp, 1024)) { $this->ui->displayLine(rtrim($line)); } pclose($fp); } return true; } function doRunTests($command, $options, $params) { $cwd = getcwd(); $php = PHP_BINDIR . '/php' . (OS_WINDOWS ? '.exe' : ''); putenv("TEST_PHP_EXECUTABLE=$php"); $ip = ini_get("include_path"); $ps = OS_WINDOWS ? ';' : ':'; $run_tests = $this->config->get('php_dir') . DIRECTORY_SEPARATOR . 'run-tests.php'; if (!file_exists($run_tests)) { $run_tests = PEAR_INSTALL_DIR . DIRECTORY_SEPARATOR . 'run-tests.php'; if (!file_exists($run_tests)) { return $this->raiseError("No `run-test.php' file found"); } } $plist = implode(" ", $params); $cmd = "$php -C -d include_path=$cwd$ps$ip -f $run_tests -- $plist"; system($cmd); return true; } function doPackageDependencies($command, $options, $params) { // $params[0] -> the PEAR package to list its information if (sizeof($params) != 1) { return $this->raiseError("bad parameter(s), try \"help $command\""); } $obj = new PEAR_Common(); if (PEAR::isError($info = $obj->infoFromAny($params[0]))) { return $info; } if (is_array($info['release_deps'])) { $this->ui->startTable(array('caption' => 'Dependencies for ' . $info['package'], 'border' => true)); $this->ui->tableRow(array("Type", "Name", "Relation", "Version")); foreach ($info['release_deps'] as $d) { if (isset($this->_deps_rel_trans[$d['rel']])) { $rel = $this->_deps_rel_trans[$d['rel']]; } else { $rel = $d['rel']; } if (isset($this->_deps_type_trans[$d['type']])) { $type = ucfirst($this->_deps_type_trans[$d['type']]); } else { $type = $d['type']; } if (isset($d['name'])) { $name = $d['name']; } else { $name = ''; } if (isset($d['version'])) { $version = $d['version']; } else { $version = ''; } $this->ui->tableRow(array($type, $name, $rel, $version), null, array(1 => array('wrap' => 55))); } $this->ui->endTable(); return true; } // Fallback $this->ui->displayLine("This package does not have any dependencies."); } } ?> Index: pear/PEAR_Frontend_Web/Command/Registry.php +++ pear/PEAR_Frontend_Web/Command/Registry.php <?php // /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Stig Bakken <ssb@fast.no> | // | | // +----------------------------------------------------------------------+ // // $Id: Registry.php,v 1.1 2002/05/27 11:52:36 dickmann Exp $ require_once 'PEAR/Command/Common.php'; require_once 'PEAR/Registry.php'; require_once 'PEAR/Config.php'; class PEAR_Command_Registry extends PEAR_Command_Common { var $commands = array( 'list' => array( 'summary' => 'List Installed Packages', 'function' => 'doList', 'shortcut' => 'l', 'options' => array(), 'doc' => '[package] If invoked without parameters, this command lists the PEAR packages installed in your php_dir ({config php_dir)). With a parameter, it lists the files in that package. ', ), 'shell-test' => array( 'summary' => 'Shell Script Test', 'function' => 'doShellTest', 'shortcut' => 'st', 'options' => array(), 'doc' => '<package> [[relation] version] Tests if a package is installed in the system. Will exit(1) if it is not. <relation> The version comparison operator. One of: <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne <version> The version to compare with '), ); /** * PEAR_Command_Registry constructor. * * @access public */ function PEAR_Command_Registry(&$ui, &$config) { parent::PEAR_Command_Common($ui, $config); } function doList($command, $options, $params) { $reg = new PEAR_Registry($this->config->get('php_dir')); if (sizeof($params) == 0) { $installed = $reg->packageInfo(); $i = $j = 0; $this->ui->startTable( array('caption' => 'Installed packages:', 'border' => true)); foreach ($installed as $package) { if ($i++ % 20 == 0) { $this->ui->tableRow( array('Package', 'Version', 'State'), array('bold' => true)); } echo $package['package']."\n"; $this->ui->tableRow(array($package['package'], $package['version'], @$package['release_state'])); } if ($i == 0) { $this->ui->tableRow(array('(no packages installed)')); } $this->ui->endTable(); } else { if (file_exists($params[0]) && !is_dir($params[0])) { include_once "PEAR/Common.php"; $obj = &new PEAR_Common; $info = $obj->infoFromAny($params[0]); $headings = array('Package File', 'Install Path'); $installed = false; } else { $info = $reg->packageInfo($params[0]); $headings = array('Type', 'Install Path'); $installed = true; } if (PEAR::isError($info)) { return $this->raiseError($info); } if ($info === null) { return $this->raiseError("`$params[0]' not installed"); } $list = $info['filelist']; if ($installed) { $caption = 'Installed Files For ' . $params[0]; } else { $caption = 'Contents of ' . basename($params[0]); } $this->ui->startTable(array('caption' => $caption, 'border' => true)); $this->ui->tableRow($headings, array('bold' => true)); foreach ($list as $file => $att) { if ($installed) { if (empty($att['installed_as'])) { continue; } $this->ui->tableRow(array($att['role'], $att['installed_as'])); } else { if (isset($att['baseinstalldir'])) { $dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR . $file; } else { $dest = $file; } switch ($att['role']) { case 'test': case 'data': if ($installed) { break 2; } $dest = '-- will not be installed --'; break; case 'doc': $dest = $this->config->get('doc_dir') . DIRECTORY_SEPARATOR . $dest; break; case 'php': default: $dest = $this->config->get('php_dir') . DIRECTORY_SEPARATOR . $dest; } $dest = preg_replace('!/+!', '/', $dest); $file = preg_replace('!/+!', '/', $file); $this->ui->tableRow(array($file, $dest)); } } $this->ui->endTable(); } return true; } function doShellTest($command, $options, $params) { $this->pushErrorHandling(PEAR_ERROR_RETURN); $reg = &new PEAR_Registry($this->config->get('php_dir')); // "pear shell-test Foo" if (sizeof($params) == 1) { if (!$reg->packageExists($params[0])) { exit(1); } // "pear shell-test Foo 1.0" } elseif (sizeof($params) == 2) { $v = $reg->packageInfo($params[0], 'version'); if (!$v || !version_compare($v, $params[1], "ge")) { exit(1); } // "pear shell-test Foo ge 1.0" } elseif (sizeof($params) == 3) { $v = $reg->packageInfo($params[0], 'version'); if (!$v || !version_compare($v, $params[2], $params[1])) { exit(1); } } else { $this->popErrorHandling(); $this->raiseError("$command: expects 1 to 3 parameters"); exit(1); } } } ?> Index: pear/PEAR_Frontend_Web/Command/Remote.php +++ pear/PEAR_Frontend_Web/Command/Remote.php <?php // /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Stig Bakken <ssb@fast.no> | // | | // +----------------------------------------------------------------------+ // // $Id: Remote.php,v 1.1 2002/05/27 11:52:36 dickmann Exp $ require_once 'PEAR/Command/Common.php'; require_once 'PEAR/Common.php'; require_once 'PEAR/Remote.php'; require_once 'PEAR/Registry.php'; class PEAR_Command_Remote extends PEAR_Command_Common { // {{{ command definitions var $commands = array( 'remote-info' => array( 'summary' => 'Information About Remote Packages', 'function' => 'doRemoteInfo', 'shortcut' => 'ri', 'options' => array(), 'doc' => '<package> Get details on a package from the server.', ), 'list-upgrades' => array( 'summary' => 'List Available Upgrades', 'function' => 'doListUpgrades', 'shortcut' => 'lu', 'options' => array(), 'doc' => ' List releases on the server of packages you have installed where a newer version is available with the same release state (stable etc.).' ), 'remote-list' => array( 'summary' => 'List Remote Packages', 'function' => 'doRemoteList', 'shortcut' => 'rl', 'options' => array(), 'doc' => ' Lists the packages available on the configured server along with the latest stable release of each package.', ), 'list-all' => array( 'summary' => 'List All Packages', 'function' => 'doListAll', 'shortcut' => 'la', 'options' => array(), 'doc' => ' Lists the packages available on the configured server along with the latest stable release of each package.', ), 'download' => array( 'summary' => 'Download Package', 'function' => 'doDownload', 'shortcut' => 'd', 'options' => array( 'nocompress' => array( 'shortopt' => 'Z', 'doc' => 'download an uncompressed (.tar) file', ), ), 'doc' => '{package|package-version} Download a package tarball. The file will be named as suggested by the server, for example if you download the DB package and the latest stable version of DB is 1.2, the downloaded file will be DB-1.2.tgz.', ), ); // }}} // {{{ constructor /** * PEAR_Command_Remote constructor. * * @access public */ function PEAR_Command_Remote(&$ui, &$config) { parent::PEAR_Command_Common($ui, $config); } // }}} // {{{ info-remote function doInfoRemote($command, $options, $params) { return false; // coming soon } // }}} // {{{ list-remote function doRemoteList($command, $options, $params) { $r = new PEAR_Remote($this->config); $available = $r->call('package.listAll', true); if (PEAR::isError($available)) { return $this->raiseError($available); } $i = $j = 0; $this->ui->startTable( array('caption' => 'Available packages:', 'border' => true)); // print_r($available); foreach ($available as $name => $info) { if ($i++ % 20 == 0) { $this->ui->tableRow( array('Package', 'Version'), array('bold' => true)); } $this->ui->tableRow(array($name, $info['stable'])); } if ($i == 0) { $this->ui->tableRow(array('(no packages installed yet)')); } $this->ui->endTable(); return true; } // }}} // {{{ list-all function doListAll($command, $options, $params) { $r = new PEAR_Remote($this->config); $reg = new PEAR_Registry($this->config->get('php_dir')); $available = $r->call('package.listAll', true); if (PEAR::isError($available)) { return $this->raiseError($available); } $i = $j = 0; $data = array( 'caption' => 'All packages:', 'border' => true, ); foreach ($available as $name => $info) { $installed = $reg->packageInfo($name); $desc = $info['summary']; if (isset($params[$name])) $desc .= "\n\n".$info['description']; $data['data'][$info['category']][] = array( $name, $info['stable'], $info['category'], $desc, $installed['version'], ); } $this->ui->outputData($data, $command); return true; } // }}} // {{{ download function doDownload($command, $options, $params) { //$params[0] -> The package to download if (count($params) != 1) { return PEAR::raiseError("download expects one argument: the package to download"); } $server = $this->config->get('master_server'); if (!ereg('^http://', $params[0])) { $pkgfile = "http://$server/get/$params[0]"; } else { $pkgfile = $params[0]; } $this->bytes_downloaded = 0; $saved = PEAR_Common::downloadHttp($pkgfile, $this->ui, '.', array(&$this, 'downloadCallback')); if (PEAR::isError($saved)) { return $this->raiseError($saved); } $fname = basename($saved); $this->ui->displayLine("File $fname downloaded ($this->bytes_downloaded bytes)"); return true; } function downloadCallback($msg, $params = null) { if ($msg == 'done') { $this->bytes_downloaded = $params; } } // }}} // {{{ list-upgrades function doListUpgrades($command, $options, $params) { include_once "PEAR/Registry.php"; $remote = new PEAR_Remote($this->config); if (empty($params[0])) { $state = $this->config->get('preferred_state'); } else { $state = $params[0]; } $caption = 'Available Upgrades'; if (empty($state) || $state == 'any') { $latest = $remote->call("package.listLatestReleases"); } else { $latest = $remote->call("package.listLatestReleases", $state); $caption .= ' (' . $state . ')'; } $caption .= ':'; if (PEAR::isError($latest)) { return $latest; } $reg = new PEAR_Registry($this->config->get('php_dir')); $inst = array_flip($reg->listPackages()); $this->ui->startTable(array('caption' => $caption, 'border' => 1)); $this->ui->tableRow(array('Package', 'Version', 'Size'), array('bold' => true)); foreach ($latest as $package => $info) { if (!isset($inst[$package])) { // skip packages we don't have installed continue; } extract($info); $inst_version = $reg->packageInfo($package, 'version'); if (version_compare($version, $inst_version, "le")) { // installed version is up-to-date continue; } if ($filesize >= 20480) { $filesize += 1024 - ($filesize % 1024); $fs = sprintf("%dkB", $filesize / 1024); } elseif ($filesize > 0) { $filesize += 103 - ($filesize % 103); $fs = sprintf("%.1fkB", $filesize / 1024.0); } else { $fs = " -"; // XXX center instead } $this->ui->tableRow(array($package, $version, $fs)); } $this->ui->endTable(); return true; } // }}} } ?>
« previous php.pear.cvs (#4139) next »