* started working on "pear list" command

This commit is contained in:
Stig Bakken 2001-10-29 14:15:43 +00:00
parent b60aedc275
commit 7ab89b02c4
3 changed files with 82 additions and 20 deletions

View file

@ -75,15 +75,6 @@ class PEAR_Installer extends PEAR_Common
$this->statedir = "/var/lib/php"; // XXX FIXME Windows $this->statedir = "/var/lib/php"; // XXX FIXME Windows
} }
// }}}
// {{{ destructor
function _PEAR_Installer()
{
chdir($this->pwd);
$this->_PEAR_Common();
}
// }}} // }}}
// {{{ install() // {{{ install()
@ -99,7 +90,7 @@ class PEAR_Installer extends PEAR_Common
{ {
// XXX FIXME Add here code to manage packages database // XXX FIXME Add here code to manage packages database
//$this->loadPackageList("$this->statedir/packages.lst"); //$this->loadPackageList("$this->statedir/packages.lst");
$this->pwd = getcwd(); $oldcwd = getcwd();
$need_download = false; $need_download = false;
if (preg_match('#^(http|ftp)://#', $pkgfile)) { if (preg_match('#^(http|ftp)://#', $pkgfile)) {
$need_download = true; $need_download = true;
@ -144,34 +135,40 @@ class PEAR_Installer extends PEAR_Common
$pkgfile = getcwd() . DIRECTORY_SEPARATOR . basename($pkgfile); $pkgfile = getcwd() . DIRECTORY_SEPARATOR . basename($pkgfile);
if (PEAR::isError($tmpdir = $this->mkTempDir())) { if (PEAR::isError($tmpdir = $this->mkTempDir())) {
chdir($oldcwd);
return $tmpdir; return $tmpdir;
} }
$this->log(2, '+ tmp dir created at ' . $tmpdir); $this->log(2, '+ tmp dir created at ' . $tmpdir);
$tar = new Archive_Tar($pkgfile, true); $tar = new Archive_Tar($pkgfile, true);
if (!$tar->extract($tmpdir)) { if (!$tar->extract($tmpdir)) {
chdir($oldcwd);
return $this->raiseError("Unable to unpack $pkgfile"); return $this->raiseError("Unable to unpack $pkgfile");
} }
$file = basename($pkgfile); $file = basename($pkgfile);
// Assume the decompressed dir name // Assume the decompressed dir name
if (($pos = strrpos($file, '.')) === false) { 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); $pkgdir = substr($file, 0, $pos);
$descfile = $tmpdir . DIRECTORY_SEPARATOR . $pkgdir . DIRECTORY_SEPARATOR . 'package.xml'; $descfile = $tmpdir . DIRECTORY_SEPARATOR . $pkgdir . DIRECTORY_SEPARATOR . 'package.xml';
if (!is_file($descfile)) { if (!is_file($descfile)) {
chdir($oldcwd);
return $this->raiseError("No package.xml file after extracting the archive."); return $this->raiseError("No package.xml file after extracting the archive.");
} }
// Parse xml file ----------------------------------------------- // Parse xml file -----------------------------------------------
$pkginfo = $this->infoFromDescriptionFile($descfile); $pkginfo = $this->infoFromDescriptionFile($descfile);
if (PEAR::isError($pkginfo)) { if (PEAR::isError($pkginfo)) {
chdir($oldcwd);
return $pkginfo; return $pkginfo;
} }
// Copy files to dest dir --------------------------------------- // Copy files to dest dir ---------------------------------------
if (!is_dir($this->phpdir)) { if (!is_dir($this->phpdir)) {
chdir($oldcwd);
return $this->raiseError("No script destination directory found\n", return $this->raiseError("No script destination directory found\n",
null, PEAR_ERROR_DIE); null, PEAR_ERROR_DIE);
} }
@ -187,6 +184,7 @@ class PEAR_Installer extends PEAR_Common
$fname = $tmp_path . DIRECTORY_SEPARATOR . $fname; $fname = $tmp_path . DIRECTORY_SEPARATOR . $fname;
$this->_installFile($fname, $dest_dir, $atts); $this->_installFile($fname, $dest_dir, $atts);
} }
chdir($oldcwd);
return true; return true;
} }
@ -228,6 +226,8 @@ class PEAR_Installer extends PEAR_Common
$this->log(1, "installed file $dest_file"); $this->log(1, "installed file $dest_file");
return true; return true;
} }
// }}} // }}}
} }
?> ?>

View file

@ -156,8 +156,11 @@ class PEAR_Registry
function listPackages() function listPackages()
{ {
$dp = opendir($this->statedir);
$pkglist = array(); $pkglist = array();
$dp = @opendir($this->statedir);
if (!$dp) {
return $pkglist;
}
while ($ent = readdir($dp)) { while ($ent = readdir($dp)) {
if ($ent{0} == "." || substr($ent, -4) != ".inf") { if ($ent{0} == "." || substr($ent, -4) != ".inf") {
continue; continue;

View file

@ -21,6 +21,7 @@
require_once 'PEAR.php'; require_once 'PEAR.php';
require_once 'PEAR/Config.php'; require_once 'PEAR/Config.php';
require_once 'PEAR/Remote.php'; require_once 'PEAR/Remote.php';
require_once 'PEAR/Registry.php';
require_once 'Console/Getopt.php'; require_once 'Console/Getopt.php';
error_reporting(E_ALL ^ E_NOTICE); error_reporting(E_ALL ^ E_NOTICE);
@ -29,7 +30,7 @@ PEAR::setErrorHandling(PEAR_ERROR_PRINT, "pear: %s\n");
// {{{ config file and option parsing // {{{ 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)) { if (PEAR::isError($options)) {
usage($options); usage($options);
} }
@ -58,6 +59,7 @@ foreach ($opts as $opt) {
$config = new PEAR_Config($pear_user_config, $pear_default_config); $config = new PEAR_Config($pear_user_config, $pear_default_config);
$store_user_config = false; $store_user_config = false;
$store_default_config = false; $store_default_config = false;
$verbose = 0;
foreach ($opts as $opt) { foreach ($opts as $opt) {
$param = $opt[1]; $param = $opt[1];
@ -76,6 +78,12 @@ foreach ($opts as $opt) {
case 'S': case 'S':
$store_default_config = true; $store_default_config = true;
break; 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"); $ext_dir = $config->get("ext_dir");
$doc_dir = $config->get("doc_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) { switch ($command) {
// {{{ install // {{{ install
@ -145,12 +172,38 @@ switch ($command) {
} }
// }}} // }}}
// {{{ list-packages // {{{ list
case 'list-packages': { 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-remote': {
$remote = new PEAR_Remote($config); $remote = new PEAR_Remote($config);
$result = $remote->call('package.listAll'); $result = $remote->call('package.listAll');
$i = $j = 0; $i = $j = 0;
print "Available packages:\n===================\n";
foreach ($result as $package) { foreach ($result as $package) {
if ($i++ % 20 == 0) { if ($i++ % 20 == 0) {
if ($j++ > 0) { if ($j++ > 0) {
@ -190,14 +243,20 @@ function usage($error = null)
fputs($stderr, fputs($stderr,
"Usage: pear [options] command <parameters>\n". "Usage: pear [options] command <parameters>\n".
"Options:\n". "Options:\n".
" -v set verbosity level to <n> (0-2, default 1)\n". " -v increase verbosity level (default 1)\n".
" -p <dir> set script install dir (absolute path)\n". " -q be quiet, decrease verbosity level\n".
" -e <dir> set extension install dir (absolute path)\n". " -c file find user configuration in `file'\n".
" -d <dir> set documentation dest dir (absolute path)\n". " -C file find system configuration in `file'\n".
" -h, -? display help/usage (this message)\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". "Commands:\n".
" install <package file>\n". " install <package file>\n".
" package [package info file]\n". " package [package info file]\n".
" list\n".
" list-remote\n".
"\n"); "\n");
fclose($stderr); fclose($stderr);
exit; exit;