cvs: php4 /pear package-pear.xml package.dtd /pear/PEAR Common.php Config.php Installer.php /pear/PEAR/Command Install.php

From: Date: Tue, 09 Apr 2002 08:10:12 +0000
Subject: cvs: php4 /pear package-pear.xml package.dtd /pear/PEAR Common.php Config.php Installer.php /pear/PEAR/Command Install.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-3167@lists.php.net to get a copy of this message
ssb Tue Apr 9 04:10:12 2002 EDT Modified files: /php4/pear package.dtd package-pear.xml /php4/pear/PEAR Common.php Installer.php Config.php /php4/pear/PEAR/Command Install.php Log: * implemented role="script" and <replace> substitution during install

Index: php4/pear/package.dtd diff -u php4/pear/package.dtd:1.21 php4/pear/package.dtd:1.22 --- php4/pear/package.dtd:1.21 Mon Apr 8 20:03:18 2002 +++ php4/pear/package.dtd Tue Apr 9 04:10:08 2002 @@ -1,5 +1,5 @@ <!-- - $Id: package.dtd,v 1.21 2002/04/09 00:03:18 ssb Exp $ + $Id: package.dtd,v 1.22 2002/04/09 08:10:08 ssb Exp $ This is the PEAR package description, version 1.0b6. It should be used with the informal public identifier: @@ -68,7 +68,6 @@ platform CDATA #IMPLIED md5sum CDATA #IMPLIED name CDATA #REQUIRED - replace (yes|no) 'no' install-as CDATA #IMPLIED> <!ELEMENT replace EMPTY> Index: php4/pear/package-pear.xml diff -u php4/pear/package-pear.xml:1.1 php4/pear/package-pear.xml:1.2 --- php4/pear/package-pear.xml:1.1 Mon Apr 8 20:03:44 2002 +++ php4/pear/package-pear.xml Tue Apr 9 04:10:08 2002 @@ -48,32 +48,32 @@ logout </notes> <filelist> - <file type="php" name="PEAR.php"/> + <file role="php" name="PEAR.php"/> <dir name="PEAR"> - <file type="php" name="Autoloader.php"/> - <file type="php" name="Command.php"/> + <file role="php" name="Autoloader.php"/> + <file role="php" name="Command.php"/> <dir name="Command"> - <file type="php" name="Auth.php"/> - <file type="php" name="Common.php"/> - <file type="php" name="Config.php"/> - <file type="php" name="Install.php"/> - <file type="php" name="Package.php"/> - <file type="php" name="Registry.php"/> - <file type="php" name="Remote.php"/> + <file role="php" name="Auth.php"/> + <file role="php" name="Common.php"/> + <file role="php" name="Config.php"/> + <file role="php" name="Install.php"/> + <file role="php" name="Package.php"/> + <file role="php" name="Registry.php"/> + <file role="php" name="Remote.php"/> </dir> - <file type="php" name="Common.php"/> - <file type="php" name="Config.php"/> - <file type="php" name="Dependency.php"/> + <file role="php" name="Common.php"/> + <file role="php" name="Config.php"/> + <file role="php" name="Dependency.php"/> <dir name="Frontend"> - <file type="php" name="CLI.php"/> + <file role="php" name="CLI.php"/> </dir> - <file type="php" name="Installer.php"/> - <file type="php" name="Packager.php"/> - <file type="php" name="Registry.php"/> - <file type="php" name="Remote.php"/> + <file role="php" name="Installer.php"/> + <file role="php" name="Packager.php"/> + <file role="php" name="Registry.php"/> + <file role="php" name="Remote.php"/> </dir> <dir name="scripts"> - <file baseinstalldir="/" type="script" install-as="pear" name="pear.in" replace="yes"> + <file baseinstalldir="/" role="script" install-as="pear" name="pear.in" replace="yes"> <replace from="@prefix@" to="PHP_PREFIX" type="php-const"/> </file> </dir> Index: php4/pear/PEAR/Common.php diff -u php4/pear/PEAR/Common.php:1.45 php4/pear/PEAR/Common.php:1.46 --- php4/pear/PEAR/Common.php:1.45 Sun Apr 7 16:47:04 2002 +++ php4/pear/PEAR/Common.php Tue Apr 9 04:10:10 2002 @@ -17,7 +17,7 @@ // | Tomas V.V.Cox <cox@idecnet.com> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.45 2002/04/07 20:47:04 cox Exp $ +// $Id: Common.php,v 1.46 2002/04/09 08:10:10 ssb Exp $ require_once 'PEAR.php'; require_once 'Archive/Tar.php'; @@ -84,7 +84,13 @@ * Valid file roles * @var array */ - var $file_roles = array('php','ext','test','doc','data','extsrc'); + var $file_roles = array('php','ext','test','doc','data','extsrc','script'); + + /** + * Valid replacement types + * @var array + */ + var $replacement_types = array('php-const', 'pear-config'); /** * User Interface object (PEAR_Frontend_* class). If null, @@ -93,6 +99,8 @@ */ var $ui = null; + var $current_path = null; + // }}} // {{{ constructor @@ -322,6 +330,34 @@ $this->dir_role = $attribs['role']; } break; + case 'file': + if (isset($attribs['name'])) { + $path = ''; + if (count($this->dir_names)) { + foreach ($this->dir_names as $dir) { + $path .= $dir . DIRECTORY_SEPARATOR; + } + } + $path .= $attribs['name']; + unset($attribs['name']); + $this->current_path = $path; + $this->filelist[$path] = $attribs; + // Set the baseinstalldir only if the file don't have this attrib + if (!isset($this->filelist[$path]['baseinstalldir']) && + isset($this->dir_install)) + { + $this->filelist[$path]['baseinstalldir'] = $this->dir_install; + } + // Set the Role + if (!isset($this->filelist[$path]['role']) && isset($this->dir_role)) { + $this->filelist[$path]['role'] = $this->dir_role; + } + } + break; + case 'replace': + $this->filelist[$this->current_path]['replacements'][] = $attribs; + break; + case 'libfile': $this->lib_atts = $attribs; $this->lib_atts['role'] = 'extsrc'; @@ -452,24 +488,25 @@ array_pop($this->dir_names); break; case 'file': - $this->current_file = $data; - $path = ''; - if (count($this->dir_names)) { - foreach ($this->dir_names as $dir) { - $path .= $dir . DIRECTORY_SEPARATOR; + if ($data) { + $path = ''; + if (count($this->dir_names)) { + foreach ($this->dir_names as $dir) { + $path .= $dir . DIRECTORY_SEPARATOR; + } + } + $path .= $data; + $this->filelist[$path] = $this->current_attributes; + // Set the baseinstalldir only if the file don't have this attrib + if (!isset($this->filelist[$path]['baseinstalldir']) && + isset($this->dir_install)) + { + $this->filelist[$path]['baseinstalldir'] = $this->dir_install; + } + // Set the Role + if (!isset($this->filelist[$path]['role']) && isset($this->dir_role)) { + $this->filelist[$path]['role'] = $this->dir_role; } - } - $path .= $this->current_file; - $this->filelist[$path] = $this->current_attributes; - // Set the baseinstalldir only if the file don't have this attrib - if (!isset($this->filelist[$path]['baseinstalldir']) && - isset($this->dir_install)) - { - $this->filelist[$path]['baseinstalldir'] = $this->dir_install; - } - // Set the Role - if (!isset($this->filelist[$path]['role']) && isset($this->dir_role)) { - $this->filelist[$path]['role'] = $this->dir_role; } break; case 'libfile': @@ -769,20 +806,41 @@ if (isset($pkginfo['filelist'])) { $ret .= "$indent <filelist>\n"; foreach ($pkginfo['filelist'] as $file => $fa) { - if ($fa['role'] == 'extsrc') { + if (@$fa['role'] == 'extsrc') { $ret .= "$indent <libfile>\n"; $ret .= "$indent <libname>$file</libname>\n"; $ret .= "$indent <sources>$fa[sources]</sources>\n"; $ret .= "$indent </libfile>\n"; } else { - $ret .= "$indent <file role=\"$fa[role]\""; + @$ret .= "$indent <file role=\"$fa[role]\""; if (isset($fa['baseinstalldir'])) { - $ret .= " baseinstalldir=\"$fa[baseinstalldir]\""; + $ret .= ' baseinstalldir="' . + htmlspecialchars($fa['baseinstalldir']) . '"'; } if (isset($fa['md5sum'])) { $ret .= " md5sum=\"$fa[md5sum]\""; } - $ret .= ">$file</file>\n"; + if (!empty($fa['replace'])) { + $ret .= ' replace="yes"'; + } + if (!empty($fa['install-as'])) { + $ret .= ' install-as="' . + htmlspecialchars($fa['install-as']) . '"'; + } + $ret .= ' name="' . htmlspecialchars($file) . '"'; + if (empty($fa['replacements'])) { + $ret .= "/>\n"; + } else { + $ret .= ">\n"; + foreach ($fa['replacements'] as $r) { + $ret .= "$indent <replace"; + foreach ($r as $k => $v) { + $ret .= " $k=\"" . htmlspecialchars($v) .'"'; + } + $ret .= "/>\n"; + } + @$ret .= "$indent </file>\n"; + } } } $ret .= "$indent </filelist>\n"; Index: php4/pear/PEAR/Installer.php diff -u php4/pear/PEAR/Installer.php:1.44 php4/pear/PEAR/Installer.php:1.45 --- php4/pear/PEAR/Installer.php:1.44 Sun Apr 7 17:09:41 2002 +++ php4/pear/PEAR/Installer.php Tue Apr 9 04:10:11 2002 @@ -17,7 +17,7 @@ // | Tomas V.V.Cox <cox@idecnet.com> | // +----------------------------------------------------------------------+ // -// $Id: Installer.php,v 1.44 2002/04/07 21:09:41 ssb Exp $ +// $Id: Installer.php,v 1.45 2002/04/09 08:10:11 ssb Exp $ require_once 'PEAR/Common.php'; require_once 'PEAR/Registry.php'; @@ -38,48 +38,60 @@ { // {{{ properties - /** name of the package directory, for example Foo-1.0 */ + /** name of the package directory, for example Foo-1.0 + * @var string + */ var $pkgdir; - /** directory where PHP code files go */ + /** directory where PHP code files go + * @var string + */ var $phpdir; - /** directory where PHP extension files go */ + /** directory where PHP extension files go + * @var string + */ var $extdir; - /** directory where documentation goes */ + /** directory where documentation goes + * @var string + */ var $docdir; /** directory where the package wants to put files, relative - * to one of the three previous dirs + * to one of the previous dirs + * @var string */ var $destdir = ''; - /** debug level (integer) */ + /** debug level + * @var int + */ var $debug = 1; - /** temporary directory */ + /** temporary directory + * @var string + */ var $tmpdir; - /** PEAR_Registry object used by the installer */ + /** PEAR_Registry object used by the installer + * @var object + */ var $registry; + /** PEAR_Config object used by the installer + * @var object + */ + var $config; + // }}} // {{{ constructor - function PEAR_Installer($phpdir = PEAR_INSTALL_DIR, - $extdir = PEAR_EXTENSION_DIR, - $docdir = null) + function PEAR_Installer(&$config) { $this->PEAR(); - $this->phpdir = $phpdir; - $this->extdir = $extdir; - if ($docdir === null) { - $docdir = PHP_DATADIR . DIRECTORY_SEPARATOR . 'pear' . - DIRECTORY_SEPARATOR . 'doc'; - } - $this->docdir = $docdir; + $this->config = &$config; } // }}} @@ -108,30 +120,40 @@ function _installFile($file, $atts, $tmp_path) { - $type = strtolower($atts['role']); - switch ($type) { - case 'test': + switch ($atts['role']) { + case 'test': case 'data': case 'ext': // don't install test files for now - $this->log(2, "+ Test file $file won't be installed yet"); + $this->log(2, "+ $file: $atts[role] file not installed yet"); return true; - break; case 'doc': - $dest_dir = $this->docdir . DIRECTORY_SEPARATOR . - $this->pkginfo['package']; + $dest_dir = $this->config->get('doc_dir') . + DIRECTORY_SEPARATOR . $this->pkginfo['package']; break; + case 'extsrc': + // don't install test files for now + $this->log(2, "+ $file: no support for building extensions yet"); + return true; case 'php': - default: { - $dest_dir = $this->phpdir; - if (isset($atts['baseinstalldir'])) { - $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir']; - } - if (dirname($file) != '.') { - $dest_dir .= DIRECTORY_SEPARATOR . dirname($file); - } + $dest_dir = $this->config->get('php_dir'); + break; + case 'script': { + $dest_dir = $this->config->get('bin_dir'); break; } + default: + break; + } + if (isset($atts['baseinstalldir'])) { + $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir']; + } + if (dirname($file) != '.') { + $dest_dir .= DIRECTORY_SEPARATOR . dirname($file); + } + if (empty($atts['install-as'])) { + $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file); + } else { + $dest_file = $dest_dir . DIRECTORY_SEPARATOR . $atts['install-as']; } - $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file); if (!@is_dir($dest_dir)) { if (!$this->mkDirHier($dest_dir)) { $this->log(0, "failed to mkdir $dest_dir"); @@ -140,13 +162,55 @@ $this->log(2, "+ created dir $dest_dir"); } $orig_file = $tmp_path . DIRECTORY_SEPARATOR . $file; - $orig_perms = fileperms($orig_file); - if (!@copy($orig_file, $dest_file)) { - $this->log(0, "failed to copy $orig_file to $dest_file"); - return false; + if (empty($atts['replacements'])) { + if (!@copy($orig_file, $dest_file)) { + $this->log(0, "failed to copy $orig_file to $dest_file"); + return false; + } + $this->log(2, "+ copy $orig_file to $dest_file"); + } else { + $fp = fopen($orig_file, "r"); + $contents = fread($fp, filesize($orig_file)); + fclose($fp); + $subst_from = $subst_to = array(); + foreach ($atts['replacements'] as $a) { + $to = ''; + if ($a['type'] == 'php-const') { + if (preg_match('/^[a-z0-9_]+$/i', $a['to'])) { + eval("\$to = $a[to];"); + } else { + $this->log(0, "invalid php-const replacement: $a[to]"); + continue; + } + } elseif ($a['type'] == 'pear-config') { + $to = $this->config->get($a['to']); + } + if ($to) { + $subst_from = $a['from']; + $subst_to = $to; + } + } + if (sizeof($subst_from)) { + $contents = str_replace($subst_from, $subst_to, $contents); + } + $wp = @fopen($dest_file, "w"); + if (!is_resource($wp)) { + $this->log(0, "failed to create $dest_file"); + return false; + } + fwrite($wp, $contents); + fclose($wp); + } + if (!OS_WINDOWS) { + if ($atts['role'] == 'script') { + $mode = 0755; + } else { + $mode = 0644; + } + if (!@chmod($dest_file, $mode)) { + $this->log(0, "failed to change mode of $dest_file"); + } } - chmod($dest_file, $orig_perms); - $this->log(2, "+ copy $orig_file to $dest_file"); // Store the full path where the file was installed for easy unistall $this->pkginfo['filelist'][$file]['installed_as'] = $dest_file; @@ -174,7 +238,7 @@ // - soft : fail silently // if (empty($this->registry)) { - $this->registry = new PEAR_Registry($this->phpdir); + $this->registry = new PEAR_Registry($this->config->get('php_dir')); } $oldcwd = getcwd(); $need_download = false; @@ -332,7 +396,7 @@ // info from the package it self we want to access from _installFile $this->pkginfo = $pkginfo; if (empty($options['register_only'])) { - if (!is_dir($this->phpdir)) { + if (!is_dir($this->config->get('php_dir'))) { chdir($oldcwd); return $this->raiseError("no script destination directory\n", null, PEAR_ERROR_DIE); @@ -374,7 +438,7 @@ function uninstall($package) { if (empty($this->registry)) { - $this->registry = new PEAR_Registry($this->phpdir); + $this->registry = new PEAR_Registry($this->config->get('php_dir')); } // Delete the files Index: php4/pear/PEAR/Config.php diff -u php4/pear/PEAR/Config.php:1.15 php4/pear/PEAR/Config.php:1.16 --- php4/pear/PEAR/Config.php:1.15 Mon Apr 1 14:13:37 2002 +++ php4/pear/PEAR/Config.php Tue Apr 9 04:10:11 2002 @@ -16,7 +16,7 @@ // | Author: Stig Bakken <ssb@fast.no> | // +----------------------------------------------------------------------+ // -// $Id: Config.php,v 1.15 2002/04/01 19:13:37 cox Exp $ +// $Id: Config.php,v 1.16 2002/04/09 08:10:11 ssb Exp $ require_once 'PEAR.php'; @@ -27,7 +27,7 @@ $GLOBALS['_PEAR_Config_instance'] = null; define('PEAR_CONFIG_DEFAULT_DOCDIR', - PHP_DATADIR.DIRECTORY_SEPARATOR.'pear'.DIRECTORY_SEPARATOR.'doc'); + PHP_DATADIR.DIRECTORY_SEPARATOR.'doc'.DIRECTORY_SEPARATOR.'pear'); // in case a --without-pear PHP installation is used if (!defined('PEAR_INSTALL_DIR')) { @@ -38,21 +38,8 @@ } /** - * This is a class for storing simple configuration values keeping - * track of which are system-defined, user-defined or defaulted. By - * default, only user-defined settings are stored back to the user's - * configuration file. - * - * Configuration member is a simple associative array. Used keys: - * - * master_server which server to query for mirror lists etc. - * server which server/mirror we're currently using - * username PEAR username - * password PEAR password (stored base64-encoded) - * php_dir Where to install .php files - * ext_dir Directory to install compiled libs in - * doc_dir Directory to install documentation in - * + * This is a class for storing configuration data, keeping track of + * which are system-defined, user-defined or defaulted. */ class PEAR_Config extends PEAR { @@ -114,7 +101,12 @@ 'doc_dir' => array( 'type' => 'directory', 'default' => PEAR_CONFIG_DEFAULT_DOCDIR, - 'doc' => 'directory where documentation is located', + 'doc' => 'directory where documentation is installed', + ), + 'bin_dir' => array( + 'type' => 'directory', + 'default' => PHP_BINDIR, + 'doc' => 'directory where executables are installed', ), 'username' => array( 'type' => 'string', @@ -775,18 +767,21 @@ } // }}} + // {{{ getLayers() /** - * Returns the layers defined (except the 'default' one) - * - * @return array of the defined layers - */ + * Returns the layers defined (except the 'default' one) + * + * @return array of the defined layers + */ function getLayers() { $cf = $this->configuration; unset($cf['default']); return array_keys($cf); } + + // }}} } ?> Index: php4/pear/PEAR/Command/Install.php diff -u php4/pear/PEAR/Command/Install.php:1.17 php4/pear/PEAR/Command/Install.php:1.18 --- php4/pear/PEAR/Command/Install.php:1.17 Sun Apr 7 12:51:17 2002 +++ php4/pear/PEAR/Command/Install.php Tue Apr 9 04:10:12 2002 @@ -16,7 +16,7 @@ // | Author: Stig Bakken <ssb@fast.no> | // +----------------------------------------------------------------------+ // -// $Id: Install.php,v 1.17 2002/04/07 16:51:17 ssb Exp $ +// $Id: Install.php,v 1.18 2002/04/09 08:10:12 ssb Exp $ require_once "PEAR/Command/Common.php"; require_once "PEAR/Installer.php"; @@ -93,9 +93,7 @@ function run($command, $options, $params) { - $installer = &new PEAR_Installer($this->config->get('php_dir'), - $this->config->get('ext_dir'), - $this->config->get('doc_dir')); + $installer = &new PEAR_Installer($this->config); $installer->setFrontend($this->ui); $installer->debug = $this->config->get('verbose');
« previous php.pear.cvs (#3167) next »