Beispiel #1
0
function _pear_run_command($config, $command, $opts, $params)
{
    ob_start('_pear_echo_message', 2);
    $cmd = PEAR_Command::factory($command, $config);
    $ret = ob_get_clean();
    if (PEAR::isError($cmd)) {
        throw new Exception($cmd->getMessage());
    }
    ob_start('_pear_echo_message', 2);
    $ok = $cmd->run($command, $opts, $params);
    $ret .= ob_get_clean();
    $ret = trim($ret);
    return PEAR::isError($ok) ? array($ret, $ok->getMessage()) : array($ret, null);
}
Beispiel #2
0
 /**
  * retrieves a list of avaible Packages from master server
  * and downloads them
  *
  * @access public
  * @param string $command the command
  * @param array $options the command options before the command
  * @param array $params the stuff after the command name
  * @return bool true if succesful
  * @throw PEAR_Error 
  */
 function doDownloadAll($command, $options, $params)
 {
     $this->config->set("php_dir", ".");
     $remote =& new PEAR_Remote($this->config);
     $remoteInfo = $remote->call("package.listAll");
     if (PEAR::isError($remoteInfo)) {
         return $remoteInfo;
     }
     $cmd =& PEAR_Command::factory("download", $this->config);
     if (PEAR::isError($cmd)) {
         return $cmd;
     }
     foreach ($remoteInfo as $pkgn => $pkg) {
         // error handling not neccesary, because
         // already done by the download command
         $cmd->run("download", array(), array($pkgn));
     }
     return true;
 }
Beispiel #3
0
 /**
  * do the install
  *
  * @access public
  * @param string $command the command
  * @param array $options the command options before the command
  * @param array $params the stuff after the command name
  * @return bool true if succesful
  * @throw PEAR_Error 
  */
 function doInstallAll($command, $options, $params)
 {
     $remote =& new PEAR_Remote($this->config);
     $remoteInfo = $remote->call("package.listAll");
     if (PEAR::isError($remoteInfo)) {
         return $remoteInfo;
     }
     $cmd =& PEAR_Command::factory("install", $this->config);
     if (PEAR::isError($cmd)) {
         return $cmd;
     }
     foreach ($remoteInfo as $pkgn => $pkg) {
         // error handling not neccesary, because
         // already done by the install command
         $options = array("nodeps" => true, "force" => true, "nobuild" => $options['nobuild']);
         $cmd->run("install", $options, array($pkgn));
     }
     return true;
 }
Beispiel #4
0
 public function invoke()
 {
     $params = func_get_args();
     switch (func_num_args()) {
         case 1:
             list($command) = $params;
             $options = array();
             $args = array();
             break;
         case 2:
             list($command, $options) = $params;
             if (is_string($options)) {
                 $args = array($options);
                 $options = array();
             } else {
                 $args = array();
             }
             break;
         case 3:
             list($command, $options, $args) = $params;
             if (is_string($args)) {
                 if (is_string($options)) {
                     $args = array($options, $args);
                     $options = array();
                 } else {
                     $args = array($args);
                 }
             }
             break;
         default:
             $command = array_shift($params);
             if (is_array($params[0])) {
                 $options = array_shift($params);
             }
             $args = $params;
     }
     $cmd = \PEAR_Command::factory($command, $this->config);
     $cmd->run($command, $options, $args);
 }
}
if ($fetype == 'Gtk' || $fetype == 'Gtk2') {
    if (!$config->validConfiguration()) {
        PEAR::raiseError('CRITICAL ERROR: no existing valid configuration files found in files ' . "'{$pear_user_config}' or '{$pear_system_config}', please copy an existing configuration" . 'file to one of these locations, or use the -c and -s options to create one');
    }
    Gtk::main();
} else {
    do {
        if ($command == 'help') {
            usage(null, @$options[1][1]);
        }
        if (!$config->validConfiguration()) {
            PEAR::raiseError('CRITICAL ERROR: no existing valid configuration files found in files ' . "'{$pear_user_config}' or '{$pear_system_config}', please copy an existing configuration" . 'file to one of these locations, or use the -c and -s options to create one');
        }
        PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
        $cmd = PEAR_Command::factory($command, $config);
        PEAR::popErrorHandling();
        if (PEAR::isError($cmd)) {
            usage(null, @$options[1][0]);
        }
        $short_args = $long_args = null;
        PEAR_Command::getGetoptArgs($command, $short_args, $long_args);
        if (in_array('getopt2', get_class_methods('Console_Getopt'))) {
            array_shift($options[1]);
            $tmp = Console_Getopt::getopt2($options[1], $short_args, $long_args);
        } else {
            $tmp = Console_Getopt::getopt($options[1], $short_args, $long_args);
        }
        if (PEAR::isError($tmp)) {
            break;
        }
Beispiel #6
0
 /**
  * For unit-testing
  */
 function &factory($a)
 {
     $a =& PEAR_Command::factory($a, $this->config);
     return $a;
 }
Beispiel #7
0
}
$config->set('download_dir', $temp_dir . '/download');
$config->set('temp_dir', $temp_dir);
$config->store();
$registry = new PEAR_Registry($php_dir);
PEAR_Command::setFrontendType('CLI');
PEAR::staticPushErrorHandling(PEAR_ERROR_DIE);
//fail silently
$ch_cmd =& PEAR_Command::factory('update-channels', $config);
$ch_cmd->run('update-channels', $options, array());
PEAR::staticPopErrorHandling();
// reset error handling
unset($ch_cmd);
print "\n" . 'Installing selected packages..................' . "\n";
displayHTMLProgress($progress = 45);
$install =& PEAR_Command::factory('install', $config);
foreach ($to_install as $pkg) {
    $pkg_basename = substr($pkg, 0, strpos($pkg, '-'));
    if (in_array($pkg, $installer_packages)) {
        $options = array('nodeps' => true);
    } else {
        $options = array('onlyreqdeps' => true);
    }
    if ($registry->packageExists($pkg) || $registry->packageExists($pkg_basename)) {
        print str_pad("Package: {$pkg}", max(50, 9 + strlen($pkg) + 4), '.') . ' already installed ... ok' . "\n";
        displayHTMLProgress($progress += round(50 / count($to_install)));
        continue;
    }
    $pkg_basename = substr($pkg, 0, strpos($pkg, '-'));
    if (in_array($pkg_basename, $bootstrap_pkgs)) {
        print str_pad("Installing bootstrap package: {$pkg_basename}", max(50, 30 + strlen($pkg_basename) + 4), '.') . "...";
Beispiel #8
0
 public function run($command, $options = array(), $params = array())
 {
     @set_time_limit(0);
     @ini_set('memory_limit', '256M');
     if (empty($this->_cmdCache[$command])) {
         $cmd = PEAR_Command::factory($command, $this->getConfig());
         if ($cmd instanceof PEAR_Error) {
             return $cmd;
         }
         $this->_cmdCache[$command] = $cmd;
     } else {
         $cmd = $this->_cmdCache[$command];
     }
     #$cmd = PEAR_Command::factory($command, $this->getConfig());
     $result = $cmd->run($command, $options, $params);
     return $result;
 }
 /**
  * Initializes the
  * @param unknown_type $command
  * @param array $opts
  * @param array $params
  * @return unknown_type
  */
 protected function _command($command, array $opts = array(), array $params = array())
 {
     // initialize the command
     $cmd = PEAR_Command::factory($command, $this->_config);
     if (PEAR::isError($cmd)) {
         throw new Exception($cmd->getMessage());
     }
     // run the command
     return $cmd->run($command, $opts, $params);
 }
Beispiel #10
0
 /**
  *  run PEAR_Command.
  *
  *  @param  string  $command    command name
  *  @param  array   $options    options
  *  @param  array   $params     parameters
  *  @return true|Ethna_Error
  *  @access private 
  *  @see PEAR_Command_Common::run, etc.
  */
 protected function _run($command, $options, $params)
 {
     if ($this->config === null) {
         return Ethna::raiseError('configuration not initialized.');
     }
     $true = true;
     $cmd = PEAR_Command::factory($command, $this->config);
     if (PEAR::isError($cmd)) {
         return $cmd;
     }
     // pear command options
     if (is_array($this->_pearopt) && count($this->_pearopt) > 0) {
         $pearopts = $this->_getPearOpt($cmd, $command, $this->_pearopt);
         $options = array_merge($pearopts, $options);
     }
     $ret = $cmd->run($command, $options, $params);
     if (PEAR::isError($ret)) {
         return $ret;
     }
     return $true;
 }
Beispiel #11
0
 function doInstall()
 {
     print "Beginning install...\n";
     // finish php_bin config
     if (OS_WINDOWS) {
         $this->php_bin .= '\\php.exe';
     } else {
         $this->php_bin .= '/php';
     }
     $this->PEARConfig =& PEAR_Config::singleton($this->pear_conf, $this->pear_conf);
     $this->PEARConfig->set('preferred_state', 'stable');
     foreach ($this->config as $var) {
         if ($var == 'pear_conf' || $var == 'prefix') {
             continue;
         }
         $this->PEARConfig->set($var, $this->{$var});
     }
     $this->PEARConfig->store();
     //       $this->PEARConfig->set('verbose', 6);
     print "Configuration written to {$this->pear_conf}...\n";
     $this->registry =& $this->PEARConfig->getRegistry();
     print "Initialized registry...\n";
     $install =& PEAR_Command::factory('install', $this->PEARConfig);
     print "Preparing to install...\n";
     $options = array('nodeps' => true, 'force' => true, 'upgrade' => true);
     foreach ($this->tarball as $pkg => $src) {
         print "installing {$src}...\n";
     }
     $install->run('install', $options, array_values($this->tarball));
 }
Beispiel #12
0
 public function run($argv)
 {
     //        $old = error_reporting(0);
     if (!defined('PEAR_RUNTYPE')) {
         define('PEAR_RUNTYPE', 'pear');
     }
     if (!defined('PEAR_IGNORE_BACKTRACE')) {
         define('PEAR_IGNORE_BACKTRACE', 1);
     }
     @ini_set('allow_url_fopen', true);
     if (!ini_get('safe_mode')) {
         @set_time_limit(0);
     }
     ob_implicit_flush(true);
     @ini_set('track_errors', true);
     @ini_set('html_errors', false);
     @ini_set('magic_quotes_runtime', false);
     $pear_package_version = "1.9.0";
     PEAR_Command::setFrontendType('CLI');
     $this->_allCommands = PEAR_Command::getCommands();
     $progname = PEAR_RUNTYPE;
     array_shift($argv);
     $options = Console_Getopt::getopt2($argv, "c:C:d:D:Gh?sSqu:vV");
     if (PEAR::isError($options)) {
         $this->usage($options);
     }
     $opts = $options[0];
     $store_user_config = false;
     $verbose = 1;
     $config = PEAR_Config::singleton($this->_pearConfigFile, "#no#system#config#");
     if ($config instanceof PEAR_Error) {
         echo $config, "\n";
         exit(1);
     }
     $config->set('verbose', 1);
     //        $config->set('verbose', -1); // supress all kind of annoying stuff.
     $ui = PEAR_Command::getFrontendObject();
     $ui->setConfig($config);
     PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, "throwException"));
     if (ini_get('safe_mode')) {
         $ui->outputData('WARNING: running in safe mode requires that all files created ' . 'be the same uid as the current script. PHP reports this script is uid: ' . @getmyuid() . ', and current user is: ' . @get_current_user());
     }
     $verbose = $config->get("verbose");
     $cmdopts = array();
     foreach ($opts as $opt) {
         $param = !empty($opt[1]) ? $opt[1] : true;
         switch ($opt[0]) {
             case 'd':
                 if ($param === true) {
                     die('Invalid usage of "-d" option, expected -d config_value=value, ' . 'received "-d"' . "\n");
                 }
                 $possible = explode('=', $param);
                 if (count($possible) != 2) {
                     die('Invalid usage of "-d" option, expected -d config_value=value, received "' . $param . '"' . "\n");
                 }
                 list($key, $value) = explode('=', $param);
                 $config->set($key, $value, 'user');
                 break;
             case 'D':
                 if ($param === true) {
                     die('Invalid usage of "-d" option, expected -d config_value=value, ' . 'received "-d"' . "\n");
                 }
                 $possible = explode('=', $param);
                 if (count($possible) != 2) {
                     die('Invalid usage of "-d" option, expected -d config_value=value, received "' . $param . '"' . "\n");
                 }
                 list($key, $value) = explode('=', $param);
                 $config->set($key, $value, 'system');
                 break;
             case 's':
                 $store_user_config = true;
                 break;
             case 'u':
                 $config->remove($param, 'user');
                 break;
             case 'v':
                 $config->set('verbose', $config->get('verbose') + 1);
                 break;
             case 'q':
                 $config->set('verbose', $config->get('verbose') - 1);
                 break;
             case 'V':
                 $this->usage(null, 'version');
             case 'c':
             case 'C':
                 break;
             default:
                 // all non pear params goes to the command
                 $cmdopts[$opt[0]] = $param;
                 break;
         }
     }
     if ($store_user_config) {
         $config->store('user');
     }
     $command = isset($options[1][0]) ? $options[1][0] : null;
     if (empty($command) && $store_user_config) {
         exit;
     }
     if ($command == 'help') {
         $this->usage(null, @$options[1][1]);
     }
     if (!$config->validConfiguration()) {
         PEAR::raiseError('CRITICAL ERROR: no existing valid configuration files found in files found');
     }
     PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
     $cmd = PEAR_Command::factory($command, $config);
     PEAR::popErrorHandling();
     if (PEAR::isError($cmd)) {
         $this->usage(null, @$options[1][0]);
     }
     $short_args = $long_args = null;
     PEAR_Command::getGetoptArgs($command, $short_args, $long_args);
     array_shift($options[1]);
     $tmp = Console_Getopt::getopt2($options[1], $short_args, $long_args);
     if (PEAR::isError($tmp)) {
         break;
     }
     list($tmpopt, $params) = $tmp;
     $opts = array();
     foreach ($tmpopt as $foo => $tmp2) {
         list($opt, $value) = $tmp2;
         if ($value === null) {
             $value = true;
             // options without args
         }
         if (strlen($opt) == 1) {
             $cmdoptions = $cmd->getOptions($command);
             foreach ($cmdoptions as $o => $d) {
                 if (isset($d['shortopt']) && $d['shortopt'] == $opt) {
                     $opts[$o] = $value;
                 }
             }
         } else {
             if (substr($opt, 0, 2) == '--') {
                 $opts[substr($opt, 2)] = $value;
             }
         }
     }
     $ok = $cmd->run($command, $opts, $params);
     if ($ok === false) {
         PEAR::raiseError("unknown command `{$command}'");
     }
     //        error_reporting($old);
 }
Beispiel #13
0
 private function nativePearInstall($package, $channel)
 {
     if (!class_exists('PEAR_Command')) {
         @(include 'PEAR/command.php');
         // loads frontend, among other things
         if (!class_exists('PEAR_Command')) {
             throw new pakeException('PEAR subsystem is unavailable (not in include_path?)');
         }
     }
     $front = PEAR_Frontend::singleton('PEAR_Frontend_CLI');
     $cfg = PEAR_Config::singleton();
     $cmd = PEAR_Command::factory('install', $cfg);
     ob_start();
     $result = $cmd->doInstall('install', array(), array($channel . '/' . $package));
     ob_end_clean();
     // we don't need output
     if ($result instanceof PEAR_Error) {
         throw new pakeException($result->getMessage());
     }
 }
Beispiel #14
0
 /**
  * @access private
  */
 function &_makePackage($setting, $workdir)
 {
     // package.xml を作る
     $pkgconfig = array('packagedirectory' => $workdir, 'outputdirectory' => $workdir, 'ignore' => array('CVS/', '.cvsignore', '.svn/', 'package.xml', '*.ini', $setting['pkgname'] . '-*.tgz'), 'filelistgenerator' => 'file', 'changelogoldtonew' => false);
     $packagexml = new PEAR_PackageFileManager2();
     $pkgconfig = array_merge($pkgconfig, $setting['config']);
     $packagexml->setOptions($pkgconfig);
     $packagexml->setPackage($setting['pkgname']);
     $packagexml->setSummary($setting['summary']);
     $packagexml->setNotes($setting['notes']);
     $packagexml->setDescription($setting['description']);
     $packagexml->setChannel($setting['channel']);
     $packagexml->setAPIVersion($setting['version']);
     $packagexml->setReleaseVersion($setting['version']);
     $packagexml->setReleaseStability($setting['state']);
     $packagexml->setAPIStability($setting['state']);
     $packagexml->setPackageType('php');
     foreach ($setting['maintainers'] as $m) {
         $packagexml->addMaintainer($m['role'], $m['user'], $m['name'], $m['email'], $m['active']);
     }
     $packagexml->setLicense($setting['license']['name'], $setting['license']['uri']);
     $packagexml->addRole('css', 'php');
     $packagexml->addRole('tpl', 'php');
     $packagexml->addRole('ethna', 'php');
     $packagexml->addRole('sh', 'script');
     $packagexml->addRole('bat', 'script');
     $packagexml->setPhpDep('4.3.0');
     $packagexml->setPearinstallerDep('1.3.5');
     $packagexml->generateContents();
     foreach ($setting['callback'] as $method => $params) {
         $r = call_user_func_array(array(&$packagexml, $method), $params);
     }
     $r = $packagexml->writePackageFile();
     if (PEAR::isError($r)) {
         return Ethna::raiseError($r->getMessage, $r->getCode());
     }
     //  finally make package
     PEAR_Command::setFrontendType('CLI');
     $ui = PEAR_Command::getFrontendObject();
     $config = PEAR_Config::singleton();
     $ui->setConfig($config);
     PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array(&$ui, 'displayFatalError'));
     $cmd = PEAR_Command::factory('package', $config);
     if (PEAR::isError($cmd)) {
         return Ethna::raiseError($cmd->getMessage, $cmd->getCode());
     }
     $r = $cmd->run('package', array(), array("{$workdir}/package.xml"));
     if (PEAR::isError($r)) {
         return Ethna::raiseError($r->getMessage, $r->getCode());
     }
 }
 private static function nativePearUpgrade($package, $channel)
 {
     pake_echo_action('pear', 'upgrading ' . $channel . '/' . $package);
     self::initPearClasses();
     $front = PEAR_Frontend::singleton('PEAR_Frontend_CLI');
     $cfg = PEAR_Config::singleton();
     $cmd = PEAR_Command::factory('upgrade', $cfg);
     ob_start();
     $result = $cmd->doInstall('upgrade', array(), array($channel . '/' . $package));
     ob_end_clean();
     // we don't need output
     if ($result instanceof PEAR_Error) {
         throw new pakeException($result->getMessage());
     }
 }
Beispiel #16
0
 /**
  * Updates the source for the package.
  *
  * We have to update required dependencies automatically to make sure that
  * everything still works properly.
  *
  * It is the developers responsibility to make sure the user is given the
  * option to update any optional dependencies if needed. This can be done
  * by creating a new instance of PEAR_PackageUpdate for the optional
  * dependency.
  *
  * @access public
  * @return boolean true if the update was successful.
  * @since  0.4.0a1
  * @throws PEAR_PACKAGEUPDATE_ERROR_NOTINSTALLED
  */
 function update()
 {
     // Create a config object.
     $config = new PEAR_Config();
     // Change the verbosity but keep track of the value to reset it just in
     // case this does something permanent.
     $verbose = $config->get('verbose');
     $config->set('verbose', 0);
     // Create a command object to do the upgrade.
     // If the current version is 0.0.0 don't upgrade. That would be a
     // sneaky way for devs to install packages without the use knowing.
     if ($this->instVersion == '0.0.0') {
         $this->pushError(PEAR_PACKAGEUPDATE_ERROR_NOTINSTALLED, NULL, array('packagename' => $this->packageName));
         return false;
     }
     require_once 'PEAR/Command.php';
     $upgrade = PEAR_Command::factory('upgrade', $config);
     // Try to upgrade the application.
     $channelPackage = $this->channel . '/' . $this->packageName;
     $result = $upgrade->doInstall('upgrade', array('onlyreqdeps' => true), array($channelPackage));
     // Reset the verbose level just to be safe.
     $config->set('verbose', $verbose);
     // Check for errors.
     if (PEAR::isError($result)) {
         $this->pushError($result);
         return false;
     } else {
         return true;
     }
 }