From 6dce2376da2e6f7229f823b12f050a4e16d471a5 Mon Sep 17 00:00:00 2001 From: Stig Bakken Date: Sun, 19 May 2002 06:48:40 +0000 Subject: [PATCH] * new command setup --- pear/PEAR/Command/Package.php | 579 ++++++++++++++++++---------------- 1 file changed, 311 insertions(+), 268 deletions(-) diff --git a/pear/PEAR/Command/Package.php b/pear/PEAR/Command/Package.php index 344a91ac30..d1cba6a6f7 100644 --- a/pear/PEAR/Command/Package.php +++ b/pear/PEAR/Command/Package.php @@ -24,7 +24,58 @@ require_once 'PEAR/Common.php'; class PEAR_Command_Package extends PEAR_Command_Common { - // {{{ constructor + var $commands = array( + 'package' => array( + 'summary' => 'Build Package', + 'function' => 'doPackage', + 'options' => array( + 'nocompress' => array( + 'shortopt' => 'Z', + 'doc' => 'Do not gzip the package file' + ), + '???' => array( + 'shortopt' => 'n', + 'doc' => 'Return only the created package file name. Useful for +shell script operations. +', + ), + ), + 'doc' => 'Creates a PEAR package from its description file (usually +called package.xml). +' + ), + 'package-info' => array( + 'summary' => 'Display information about a package file', + 'function' => 'doPackageInfo', + 'options' => array(), + 'doc' => 'Extracts information from a package file and displays it. +', + ), + 'package-list' => array( + 'summary' => 'List Files in Package', + 'function' => 'doPackageList', + 'options' => array(), + 'doc' => '', + ), + 'package-validate' => array( + 'summary' => 'Validate Package Consistency', + 'function' => 'doPackageValidate', + 'options' => array(), + 'doc' => '', + ), + 'cvstag' => array( + 'summary' => 'Set CVS Release Tag', + 'function' => 'doCvsTag', + 'options' => array(), + 'doc' => '', + ), + 'run-tests' => array( + 'summary' => 'Run Regression Tests', + 'function' => 'doRunTests', + 'options' => array(), + 'doc' => '', + ), + ); /** * PEAR_Command_Package constructor. @@ -36,10 +87,6 @@ class PEAR_Command_Package extends PEAR_Command_Common parent::PEAR_Command_Common($ui, $config); } - // }}} - - // {{{ _displayValidationResults() - function _displayValidationResults($err, $warn, $strict = false) { foreach ($err as $e) { @@ -57,9 +104,6 @@ class PEAR_Command_Package extends PEAR_Command_Common return true; } - // }}} - // {{{ getCommands() - /** * Return a list of all the commands defined by this class. * @return array list of commands @@ -75,7 +119,6 @@ class PEAR_Command_Package extends PEAR_Command_Common 'run-tests' => 'Run Regression Tests'); } - // }}} // {{{ getOptions() function getOptions() @@ -132,295 +175,295 @@ class PEAR_Command_Package extends PEAR_Command_Common { $failmsg = ''; switch ($command) { - // {{{ package - - case 'package': { - $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)) { - break; - } - $compress = empty($options['Z']) ? true : false; - $result = $packager->Package($pkginfofile, $compress); - $output = ob_get_contents(); - ob_end_clean(); - if (PEAR::isError($result)) { - $failmsg = $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()); - } + case 'package': + case 'package-list': + case 'package-info': + case 'package-validate': break; + // {{{ cvstag + + case 'cvstag': { } // }}} - // {{{ package-list - - case 'package-list': { - // $params[0] -> the PEAR package to list its files - if (sizeof($params) != 1) { - $failmsg = "Command package-list requires a valid PEAR package filename ". - " as the first argument. Try the command \"help package-list\""; - break; - } - $obj = new PEAR_Common(); + // {{{ run-tests - if (PEAR::isError($info = $obj->infoFromTgzFile($params[0]))) { - return $info; - } - $list =$info['filelist']; - $caption = 'Contents of ' . basename($params[0]); - $this->ui->startTable(array('caption' => $caption, - 'border' => true)); - $this->ui->tableRow(array('Package Files', 'Install Destination'), - array('bold' => true)); - foreach ($list as $file => $att) { - if (isset($att['baseinstalldir'])) { - $dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR . - $file; - } else { - $dest = $file; - } - switch ($att['role']) { - case 'test': - $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); - $opts = array(0 => array('wrap' => 23), - 1 => array('wrap' => 45) - ); - $this->ui->tableRow(array($file, $dest), null, $opts); - } - $this->ui->endTable(); + case 'run-tests': { break; } // }}} - // {{{ package-info + default: { + return false; + } + } + if ($failmsg) { + return $this->raiseError($failmsg); + } + return true; + } + + // }}} + + + function doPackage($command, $options, $params) + { + $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 doPackageList($command, $options, $params) + { + // $params[0] -> the PEAR package to list its files + if (sizeof($params) != 1) { + return $this->raiseError("bad parameters, try \"help $command\""); + } + $obj = new PEAR_Common(); - case 'package-info': { - // $params[0] -> the PEAR package to list its information - if (sizeof($params) != 1) { - $failmsg = "Command package-info requires a valid PEAR package filename ". - " as the first argument. Try the command \"help package-info\""; + if (PEAR::isError($info = $obj->infoFromTgzFile($params[0]))) { + return $info; + } + $list =$info['filelist']; + $caption = 'Contents of ' . basename($params[0]); + $this->ui->startTable(array('caption' => $caption, + 'border' => true)); + $this->ui->tableRow(array('Package Files', 'Install Destination'), + array('bold' => true)); + foreach ($list as $file => $att) { + if (isset($att['baseinstalldir'])) { + $dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR . + $file; + } else { + $dest = $file; + } + switch ($att['role']) { + case 'test': + $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); + $opts = array(0 => array('wrap' => 23), + 1 => array('wrap' => 45) + ); + $this->ui->tableRow(array($file, $dest), null, $opts); + } + $this->ui->endTable(); + return true; + } - $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; + 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'; } - case 'release_deps': { - static $rel_trans = array( - 'lt' => '<', - 'le' => '<=', - 'eq' => '=', - 'ne' => '!=', - 'gt' => '>', - 'ge' => '>=', - ); - $i = 0; - $dstr = ''; - foreach ($info[$key] as $d) { - if ($i++ > 0) { - $dstr .= ", "; - } - if (isset($rel_trans[$d['rel']])) { - $d['rel'] = $rel_trans[$d['rel']]; - } - $dstr .= "$d[type] $d[rel]"; - if (isset($d['version'])) { - $dstr .= " $d[version]"; - } - } - $info[$key] = $dstr; - break; + $mstr .= "> ($m[role])"; + } + $info[$key] = $mstr; + break; + } + case 'release_deps': { + static $rel_trans = array( + 'lt' => '<', + 'le' => '<=', + 'eq' => '=', + 'ne' => '!=', + 'gt' => '>', + 'ge' => '>=', + ); + $i = 0; + $dstr = ''; + foreach ($info[$key] as $d) { + if ($i++ > 0) { + $dstr .= ", "; } - default: { - $info[$key] = implode(", ", $info[$key]); - break; + if (isset($rel_trans[$d['rel']])) { + $d['rel'] = $rel_trans[$d['rel']]; + } + $dstr .= "$d[type] $d[rel]"; + if (isset($d['version'])) { + $dstr .= " $d[version]"; } } + $info[$key] = $dstr; + break; } - $info[$key] = trim($info[$key]); - if (in_array($key, $longtext)) { - $info[$key] = preg_replace('/ +/', ' ', $info[$key]); + default: { + $info[$key] = implode(", ", $info[$key]); + break; } } - $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(); - break; } - - // }}} - // {{{ package-validate - - case 'package-validate': { - if (sizeof($params) < 1) { - $params[0] = "package.xml"; - } - $obj = new PEAR_Common; - $info = null; - if (file_exists($params[0])) { - $fp = fopen($params[0], "r"); - $test = fread($fp, 5); - fclose($fp); - if ($test == "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); - 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; + } - // }}} - // {{{ cvstag - - case 'cvstag': { - if (sizeof($params) < 1) { - $help = $this->getHelp($command); - return $this->raiseError("$command: missing parameter: $help[0]"); - } - $obj = new PEAR_Common; + function doPackageValidate($command, $options, $params) + { + if (sizeof($params) < 1) { + $params[0] = "package.xml"; + } + $obj = new PEAR_Common; + $info = null; + if (file_exists($params[0])) { + $fp = fopen($params[0], "r"); + $test = fread($fp, 5); + fclose($fp); + if ($test == "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"; - /* until the getopt bug is fixed, these won't work: - if (isset($options['q'])) { - $command .= ' -q'; - } - if (isset($options['Q'])) { - $command .= ' -Q'; - } - */ - $command .= ' tag'; - if (isset($options['F'])) { - $command .= ' -F'; - } - /* neither will this one: - if (isset($options['d'])) { - $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); - } - break; - } - - // }}} - // {{{ run-tests - - case 'run-tests': { - $cwd = getcwd(); - $php = PHP_BINDIR . '/php' . (OS_WINDOWS ? '.exe' : ''); - $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'; - } - $plist = implode(" ", $params); - $cmd = "$php -d include_path=$cwd$ps$ip $run_tests $plist"; - system($cmd); - break; - } - - // }}} - default: { - return false; } } - if ($failmsg) { - return $this->raiseError($failmsg); + 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['q'])) { + $command .= ' -q'; + } + if (isset($options['Q'])) { + $command .= ' -Q'; + } + $command .= ' tag'; + if (isset($options['F'])) { + $command .= ' -F'; + } + if (isset($options['d'])) { + $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'; + } + $plist = implode(" ", $params); + $cmd = "$php -d include_path=$cwd$ps$ip $run_tests $plist"; + system($cmd); + return true; + } } ?> \ No newline at end of file -- 2.50.1