<commit_before><?php
//
// +----------------------------------------------------------------------+
// | PHP Version 4                                                        |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group                                |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license,      |
// | that is bundled with this package in the file LICENSE, and is        |
// | available at through the world-wide-web at                           |
// | http://www.php.net/license/2_02.txt.                                 |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// | <EMAIL> so we can mail you a copy immediately.               |
// +----------------------------------------------------------------------+
// | Author: <NAME> <<EMAIL>>                                    |
// +----------------------------------------------------------------------+
//
// $Id$

require_once 'PEAR/Command/Common.php';
require_once 'PEAR/Packager.php';
require_once 'PEAR/Common.php';

class PEAR_Command_Package extends PEAR_Command_Common
{
    // {{{ constructor

    /**
     * PEAR_Command_Package constructor.
     *
     * @access public
     */
    function PEAR_Command_Package(&$ui, &$config)
    {
        parent::PEAR_Command_Common($ui, $config);
    }

    // }}}

    // {{{ _displayValidationResults()

    function _displayValidationResults($err, $warn, $strict = false)
    {
        foreach ($err as $e) {
            $this->ui->displayLine("Error: $e");
        }
        foreach ($warn as $w) {
            $this->ui->displayLine("Warning: $w");
        }
        $this->ui->displayLine(sprintf('Validation: %d error(s), %d warning(s)',
                                       sizeof($err), sizeof($warn)));
        if ($strict && sizeof($err) > 0) {
            $this->ui->displayLine("Fix these errors and try again.");
            return false;
        }
        return true;
    }

    // }}}
    // {{{ getCommands()

    /**
     * Return a list of all the commands defined by this class.
     * @return array list of commands
     * @access public
     */
    function getCommands()
    {
        return array('package',
                     'package-info',
                     'package-list',
                     'package-validate',
                     'cvstag');
    }

    // }}}
    // {{{ getOptions()

    function getOptions()
    {
        return array('Z', 'n' /*, 'f', 'd', 'q', 'Q'*/);
    }

    // }}}
    // {{{ getHelp()

    function getHelp($command)
    {
        switch ($command) {
            case 'package':
                return array('[<package.xml>]',
                             'Creates a PEAR package from its description file (usually '.
                             'named as package.xml)');
            case 'package-list':
                return array('<pear package>',
                             'List the contents of a PEAR package');
            case 'packge-info':
                return array('<pear package>',
                             'Shows information about a PEAR package');
            case 'package-validate':
                return array('<package.(tgz|tar|xml)>',
                             'Verifies a package or description file');
            case 'cvstag':
                return array('<package.xml>',
                             'Runs "cvs tag" on files contained in a release');
        }
    }

    // }}}
    // {{{ run()

    /**
     * Execute the command.
     *
     * @param string command name
     *
     * @param array option_name => value
     *
     * @param array list of additional parameters
     *
     * @return bool TRUE on success, FALSE for unknown commands, or
     * a PEAR error on failure
     *
     * @access public
     */
    function run($command, $options, $params)
    {
        $failmsg = '';
        switch ($command) {
            // {{{ package

            case 'package': {
                $pkginfofile = isset($params[0]) ? $params[0] : 'package.xml';
                ob_start();
                $packager =& new PEAR_Packager($this->config->get('php_dir'),
                                               $this->config->get('ext_dir'),
                                               $this->config->get('doc_dir'));
                $packager->debug = $this->config->get('verbose');
                $err = $warn = array();
                $packager->validatePackageInfo($pkginfofile, $err, $warn);
                if (!$this->_displayValidationResults($err, $warn, true)) {
                    break;
                }
                $compress = empty($options['Z']) ? true : false;
                $result = $packager->Package($pkginfofile, $compress);
                $output = ob_get_contents();
                ob_end_clean();
                $lines = explode("\n", $output);
                foreach ($lines as $line) {
                    $this->ui->displayLine($line);
                }
                if (PEAR::isError($result)) {
                    $this->ui->displayLine("Package failed: ".$result->getMessage());
                }
                break;
            }

            // }}}
            // {{{ package-list

            case 'package-list': {
                $obj = new PEAR_Common();
                if (PEAR::isError($info = $obj->infoFromTgzFile($params[0]))) {
                    return $info;
                }
                $list =$info['filelist'];
                $caption = 'Contents of ' . basename($params[0]);
                $this->ui->startTable(array('caption' => $caption,
                                            'border' => true));
                $this->ui->tableRow(array('Package Files', 'Install Destination'),
                                    array('bold' => true));
                foreach ($list as $file => $att) {
                    if (isset($att['baseinstalldir'])) {
                        $dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR .
                                basename($file);
                    } else {
                        $dest = basename($file);
                    }
                    switch ($att['role']) {
                        case 'test':
                            $dest = '-- will not be installed --'; break;
                        case 'doc':
                            $dest = $this->config->get('doc_dir') . DIRECTORY_SEPARATOR .
                                    $dest;
                            break;
                        case 'php':
                        default:
                            $dest = $this->config->get('php_dir') . DIRECTORY_SEPARATOR .
                                    $dest;
                    }
                    $dest = preg_replace('!/+!', '/', $dest);
                    $file = preg_replace('!/+!', '/', $file);
                    $opts = array(0 => array('wrap' => 23),<commit_msg>Fix package-list not showing the right Install path<commit_after><?php
//
// +----------------------------------------------------------------------+
// | PHP Version 4                                                        |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group                                |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license,      |
// | that is bundled with this package in the file LICENSE, and is        |
// | available at through the world-wide-web at                           |
// | http://www.php.net/license/2_02.txt.                                 |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// | <EMAIL> so we can mail you a copy immediately.               |
// +----------------------------------------------------------------------+
// | Author: <NAME> <<EMAIL>>                                    |
// +----------------------------------------------------------------------+
//
// $Id$

require_once 'PEAR/Command/Common.php';
require_once 'PEAR/Packager.php';
require_once 'PEAR/Common.php';

class PEAR_Command_Package extends PEAR_Command_Common
{
    // {{{ constructor

    /**
     * PEAR_Command_Package constructor.
     *
     * @access public
     */
    function PEAR_Command_Package(&$ui, &$config)
    {
        parent::PEAR_Command_Common($ui, $config);
    }

    // }}}

    // {{{ _displayValidationResults()

    function _displayValidationResults($err, $warn, $strict = false)
    {
        foreach ($err as $e) {
            $this->ui->displayLine("Error: $e");
        }
        foreach ($warn as $w) {
            $this->ui->displayLine("Warning: $w");
        }
        $this->ui->displayLine(sprintf('Validation: %d error(s), %d warning(s)',
                                       sizeof($err), sizeof($warn)));
        if ($strict && sizeof($err) > 0) {
            $this->ui->displayLine("Fix these errors and try again.");
            return false;
        }
        return true;
    }

    // }}}
    // {{{ getCommands()

    /**
     * Return a list of all the commands defined by this class.
     * @return array list of commands
     * @access public
     */
    function getCommands()
    {
        return array('package',
                     'package-info',
                     'package-list',
                     'package-validate',
                     'cvstag');
    }

    // }}}
    // {{{ getOptions()

    function getOptions()
    {
        return array('Z', 'n' /*, 'f', 'd', 'q', 'Q'*/);
    }

    // }}}
    // {{{ getHelp()

    function getHelp($command)
    {
        switch ($command) {
            case 'package':
                return array('[<package.xml>]',
                             'Creates a PEAR package from its description file (usually '.
                             'named as package.xml)');
            case 'package-list':
                return array('<pear package>',
                             'List the contents of a PEAR package');
            case 'packge-info':
                return array('<pear package>',
                             'Shows information about a PEAR package');
            case 'package-validate':
                return array('<package.(tgz|tar|xml)>',
                             'Verifies a package or description file');
            case 'cvstag':
                return array('<package.xml>',
                             'Runs "cvs tag" on files contained in a release');
        }
    }

    // }}}
    // {{{ run()

    /**
     * Execute the command.
     *
     * @param string command name
     *
     * @param array option_name => value
     *
     * @param array list of additional parameters
     *
     * @return bool TRUE on success, FALSE for unknown commands, or
     * a PEAR error on failure
     *
     * @access public
     */
    function run($command, $options, $params)
    {
        $failmsg = '';
        switch ($command) {
            // {{{ package

            case 'package': {
                $pkginfofile = isset($params[0]) ? $params[0] : 'package.xml';
                ob_start();
                $packager =& new PEAR_Packager($this->config->get('php_dir'),
                                               $this->config->get('ext_dir'),
                                               $this->config->get('doc_dir'));
                $packager->debug = $this->config->get('verbose');
                $err = $warn = array();
                $packager->validatePackageInfo($pkginfofile, $err, $warn);
                if (!$this->_displayValidationResults($err, $warn, true)) {
                    break;
                }
                $compress = empty($options['Z']) ? true : false;
                $result = $packager->Package($pkginfofile, $compress);
                $output = ob_get_contents();
                ob_end_clean();
                $lines = explode("\n", $output);
                foreach ($lines as $line) {
                    $this->ui->displayLine($line);
                }
                if (PEAR::isError($result)) {
                    $this->ui->displayLine("Package failed: ".$result->getMessage());
                }
                break;
            }

            // }}}
            // {{{ package-list

            case 'package-list': {
                // $params[0] -> the PEAR package to list its contents
                if (sizeof($params) != 1) {
                    $failmsg = "Command package-list requires a valid PEAR package filename ".
                               " as the first argument. Try the command \"help package-list\"";
                    break;
                }
                $obj = new PEAR_Common();

                if (PEAR::isError($info = $obj->infoFromTgzFile($params[0]))) {
                    return $info;
                }
                $list =$info['filelist'];
                $caption = 'Contents of ' . basename($params[0]);
                $this->ui->startTable(array('caption' => $caption,
                                            'border' => true));
                $this->ui->tableRow(array('Package Files', 'Install Destination'),
                                    array('bold' => true));
                foreach ($list as $file => $att) {
                    if (isset($att['baseinstalldir'])) {
                        $dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR .
                                $file;
                    } else {
                        $dest = $file;
                    }
                    switch ($att['role']) {
                        case 'test':
                            $dest = '-- will not be installed --'; break;
                        case 'doc':
                            $dest = $this->config->get('doc_dir') . DIRECTORY_SEPARATOR .
                                    $dest;
                            break;
                        case 'php':
                        default:
                            $dest = $this->config->get('php_dir') . DIRECTORY_SEPARATOR .
                                    $dest;
                    }
                    $dest = preg_replace('!/+!', '/', $dest);
                    $file = preg_replace('!/+!', '/', $file);
                    $opts = array(0 => array('wrap' => 23),
{'fraction_non_alphanumeric': 0.1798036274376108, 'fraction_numerical': 0.003272876039819992, 'mean_word_length': 1.082197614991482, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 106, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 27, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2064903', 'n_tokens_mistral': 3689, 'n_tokens_neox': 3509, 'n_words': 854}