PEAR
[ class tree: PEAR ] [ index: PEAR ] [ all elements ]

Source for file Package.php

Documentation is available at Package.php

  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. // | Authors: Stig Bakken <ssb@php.net>                                   |
  17. // |          Martin Jansen <mj@php.net>                                  |
  18. // |          Greg Beaver <cellog@php.net>                                |
  19. // +----------------------------------------------------------------------+
  20. //
  21. // $Id: Package.php,v 1.61.2.5 2004/11/09 19:56:57 cellog Exp $
  22.  
  23. require_once 'PEAR/Common.php';
  24. require_once 'PEAR/Command/Common.php';
  25.  
  26. class PEAR_Command_Package extends PEAR_Command_Common
  27. {
  28.     // {{{ properties
  29.  
  30.     var $commands = array(
  31.         'package' => array(
  32.             'summary' => 'Build Package',
  33.             'function' => 'doPackage',
  34.             'shortcut' => 'p',
  35.             'options' => array(
  36.                 'nocompress' => array(
  37.                     'shortopt' => 'Z',
  38.                     'doc' => 'Do not gzip the package file'
  39.                     ),
  40.                 'showname' => array(
  41.                     'shortopt' => 'n',
  42.                     'doc' => 'Print the name of the packaged file.',
  43.                     ),
  44.                 ),
  45.             'doc' => '[descfile]
  46. Creates a PEAR package from its description file (usually called
  47. package.xml).
  48. '
  49.             ),
  50.         'package-validate' => array(
  51.             'summary' => 'Validate Package Consistency',
  52.             'function' => 'doPackageValidate',
  53.             'shortcut' => 'pv',
  54.             'options' => array(),
  55.             'doc' => '
  56. ',
  57.             ),
  58.         'cvsdiff' => array(
  59.             'summary' => 'Run a "cvs diff" for all files in a package',
  60.             'function' => 'doCvsDiff',
  61.             'shortcut' => 'cd',
  62.             'options' => array(
  63.                 'quiet' => array(
  64.                     'shortopt' => 'q',
  65.                     'doc' => 'Be quiet',
  66.                     ),
  67.                 'reallyquiet' => array(
  68.                     'shortopt' => 'Q',
  69.                     'doc' => 'Be really quiet',
  70.                     ),
  71.                 'date' => array(
  72.                     'shortopt' => 'D',
  73.                     'doc' => 'Diff against revision of DATE',
  74.                     'arg' => 'DATE',
  75.                     ),
  76.                 'release' => array(
  77.                     'shortopt' => 'R',
  78.                     'doc' => 'Diff against tag for package release REL',
  79.                     'arg' => 'REL',
  80.                     ),
  81.                 'revision' => array(
  82.                     'shortopt' => 'r',
  83.                     'doc' => 'Diff against revision REV',
  84.                     'arg' => 'REV',
  85.                     ),
  86.                 'context' => array(
  87.                     'shortopt' => 'c',
  88.                     'doc' => 'Generate context diff',
  89.                     ),
  90.                 'unified' => array(
  91.                     'shortopt' => 'u',
  92.                     'doc' => 'Generate unified diff',
  93.                     ),
  94.                 'ignore-case' => array(
  95.                     'shortopt' => 'i',
  96.                     'doc' => 'Ignore case, consider upper- and lower-case letters equivalent',
  97.                     ),
  98.                 'ignore-whitespace' => array(
  99.                     'shortopt' => 'b',
  100.                     'doc' => 'Ignore changes in amount of white space',
  101.                     ),
  102.                 'ignore-blank-lines' => array(
  103.                     'shortopt' => 'B',
  104.                     'doc' => 'Ignore changes that insert or delete blank lines',
  105.                     ),
  106.                 'brief' => array(
  107.                     'doc' => 'Report only whether the files differ, no details',
  108.                     ),
  109.                 'dry-run' => array(
  110.                     'shortopt' => 'n',
  111.                     'doc' => 'Don\'t do anything, just pretend',
  112.                     ),
  113.                 ),
  114.             'doc' => '<package.xml>
  115. Compares all the files in a package.  Without any options, this
  116. command will compare the current code with the last checked-in code.
  117. Using the -r or -R option you may compare the current code with that
  118. of a specific release.
  119. ',
  120.             ),
  121.         'cvstag' => array(
  122.             'summary' => 'Set CVS Release Tag',
  123.             'function' => 'doCvsTag',
  124.             'shortcut' => 'ct',
  125.             'options' => array(
  126.                 'quiet' => array(
  127.                     'shortopt' => 'q',
  128.                     'doc' => 'Be quiet',
  129.                     ),
  130.                 'reallyquiet' => array(
  131.                     'shortopt' => 'Q',
  132.                     'doc' => 'Be really quiet',
  133.                     ),
  134.                 'slide' => array(
  135.                     'shortopt' => 'F',
  136.                     'doc' => 'Move (slide) tag if it exists',
  137.                     ),
  138.                 'delete' => array(
  139.                     'shortopt' => 'd',
  140.                     'doc' => 'Remove tag',
  141.                     ),
  142.                 'dry-run' => array(
  143.                     'shortopt' => 'n',
  144.                     'doc' => 'Don\'t do anything, just pretend',
  145.                     ),
  146.                 ),
  147.             'doc' => '<package.xml>
  148. Sets a CVS tag on all files in a package.  Use this command after you have
  149. packaged a distribution tarball with the "package" command to tag what
  150. revisions of what files were in that release.  If need to fix something
  151. after running cvstag once, but before the tarball is released to the public,
  152. use the "slide" option to move the release tag.
  153. ',
  154.             ),
  155.         'run-tests' => array(
  156.             'summary' => 'Run Regression Tests',
  157.             'function' => 'doRunTests',
  158.             'shortcut' => 'rt',
  159.             'options' => array(
  160.                 'recur' => array(
  161.                     'shortopt' => 'r',
  162.                     'doc' => 'Run tests in child directories, recursively.  4 dirs deep maximum',
  163.                 )
  164.             ),
  165.             'doc' => '[testfile|dir ...]
  166. Run regression tests with PHP\'s regression testing script (run-tests.php).',
  167.             ),
  168.         'package-dependencies' => array(
  169.             'summary' => 'Show package dependencies',
  170.             'function' => 'doPackageDependencies',
  171.             'shortcut' => 'pd',
  172.             'options' => array(),
  173.             'doc' => '
  174. List all depencies the package has.'
  175.             ),
  176.         'sign' => array(
  177.             'summary' => 'Sign a package distribution file',
  178.             'function' => 'doSign',
  179.             'shortcut' => 'si',
  180.             'options' => array(),
  181.             'doc' => '<package-file>
  182. Signs a package distribution (.tar or .tgz) file with GnuPG.',
  183.             ),
  184.         'makerpm' => array(
  185.             'summary' => 'Builds an RPM spec file from a PEAR package',
  186.             'function' => 'doMakeRPM',
  187.             'shortcut' => 'rpm',
  188.             'options' => array(
  189.                 'spec-template' => array(
  190.                     'shortopt' => 't',
  191.                     'arg' => 'FILE',
  192.                     'doc' => 'Use FILE as RPM spec file template'
  193.                     ),
  194.                 'rpm-pkgname' => array(
  195.                     'shortopt' => 'p',
  196.                     'arg' => 'FORMAT',
  197.                     'doc' => 'Use FORMAT as format string for RPM package name, %s is replaced
  198. by the PEAR package name, defaults to "PEAR::%s".',
  199.                     ),
  200.                 ),
  201.             'doc' => '<package-file>
  202.  
  203. Creates an RPM .spec file for wrapping a PEAR package inside an RPM
  204. package.  Intended to be used from the SPECS directory, with the PEAR
  205. package tarball in the SOURCES directory:
  206.  
  207. $ pear makerpm ../SOURCES/Net_Socket-1.0.tgz
  208. Wrote RPM spec file PEAR::Net_Geo-1.0.spec
  209. $ rpm -bb PEAR::Net_Socket-1.0.spec
  210. ...
  211. Wrote: /usr/src/redhat/RPMS/i386/PEAR::Net_Socket-1.0-1.i386.rpm
  212. ',
  213.             ),
  214.         );
  215.  
  216.     var $output;
  217.  
  218.     // }}}
  219.     // {{{ constructor
  220.  
  221.     /**
  222.      * PEAR_Command_Package constructor.
  223.      *
  224.      * @access public
  225.      */
  226.     function PEAR_Command_Package(&$ui&$config)
  227.     {
  228.         parent::PEAR_Command_Common($ui$config);
  229.     }
  230.  
  231.     // }}}
  232.  
  233.     // {{{ _displayValidationResults()
  234.  
  235.     function _displayValidationResults($err$warn$strict = false)
  236.     {
  237.         foreach ($err as $e{
  238.             $this->output .= "Error: $e\n";
  239.         }
  240.         foreach ($warn as $w{
  241.             $this->output .= "Warning: $w\n";
  242.         }
  243.         $this->output .= sprintf('Validation: %d error(s), %d warning(s)'."\n",
  244.                                        sizeof($err)sizeof($warn));
  245.         if ($strict && sizeof($err> 0{
  246.             $this->output .= "Fix these errors and try again.";
  247.             return false;
  248.         }
  249.         return true;
  250.     }
  251.  
  252.     // }}}
  253.     // {{{ doPackage()
  254.  
  255.     function doPackage($command$options$params)
  256.     {
  257.         $this->output '';
  258.         include_once 'PEAR/Packager.php';
  259.         if (sizeof($params< 1{
  260.             $params[0"package.xml";
  261.         }
  262.         $pkginfofile = isset($params[0]$params[0'package.xml';
  263.         $packager =new PEAR_Packager();
  264.         $err $warn = array();
  265.         $dir dirname($pkginfofile);
  266.         $compress = empty($options['nocompress']? true : false;
  267.         $result $packager->package($pkginfofile$compress);
  268.         if (PEAR::isError($result)) {
  269.             $this->ui->outputData($this->output$command);
  270.             return $this->raiseError($result);
  271.         }
  272.         // Don't want output, only the package file name just created
  273.         if (isset($options['showname'])) {
  274.             $this->output $result;
  275.         }
  276.         if (PEAR::isError($result)) {
  277.             $this->output .= "Package failed: ".$result->getMessage();
  278.         }
  279.         $this->ui->outputData($this->output$command);
  280.         return true;
  281.     }
  282.  
  283.     // }}}
  284.     // {{{ doPackageValidate()
  285.  
  286.     function doPackageValidate($command$options$params)
  287.     {
  288.         $this->output '';
  289.         if (sizeof($params< 1{
  290.             $params[0"package.xml";
  291.         }
  292.         $obj = new PEAR_Common;
  293.         $info = null;
  294.         if ($fp @fopen($params[0]"r")) {
  295.             $test fread($fp5);
  296.             fclose($fp);
  297.             if ($test == "<?xml"{
  298.                 $info $obj->infoFromDescriptionFile($params[0]);
  299.             }
  300.         }
  301.         if (empty($info)) {
  302.             $info $obj->infoFromTgzFile($params[0]);
  303.         }
  304.         if (PEAR::isError($info)) {
  305.             return $this->raiseError($info);
  306.         }
  307.         $obj->validatePackageInfo($info$err$warn);
  308.         $this->_displayValidationResults($err$warn);
  309.         $this->ui->outputData($this->output$command);
  310.         return true;
  311.     }
  312.  
  313.     // }}}
  314.     // {{{ doCvsTag()
  315.  
  316.     function doCvsTag($command$options$params)
  317.     {
  318.         $this->output '';
  319.         $_cmd $command;
  320.         if (sizeof($params< 1{
  321.             $help $this->getHelp($command);
  322.             return $this->raiseError("$command: missing parameter: $help[0]");
  323.         }
  324.         $obj = new PEAR_Common;
  325.         $info $obj->infoFromDescriptionFile($params[0]);
  326.         if (PEAR::isError($info)) {
  327.             return $this->raiseError($info);
  328.         }
  329.         $err $warn = array();
  330.         $obj->validatePackageInfo($info$err$warn);
  331.         if (!$this->_displayValidationResults($err$warntrue)) {
  332.             $this->ui->outputData($this->output$command);
  333.             break;
  334.         }
  335.         $version $info['version'];
  336.         $cvsversion preg_replace('/[^a-z0-9]/i''_'$version);
  337.         $cvstag = "RELEASE_$cvsversion";
  338.         $files array_keys($info['filelist']);
  339.         $command "cvs";
  340.         if (isset($options['quiet'])) {
  341.             $command .= ' -q';
  342.         }
  343.         if (isset($options['reallyquiet'])) {
  344.             $command .= ' -Q';
  345.         }
  346.         $command .= ' tag';
  347.         if (isset($options['slide'])) {
  348.             $command .= ' -F';
  349.         }
  350.         if (isset($options['delete'])) {
  351.             $command .= ' -d';
  352.         }
  353.         $command .= ' ' $cvstag ' ' escapeshellarg($params[0]);
  354.         foreach ($files as $file{
  355.             $command .= ' ' escapeshellarg($file);
  356.         }
  357.         if ($this->config->get('verbose'> 1{
  358.             $this->output .= "$command\n";
  359.         }
  360.         $this->output .= "$command\n";
  361.         if (empty($options['dry-run'])) {
  362.             $fp popen($command"r");
  363.             while ($line fgets($fp1024)) {
  364.                 $this->output .= rtrim($line)."\n";
  365.             }
  366.             pclose($fp);
  367.         }
  368.         $this->ui->outputData($this->output$_cmd);
  369.         return true;
  370.     }
  371.  
  372.     // }}}
  373.     // {{{ doCvsDiff()
  374.  
  375.     function doCvsDiff($command$options$params)
  376.     {
  377.         $this->output '';
  378.         if (sizeof($params< 1{
  379.             $help $this->getHelp($command);
  380.             return $this->raiseError("$command: missing parameter: $help[0]");
  381.         }
  382.         $obj = new PEAR_Common;
  383.         $info $obj->infoFromDescriptionFile($params[0]);
  384.         if (PEAR::isError($info)) {
  385.             return $this->raiseError($info);
  386.         }
  387.         $files array_keys($info['filelist']);
  388.         $cmd "cvs";
  389.         if (isset($options['quiet'])) {
  390.             $cmd .= ' -q';
  391.             unset($options['quiet']);
  392.         }
  393.         if (isset($options['reallyquiet'])) {
  394.             $cmd .= ' -Q';
  395.             unset($options['reallyquiet']);
  396.         }
  397.         if (isset($options['release'])) {
  398.             $cvsversion preg_replace('/[^a-z0-9]/i''_'$options['release']);
  399.             $cvstag = "RELEASE_$cvsversion";
  400.             $options['revision'$cvstag;
  401.             unset($options['release']);
  402.         }
  403.         $execute = true;
  404.         if (isset($options['dry-run'])) {
  405.             $execute = false;
  406.             unset($options['dry-run']);
  407.         }
  408.         $cmd .= ' diff';
  409.         // the rest of the options are passed right on to "cvs diff"
  410.         foreach ($options as $option => $optarg{
  411.             $arg @$this->commands[$command]['options'][$option]['arg'];
  412.             $short @$this->commands[$command]['options'][$option]['shortopt'];
  413.             $cmd .= $short ? " -$short" : " --$option";
  414.             if ($arg && $optarg{
  415.                 $cmd .= ($short '' '='escapeshellarg($optarg);
  416.             }
  417.         }
  418.         foreach ($files as $file{
  419.             $cmd .= ' ' escapeshellarg($file);
  420.         }
  421.         if ($this->config->get('verbose'> 1{
  422.             $this->output .= "$cmd\n";
  423.         }
  424.         if ($execute{
  425.             $fp popen($cmd"r");
  426.             while ($line fgets($fp1024)) {
  427.                 $this->output .= rtrim($line)."\n";
  428.             }
  429.             pclose($fp);
  430.         }
  431.         $this->ui->outputData($this->output$command);
  432.         return true;
  433.     }
  434.  
  435.     // }}}
  436.     // {{{ doRunTests()
  437.  
  438.     function doRunTests($command$options$params)
  439.     {
  440.         include_once 'PEAR/RunTest.php';
  441.         $log = new PEAR_Common;
  442.         $log->ui = &$this->ui// slightly hacky, but it will work
  443.         $run = new PEAR_RunTest($log);
  444.         $tests = array();
  445.         if (isset($options['recur'])) {
  446.             $depth = 4;
  447.         else {
  448.             $depth = 1;
  449.         }
  450.         foreach ($params as $p{
  451.             if (is_dir($p)) {
  452.                 $dir System::find(array($p'-type''f',
  453.                                             '-maxdepth'$depth,
  454.                                             '-name''*.phpt'));
  455.                 $tests array_merge($tests$dir);
  456.             else {
  457.                 $tests[$p;
  458.             }
  459.         }
  460.         foreach ($tests as $t{
  461.             $run->run($t);
  462.         }
  463.         $failed = array();
  464.         foreach ($tests as $t{
  465.             if ($run->run($t== 'FAILED'{
  466.                 $failed[$t;
  467.             }
  468.         }
  469.         if (count($failed)) {
  470.             $this->ui->outputData('FAILED TESTS:');
  471.             foreach ($failed as $failure{
  472.                 $this->ui->outputData($failure);
  473.             }
  474.         }
  475.  
  476.         return true;
  477.         /*
  478.         $cwd = getcwd();
  479.         $php = $this->config->get('php_bin');
  480.         putenv("TEST_PHP_EXECUTABLE=$php");
  481.         // all core PEAR tests use this constant to determine whether they should be run or not
  482.         putenv("PHP_PEAR_RUNTESTS=1");
  483.         $ip = ini_get("include_path");
  484.         $ps = OS_WINDOWS ? ';' : ':';
  485.         $run_tests = $rtsts = $this->config->get('php_dir') . DIRECTORY_SEPARATOR . 'run-tests.php';
  486.         if (!file_exists($run_tests)) {
  487.             $run_tests = PEAR_INSTALL_DIR . DIRECTORY_SEPARATOR . 'run-tests.php';
  488.             if (!file_exists($run_tests)) {
  489.                 return $this->raiseError("No run-tests.php file found. Please copy this ".
  490.                                                 "file from the sources of your PHP distribution to $rtsts");
  491.             }
  492.         }
  493.         if (OS_WINDOWS) {
  494.             // note, this requires a slightly modified version of run-tests.php
  495.             // for some setups
  496.             // unofficial download location is in the pear-dev archives
  497.             $argv = $params;
  498.             array_unshift($argv, $run_tests);
  499.             $argc = count($argv);
  500.             include $run_tests;
  501.         } else {
  502.             $plist = implode(' ', $params);
  503.             $cmd = "$php -d include_path=$cwd$ps$ip -f $run_tests -- $plist";
  504.             system($cmd);
  505.         }
  506.         return true;
  507.         */
  508.     }
  509.  
  510.     // }}}
  511.     // {{{ doPackageDependencies()
  512.  
  513.     function doPackageDependencies($command$options$params)
  514.     {
  515.         // $params[0] -> the PEAR package to list its information
  516.         if (sizeof($params!= 1{
  517.             return $this->raiseError("bad parameter(s), try \"help $command\"");
  518.         }
  519.  
  520.         $obj = new PEAR_Common();
  521.         if (PEAR::isError($info $obj->infoFromAny($params[0]))) {
  522.             return $this->raiseError($info);
  523.         }
  524.  
  525.         if (is_array($info['release_deps'])) {
  526.             $data = array(
  527.                 'caption' => 'Dependencies for ' $info['package'],
  528.                 'border' => true,
  529.                 'headline' => array("Type""Name""Relation""Version"),
  530.                 );
  531.  
  532.             foreach ($info['release_deps'as $d{
  533.  
  534.                 if (isset($this->_deps_rel_trans[$d['rel']])) {
  535.                     $rel $this->_deps_rel_trans[$d['rel']];
  536.                 else {
  537.                     $rel $d['rel'];
  538.                 }
  539.  
  540.                 if (isset($this->_deps_type_trans[$d['type']])) {
  541.                     $type ucfirst($this->_deps_type_trans[$d['type']]);
  542.                 else {
  543.                     $type $d['type'];
  544.                 }
  545.  
  546.                 if (isset($d['name'])) {
  547.                     $name $d['name'];
  548.                 else {
  549.                     $name '';
  550.                 }
  551.  
  552.                 if (isset($d['version'])) {
  553.                     $version $d['version'];
  554.                 else {
  555.                     $version '';
  556.                 }
  557.  
  558.                 $data['data'][= array($type$name$rel$version);
  559.             }
  560.  
  561.             $this->ui->outputData($data$command);
  562.             return true;
  563.         }
  564.  
  565.         // Fallback
  566.         $this->ui->outputData("This package does not have any dependencies."$command);
  567.     }
  568.  
  569.     // }}}
  570.     // {{{ doSign()
  571.  
  572.     function doSign($command$options$params)
  573.     {
  574.         // should move most of this code into PEAR_Packager
  575.         // so it'll be easy to implement "pear package --sign"
  576.         if (sizeof($params!= 1{
  577.             return $this->raiseError("bad parameter(s), try \"help $command\"");
  578.         }
  579.         if (!file_exists($params[0])) {
  580.             return $this->raiseError("file does not exist: $params[0]");
  581.         }
  582.         $obj = new PEAR_Common;
  583.         $info $obj->infoFromTgzFile($params[0]);
  584.         if (PEAR::isError($info)) {
  585.             return $this->raiseError($info);
  586.         }
  587.         include_once "Archive/Tar.php";
  588.         include_once "System.php";
  589.         $tar = new Archive_Tar($params[0]);
  590.         $tmpdir System::mktemp('-d pearsign');
  591.         if (!$tar->extractList('package.xml package.sig'$tmpdir)) {
  592.             return $this->raiseError("failed to extract tar file");
  593.         }
  594.         if (file_exists("$tmpdir/package.sig")) {
  595.             return $this->raiseError("package already signed");
  596.         }
  597.         @unlink("$tmpdir/package.sig");
  598.         $input $this->ui->userDialog($command,
  599.                                        array('GnuPG Passphrase'),
  600.                                        array('password'));
  601.         $gpg popen("gpg --batch --passphrase-fd 0 --armor --detach-sign --output $tmpdir/package.sig $tmpdir/package.xml 2>/dev/null""w");
  602.         if (!$gpg{
  603.             return $this->raiseError("gpg command failed");
  604.         }
  605.         fwrite($gpg"$input[0]\r");
  606.         if (pclose($gpg|| !file_exists("$tmpdir/package.sig")) {
  607.             return $this->raiseError("gpg sign failed");
  608.         }
  609.         $tar->addModify("$tmpdir/package.sig"''$tmpdir);
  610.         return true;
  611.     }
  612.  
  613.     // }}}
  614.     // {{{ doMakeRPM()
  615.  
  616.     /*
  617.  
  618.     (cox)
  619.  
  620.     TODO:
  621.  
  622.         - Fill the rpm dependencies in the template file.
  623.  
  624.     IDEAS:
  625.  
  626.         - Instead of mapping the role to rpm vars, perhaps it's better
  627.  
  628.           to use directly the pear cmd to install the files by itself
  629.  
  630.           in %postrun so:
  631.  
  632.           pear -d php_dir=%{_libdir}/php/pear -d test_dir=.. <package>
  633.  
  634.     */
  635.  
  636.     function doMakeRPM($command$options$params)
  637.     {
  638.         if (sizeof($params!= 1{
  639.             return $this->raiseError("bad parameter(s), try \"help $command\"");
  640.         }
  641.         if (!file_exists($params[0])) {
  642.             return $this->raiseError("file does not exist: $params[0]");
  643.         }
  644.         include_once "Archive/Tar.php";
  645.         include_once "PEAR/Installer.php";
  646.         include_once "System.php";
  647.         $tar = new Archive_Tar($params[0]);
  648.         $tmpdir System::mktemp('-d pear2rpm');
  649.         $instroot System::mktemp('-d pear2rpm');
  650.         $tmp $this->config->get('verbose');
  651.         $this->config->set('verbose'0);
  652.         $installer = new PEAR_Installer($this->ui);
  653.         $info $installer->install($params[0],
  654.                                     array('installroot' => $instroot,
  655.                                           'nodeps' => true));
  656.         $pkgdir = "$info[package]-$info[version]";
  657.         $info['rpm_xml_dir''/var/lib/pear';
  658.         $this->config->set('verbose'$tmp);
  659.         if (!$tar->extractList("package.xml"$tmpdir$pkgdir)) {
  660.             return $this->raiseError("failed to extract $params[0]");
  661.         }
  662.         if (!file_exists("$tmpdir/package.xml")) {
  663.             return $this->raiseError("no package.xml found in $params[0]");
  664.         }
  665.         if (isset($options['spec-template'])) {
  666.             $spec_template $options['spec-template'];
  667.         else {
  668.             $spec_template $this->config->get('data_dir'.
  669.                 '/PEAR/template.spec';
  670.         }
  671.         if (isset($options['rpm-pkgname'])) {
  672.             $rpm_pkgname_format $options['rpm-pkgname'];
  673.         else {
  674.             $rpm_pkgname_format "PEAR::%s";
  675.         }
  676.  
  677.         $info['extra_headers''';
  678.         $info['doc_files''';
  679.         $info['files''';
  680.         $info['rpm_package'sprintf($rpm_pkgname_format$info['package']);
  681.         $srcfiles = 0;
  682.         foreach ($info['filelist'as $name => $attr{
  683.  
  684.             if (!isset($attr['role'])) {
  685.                 continue;
  686.             }
  687.             $name preg_replace('![/:\\\\]!''/'$name);
  688.             if ($attr['role'== 'doc'{
  689.                 $info['doc_files'.= " $name";
  690.  
  691.             // Map role to the rpm vars
  692.             else {
  693.  
  694.                 $c_prefix '%{_libdir}/php/pear';
  695.  
  696.                 switch ($attr['role']{
  697.  
  698.                     case 'php':
  699.  
  700.                         $prefix $c_prefix; break;
  701.  
  702.                     case 'ext':
  703.  
  704.                         $prefix '%{_libdir}/php'; break; // XXX good place?
  705.  
  706.                     case 'src':
  707.  
  708.                         $srcfiles++;
  709.  
  710.                         $prefix '%{_includedir}/php'; break; // XXX good place?
  711.  
  712.                     case 'test':
  713.  
  714.                         $prefix = "$c_prefix/tests/" . $info['package']; break;
  715.  
  716.                     case 'data':
  717.  
  718.                         $prefix = "$c_prefix/data/" . $info['package']; break;
  719.  
  720.                     case 'script':
  721.  
  722.                         $prefix '%{_bindir}'; break;
  723.  
  724.                 }
  725.  
  726.                 $name str_replace('\\''/'$name);
  727.                 $info['files'.= "$prefix/$name\n";
  728.  
  729.             }
  730.         }
  731.         if ($srcfiles > 0{
  732.             include_once "OS/Guess.php";
  733.             $os = new OS_Guess;
  734.             $arch $os->getCpu();
  735.         else {
  736.             $arch 'noarch';
  737.         }
  738.         $cfg = array('master_server''php_dir''ext_dir''doc_dir',
  739.                      'bin_dir''data_dir''test_dir');
  740.         foreach ($cfg as $k{
  741.             $info[$k$this->config->get($k);
  742.         }
  743.         $info['arch'$arch;
  744.         $fp @fopen($spec_template"r");
  745.         if (!$fp{
  746.             return $this->raiseError("could not open RPM spec file template $spec_template$php_errormsg");
  747.         }
  748.         $spec_contents preg_replace('/@([a-z0-9_-]+)@/e''$info["\1"]'fread($fpfilesize($spec_template)));
  749.         fclose($fp);
  750.         $spec_file = "$info[rpm_package]-$info[version].spec";
  751.         $wp fopen($spec_file"wb");
  752.         if (!$wp{
  753.             return $this->raiseError("could not write RPM spec file $spec_file$php_errormsg");
  754.         }
  755.         fwrite($wp$spec_contents);
  756.         fclose($wp);
  757.         $this->ui->outputData("Wrote RPM spec file $spec_file"$command);
  758.  
  759.         return true;
  760.     }
  761.  
  762.     // }}}
  763. }
  764.  
  765. ?>

Documentation generated on Mon, 11 Mar 2019 13:58:39 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.