cvs: php4 /pear/PEAR/Command Install.php
| From: | Sterling Hughes | Date: | Sat, 07 Jun 2003 03:08:05 +0000 |
| Subject: | cvs: php4 /pear/PEAR/Command Install.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-10739@lists.php.net to get a copy of this message | ||
sterling Fri Jun 6 23:08:05 2003 EDT
Modified files:
/php4/pear/PEAR/Command Install.php
Log:
Add the pear bundle command from Thomas Cox.
Index: php4/pear/PEAR/Command/Install.php
diff -u php4/pear/PEAR/Command/Install.php:1.42 php4/pear/PEAR/Command/Install.php:1.43
--- php4/pear/PEAR/Command/Install.php:1.42 Tue Mar 18 07:06:07 2003
+++ php4/pear/PEAR/Command/Install.php Fri Jun 6 23:08:05 2003
@@ -16,7 +16,7 @@
// | Author: Stig Sæther Bakken <ssb@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: Install.php,v 1.42 2003/03/18 12:06:07 ssb Exp $
+// $Id: Install.php,v 1.43 2003/06/07 03:08:05 sterling Exp $
require_once "PEAR/Command/Common.php";
require_once "PEAR/Installer.php";
@@ -196,7 +196,25 @@
Uninstalls one or more PEAR packages. More than one package may be
specified at once.
'),
-
+ 'bundle' => array(
+ 'summary' => 'Unpacks a Pecl Package',
+ 'function' => 'doBundle',
+ 'shortcut' => 'bun',
+ 'options' => array(
+ 'destination' => array(
+ 'shortopt' => 'd',
+ 'arg' => 'DIR',
+ 'doc' => 'Optional destination directory for unpacking
(defaults to current path or "ext" if exists)',
+ ),
+ 'force' => array(
+ 'shortopt' => 'f',
+ 'doc' => 'Force the unpacking even if there were errors in
the package',
+ ),
+ ),
+ 'doc' => '<package>
+Unpacks a Pecl Package into the selected location. It will download the
+package if needed.
+'),
);
// }}}
@@ -296,7 +314,102 @@
return true;
}
+ // }}}
+
+
// }}}
-}
+ // {{{ doBundle()
+ /*
+ (cox) It just downloads and untars the package, does not do
+ any check that the PEAR_Installer::_installFile() does.
+ */
+
+ function doBundle($command, $options, $params)
+ {
+ if (empty($this->installer)) {
+ $this->installer = &new PEAR_Installer($this->ui);
+ }
+ $installer = &$this->installer;
+ if (sizeof($params) < 1) {
+ return $this->raiseError("Please supply the package you want to bundle");
+ }
+ $pkgfile = $params[0];
+
+ if (preg_match('#^(http|ftp)://#', $pkgfile)) {
+ $need_download = true;
+ } elseif (!@is_file($pkgfile)) {
+ if ($installer->validPackageName($pkgfile)) {
+ $pkgfile = $installer->getPackageDownloadUrl($pkgfile);
+ $need_download = true;
+ } else {
+ if (strlen($pkgfile)) {
+ return $this->raiseError("Could not open the package file:
$pkgfile");
+ } else {
+ return $this->raiseError("No package file given");
+ }
+ }
+ }
+ // Download package -----------------------------------------------
+ if ($need_download) {
+ $downloaddir = $installer->config->get('download_dir');
+ if (empty($downloaddir)) {
+ if (PEAR::isError($downloaddir = System::mktemp('-d'))) {
+ return $downloaddir;
+ }
+ $installer->log(2, '+ tmp dir created at ' . $downloaddir);
+ }
+ $callback = $this->ui ? array(&$installer, '_downloadCallback') :
null;
+ $file = $installer->downloadHttp($pkgfile, $this->ui, $downloaddir, $callback);
+ if (PEAR::isError($file)) {
+ return $this->raiseError($file);
+ }
+ $pkgfile = $file;
+ }
+
+ // Parse xml file -----------------------------------------------
+ $pkginfo = $installer->infoFromTgzFile($pkgfile);
+ if (PEAR::isError($pkginfo)) {
+ return $this->raiseError($pkginfo);
+ }
+ $installer->validatePackageInfo($pkginfo, $errors, $warnings);
+ // XXX We allow warnings, do we have to do it?
+ if (count($errors)) {
+ if (empty($options['force'])) {
+ return $this->raiseError("The following errors where found:\n".
+ implode("\n", $errors));
+ } else {
+ $this->log(0, "warning : the following errors were found:\n".
+ implode("\n", $errors));
+ }
+ }
+ $pkgname = $pkginfo['package'];
+
+ // Unpacking -------------------------------------------------
+
+ if (isset($options['destination'])) {
+ if (!is_dir($options['destination'])) {
+ System::mkdir('-p ' . $options['destination']);
+ }
+ $dest = realpath($options['destination']);
+ } else {
+ $pwd = getcwd();
+ if (is_dir($pwd . DIRECTORY_SEPARATOR . 'ext')) {
+ $dest = $pwd . DIRECTORY_SEPARATOR . 'ext';
+ } else {
+ $dest = $pwd;
+ }
+ }
+ $dest .= DIRECTORY_SEPARATOR . $pkgname;
+ $orig = $pkgname . '-' . $pkginfo['version'];
+
+ $tar = new Archive_Tar($pkgfile);
+ if (!@$tar->extractModify($dest, $orig)) {
+ return $this->raiseError("unable to unpack $pkgfile");
+ }
+ $this->ui->outputData("Package ready at '$dest'");
+ // }}}
+ }
+
+}
?>