[ Index ]
 

Code source de SPIP Agora 1.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Pear/PEAR/Command/ -> Install.php (source)

   1  <?php
   2  //
   3  // +----------------------------------------------------------------------+
   4  // | PHP Version 5                                                        |
   5  // +----------------------------------------------------------------------+
   6  // | Copyright (c) 1997-2004 The PHP Group                                |
   7  // +----------------------------------------------------------------------+
   8  // | This source file is subject to version 3.0 of the PHP license,       |
   9  // | that is bundled with this package in the file LICENSE, and is        |
  10  // | available through the world-wide-web at the following url:           |
  11  // | http://www.php.net/license/3_0.txt.                                  |
  12  // | If you did not receive a copy of the PHP license and are unable to   |
  13  // | obtain it through the world-wide-web, please send a note to          |
  14  // | license@php.net so we can mail you a copy immediately.               |
  15  // +----------------------------------------------------------------------+
  16  // | Author: Stig Sæther Bakken <ssb@php.net>                             |
  17  // +----------------------------------------------------------------------+
  18  //
  19  // $Id: Install.php,v 1.53.2.1 2004/10/19 04:08:42 cellog Exp $
  20  
  21  require_once "PEAR/Command/Common.php";
  22  require_once "PEAR/Installer.php";
  23  
  24  /**
  25   * PEAR commands for installation or deinstallation/upgrading of
  26   * packages.
  27   *
  28   */
  29  class PEAR_Command_Install extends PEAR_Command_Common
  30  {
  31      // {{{ properties
  32  
  33      var $commands = array(
  34          'install' => array(
  35              'summary' => 'Install Package',
  36              'function' => 'doInstall',
  37              'shortcut' => 'i',
  38              'options' => array(
  39                  'force' => array(
  40                      'shortopt' => 'f',
  41                      'doc' => 'will overwrite newer installed packages',
  42                      ),
  43                  'nodeps' => array(
  44                      'shortopt' => 'n',
  45                      'doc' => 'ignore dependencies, install anyway',
  46                      ),
  47                  'register-only' => array(
  48                      'shortopt' => 'r',
  49                      'doc' => 'do not install files, only register the package as installed',
  50                      ),
  51                  'soft' => array(
  52                      'shortopt' => 's',
  53                      'doc' => 'soft install, fail silently, or upgrade if already installed',
  54                      ),
  55                  'nobuild' => array(
  56                      'shortopt' => 'B',
  57                      'doc' => 'don\'t build C extensions',
  58                      ),
  59                  'nocompress' => array(
  60                      'shortopt' => 'Z',
  61                      'doc' => 'request uncompressed files when downloading',
  62                      ),
  63                  'installroot' => array(
  64                      'shortopt' => 'R',
  65                      'arg' => 'DIR',
  66                      'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
  67                      ),
  68                  'ignore-errors' => array(
  69                      'doc' => 'force install even if there were errors',
  70                      ),
  71                  'alldeps' => array(
  72                      'shortopt' => 'a',
  73                      'doc' => 'install all required and optional dependencies',
  74                      ),
  75                  'onlyreqdeps' => array(
  76                      'shortopt' => 'o',
  77                      'doc' => 'install all required dependencies',
  78                      ),
  79                  ),
  80              'doc' => '<package> ...
  81  Installs one or more PEAR packages.  You can specify a package to
  82  install in four ways:
  83  
  84  "Package-1.0.tgz" : installs from a local file
  85  
  86  "http://example.com/Package-1.0.tgz" : installs from
  87  anywhere on the net.
  88  
  89  "package.xml" : installs the package described in
  90  package.xml.  Useful for testing, or for wrapping a PEAR package in
  91  another package manager such as RPM.
  92  
  93  "Package" : queries your configured server
  94  ({config master_server}) and downloads the newest package with
  95  the preferred quality/state ({config preferred_state}).
  96  
  97  More than one package may be specified at once.  It is ok to mix these
  98  four ways of specifying packages.
  99  '),
 100          'upgrade' => array(
 101              'summary' => 'Upgrade Package',
 102              'function' => 'doInstall',
 103              'shortcut' => 'up',
 104              'options' => array(
 105                  'force' => array(
 106                      'shortopt' => 'f',
 107                      'doc' => 'overwrite newer installed packages',
 108                      ),
 109                  'nodeps' => array(
 110                      'shortopt' => 'n',
 111                      'doc' => 'ignore dependencies, upgrade anyway',
 112                      ),
 113                  'register-only' => array(
 114                      'shortopt' => 'r',
 115                      'doc' => 'do not install files, only register the package as upgraded',
 116                      ),
 117                  'nobuild' => array(
 118                      'shortopt' => 'B',
 119                      'doc' => 'don\'t build C extensions',
 120                      ),
 121                  'nocompress' => array(
 122                      'shortopt' => 'Z',
 123                      'doc' => 'request uncompressed files when downloading',
 124                      ),
 125                  'installroot' => array(
 126                      'shortopt' => 'R',
 127                      'arg' => 'DIR',
 128                      'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
 129                      ),
 130                  'ignore-errors' => array(
 131                      'doc' => 'force install even if there were errors',
 132                      ),
 133                  'alldeps' => array(
 134                      'shortopt' => 'a',
 135                      'doc' => 'install all required and optional dependencies',
 136                      ),
 137                  'onlyreqdeps' => array(
 138                      'shortopt' => 'o',
 139                      'doc' => 'install all required dependencies',
 140                      ),
 141                  ),
 142              'doc' => '<package> ...
 143  Upgrades one or more PEAR packages.  See documentation for the
 144  "install" command for ways to specify a package.
 145  
 146  When upgrading, your package will be updated if the provided new
 147  package has a higher version number (use the -f option if you need to
 148  upgrade anyway).
 149  
 150  More than one package may be specified at once.
 151  '),
 152          'upgrade-all' => array(
 153              'summary' => 'Upgrade All Packages',
 154              'function' => 'doInstall',
 155              'shortcut' => 'ua',
 156              'options' => array(
 157                  'nodeps' => array(
 158                      'shortopt' => 'n',
 159                      'doc' => 'ignore dependencies, upgrade anyway',
 160                      ),
 161                  'register-only' => array(
 162                      'shortopt' => 'r',
 163                      'doc' => 'do not install files, only register the package as upgraded',
 164                      ),
 165                  'nobuild' => array(
 166                      'shortopt' => 'B',
 167                      'doc' => 'don\'t build C extensions',
 168                      ),
 169                  'nocompress' => array(
 170                      'shortopt' => 'Z',
 171                      'doc' => 'request uncompressed files when downloading',
 172                      ),
 173                  'installroot' => array(
 174                      'shortopt' => 'R',
 175                      'arg' => 'DIR',
 176                      'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
 177                      ),
 178                  'ignore-errors' => array(
 179                      'doc' => 'force install even if there were errors',
 180                      ),
 181                  ),
 182              'doc' => '
 183  Upgrades all packages that have a newer release available.  Upgrades are
 184  done only if there is a release available of the state specified in
 185  "preferred_state" (currently {config preferred_state}), or a state considered
 186  more stable.
 187  '),
 188          'uninstall' => array(
 189              'summary' => 'Un-install Package',
 190              'function' => 'doUninstall',
 191              'shortcut' => 'un',
 192              'options' => array(
 193                  'nodeps' => array(
 194                      'shortopt' => 'n',
 195                      'doc' => 'ignore dependencies, uninstall anyway',
 196                      ),
 197                  'register-only' => array(
 198                      'shortopt' => 'r',
 199                      'doc' => 'do not remove files, only register the packages as not installed',
 200                      ),
 201                  'installroot' => array(
 202                      'shortopt' => 'R',
 203                      'arg' => 'DIR',
 204                      'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
 205                      ),
 206                  'ignore-errors' => array(
 207                      'doc' => 'force install even if there were errors',
 208                      ),
 209                  ),
 210              'doc' => '<package> ...
 211  Uninstalls one or more PEAR packages.  More than one package may be
 212  specified at once.
 213  '),
 214          'bundle' => array(
 215              'summary' => 'Unpacks a Pecl Package',
 216              'function' => 'doBundle',
 217              'shortcut' => 'bun',
 218              'options' => array(
 219                  'destination' => array(
 220                     'shortopt' => 'd',
 221                      'arg' => 'DIR',
 222                      'doc' => 'Optional destination directory for unpacking (defaults to current path or "ext" if exists)',
 223                      ),
 224                  'force' => array(
 225                      'shortopt' => 'f',
 226                      'doc' => 'Force the unpacking even if there were errors in the package',
 227                  ),
 228              ),
 229              'doc' => '<package>
 230  Unpacks a Pecl Package into the selected location. It will download the
 231  package if needed.
 232  '),
 233      );
 234  
 235      // }}}
 236      // {{{ constructor
 237  
 238      /**
 239       * PEAR_Command_Install constructor.
 240       *
 241       * @access public
 242       */
 243      function PEAR_Command_Install(&$ui, &$config)
 244      {
 245          parent::PEAR_Command_Common($ui, $config);
 246      }
 247  
 248      // }}}
 249  
 250      // {{{ doInstall()
 251  
 252      function doInstall($command, $options, $params)
 253      {
 254          require_once 'PEAR/Downloader.php';
 255          if (empty($this->installer)) {
 256              $this->installer = &new PEAR_Installer($this->ui);
 257          }
 258          if ($command == 'upgrade') {
 259              $options['upgrade'] = true;
 260          }
 261          if ($command == 'upgrade-all') {
 262              include_once "PEAR/Remote.php";
 263              $options['upgrade'] = true;
 264              $remote = &new PEAR_Remote($this->config);
 265              $state = $this->config->get('preferred_state');
 266              if (empty($state) || $state == 'any') {
 267                  $latest = $remote->call("package.listLatestReleases");
 268              } else {
 269                  $latest = $remote->call("package.listLatestReleases", $state);
 270              }
 271              if (PEAR::isError($latest)) {
 272                  return $latest;
 273              }
 274              $reg = new PEAR_Registry($this->config->get('php_dir'));
 275              $installed = array_flip($reg->listPackages());
 276              $params = array();
 277              foreach ($latest as $package => $info) {
 278                  $package = strtolower($package);
 279                  if (!isset($installed[$package])) {
 280                      // skip packages we don't have installed
 281                      continue;
 282                  }
 283                  $inst_version = $reg->packageInfo($package, 'version');
 284                  if (version_compare("$info[version]", "$inst_version", "le")) {
 285                      // installed version is up-to-date
 286                      continue;
 287                  }
 288                  $params[] = $package;
 289                  $this->ui->outputData(array('data' => "Will upgrade $package"), $command);
 290              }
 291          }
 292          $this->downloader = &new PEAR_Downloader($this->ui, $options, $this->config);
 293          $errors = array();
 294          $downloaded = array();
 295          $this->downloader->download($params);
 296          $errors = $this->downloader->getErrorMsgs();
 297          if (count($errors)) {
 298              $err['data'] = array($errors);
 299              $err['headline'] = 'Install Errors';
 300              $this->ui->outputData($err);
 301              return $this->raiseError("$command failed");
 302          }
 303          $downloaded = $this->downloader->getDownloadedPackages();
 304          $this->installer->sortPkgDeps($downloaded);
 305          foreach ($downloaded as $pkg) {
 306              PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
 307              $info = $this->installer->install($pkg['file'], $options, $this->config);
 308              PEAR::popErrorHandling();
 309              if (PEAR::isError($info)) {
 310                  $this->ui->outputData('ERROR: ' .$info->getMessage());
 311                  continue;
 312              }
 313              if (is_array($info)) {
 314                  if ($this->config->get('verbose') > 0) {
 315                      $label = "$info[package] $info[version]";
 316                      $out = array('data' => "$command ok: $label");
 317                      if (isset($info['release_warnings'])) {
 318                          $out['release_warnings'] = $info['release_warnings'];
 319                      }
 320                      $this->ui->outputData($out, $command);
 321                  }
 322              } else {
 323                  return $this->raiseError("$command failed");
 324              }
 325          }
 326          return true;
 327      }
 328  
 329      // }}}
 330      // {{{ doUninstall()
 331  
 332      function doUninstall($command, $options, $params)
 333      {
 334          if (empty($this->installer)) {
 335              $this->installer = &new PEAR_Installer($this->ui);
 336          }
 337          if (sizeof($params) < 1) {
 338              return $this->raiseError("Please supply the package(s) you want to uninstall");
 339          }
 340          include_once 'PEAR/Registry.php';
 341          $reg = new PEAR_Registry($this->config->get('php_dir'));
 342          $newparams = array();
 343          $badparams = array();
 344          foreach ($params as $pkg) {
 345              $info = $reg->packageInfo($pkg);
 346              if ($info === null) {
 347                  $badparams[] = $pkg;
 348              } else {
 349                  $newparams[] = $info;
 350              }
 351          }
 352          $this->installer->sortPkgDeps($newparams, true);
 353          $params = array();
 354          foreach($newparams as $info) {
 355              $params[] = $info['info']['package'];
 356          }
 357          $params = array_merge($params, $badparams);
 358          foreach ($params as $pkg) {
 359              if ($this->installer->uninstall($pkg, $options)) {
 360                  if ($this->config->get('verbose') > 0) {
 361                      $this->ui->outputData("uninstall ok: $pkg", $command);
 362                  }
 363              } else {
 364                  return $this->raiseError("uninstall failed: $pkg");
 365              }
 366          }
 367          return true;
 368      }
 369  
 370      // }}}
 371  
 372  
 373      // }}}
 374      // {{{ doBundle()
 375      /*
 376      (cox) It just downloads and untars the package, does not do
 377              any check that the PEAR_Installer::_installFile() does.
 378      */
 379  
 380      function doBundle($command, $options, $params)
 381      {
 382          if (empty($this->installer)) {
 383              $this->installer = &new PEAR_Downloader($this->ui);
 384          }
 385          $installer = &$this->installer;
 386          if (sizeof($params) < 1) {
 387              return $this->raiseError("Please supply the package you want to bundle");
 388          }
 389          $pkgfile = $params[0];
 390          $need_download = false;
 391          if (preg_match('#^(http|ftp)://#', $pkgfile)) {
 392              $need_download = true;
 393          } elseif (!@is_file($pkgfile)) {
 394              if ($installer->validPackageName($pkgfile)) {
 395                  $pkgfile = $installer->getPackageDownloadUrl($pkgfile);
 396                  $need_download = true;
 397              } else {
 398                  if (strlen($pkgfile)) {
 399                      return $this->raiseError("Could not open the package file: $pkgfile");
 400                  } else {
 401                      return $this->raiseError("No package file given");
 402                  }
 403              }
 404          }
 405  
 406          // Download package -----------------------------------------------
 407          if ($need_download) {
 408              $downloaddir = $installer->config->get('download_dir');
 409              if (empty($downloaddir)) {
 410                  if (PEAR::isError($downloaddir = System::mktemp('-d'))) {
 411                      return $downloaddir;
 412                  }
 413                  $installer->log(2, '+ tmp dir created at ' . $downloaddir);
 414              }
 415              $callback = $this->ui ? array(&$installer, '_downloadCallback') : null;
 416              $file = $installer->downloadHttp($pkgfile, $this->ui, $downloaddir, $callback);
 417              if (PEAR::isError($file)) {
 418                  return $this->raiseError($file);
 419              }
 420              $pkgfile = $file;
 421          }
 422  
 423         // Parse xml file -----------------------------------------------
 424          $pkginfo = $installer->infoFromTgzFile($pkgfile);
 425          if (PEAR::isError($pkginfo)) {
 426              return $this->raiseError($pkginfo);
 427          }
 428          $installer->validatePackageInfo($pkginfo, $errors, $warnings);
 429          // XXX We allow warnings, do we have to do it?
 430          if (count($errors)) {
 431               if (empty($options['force'])) {
 432                  return $this->raiseError("The following errors where found:\n".
 433                                                   implode("\n", $errors));
 434              } else {
 435                  $this->log(0, "warning : the following errors were found:\n".
 436                             implode("\n", $errors));
 437              }
 438          }
 439          $pkgname = $pkginfo['package'];
 440  
 441          // Unpacking -------------------------------------------------
 442  
 443          if (isset($options['destination'])) {
 444              if (!is_dir($options['destination'])) {
 445                  System::mkdir('-p ' . $options['destination']);
 446              }
 447              $dest = realpath($options['destination']);
 448          } else {
 449              $pwd = getcwd();
 450              if (is_dir($pwd . DIRECTORY_SEPARATOR . 'ext')) {
 451                  $dest = $pwd . DIRECTORY_SEPARATOR . 'ext';
 452              } else {
 453                  $dest = $pwd;
 454              }
 455          }
 456          $dest .= DIRECTORY_SEPARATOR . $pkgname;
 457          $orig = $pkgname . '-' . $pkginfo['version'];
 458  
 459          $tar = new Archive_Tar($pkgfile);
 460          if (!@$tar->extractModify($dest, $orig)) {
 461              return $this->raiseError("unable to unpack $pkgfile");
 462          }
 463          $this->ui->outputData("Package ready at '$dest'");
 464      // }}}
 465      }
 466  
 467      // }}}
 468  
 469  }
 470  ?>


Généré le : Sat Feb 24 14:40:03 2007 par Balluche grâce à PHPXref 0.7