📄 package.php
字号:
$this->output .= rtrim($line)."\n"; } pclose($fp); } $this->ui->outputData($this->output, $_cmd); return true; } // }}} // {{{ doCvsDiff() function doCvsDiff($command, $options, $params) { $this->output = ''; if (sizeof($params) < 1) { $help = $this->getHelp($command); return $this->raiseError("$command: missing parameter: $help[0]"); } $obj = new PEAR_Common; $info = $obj->infoFromDescriptionFile($params[0]); if (PEAR::isError($info)) { return $this->raiseError($info); } $files = array_keys($info['filelist']); $cmd = "cvs"; if (isset($options['quiet'])) { $cmd .= ' -q'; unset($options['quiet']); } if (isset($options['reallyquiet'])) { $cmd .= ' -Q'; unset($options['reallyquiet']); } if (isset($options['release'])) { $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $options['release']); $cvstag = "RELEASE_$cvsversion"; $options['revision'] = $cvstag; unset($options['release']); } $execute = true; if (isset($options['dry-run'])) { $execute = false; unset($options['dry-run']); } $cmd .= ' diff'; // the rest of the options are passed right on to "cvs diff" foreach ($options as $option => $optarg) { $arg = @$this->commands[$command]['options'][$option]['arg']; $short = @$this->commands[$command]['options'][$option]['shortopt']; $cmd .= $short ? " -$short" : " --$option"; if ($arg && $optarg) { $cmd .= ($short ? '' : '=') . escapeshellarg($optarg); } } foreach ($files as $file) { $cmd .= ' ' . escapeshellarg($file); } if ($this->config->get('verbose') > 1) { $this->output .= "+ $cmd\n"; } if ($execute) { $fp = popen($cmd, "r"); while ($line = fgets($fp, 1024)) { $this->output .= rtrim($line)."\n"; } pclose($fp); } $this->ui->outputData($this->output, $command); return true; } // }}} // {{{ doRunTests() function doRunTests($command, $options, $params) { $cwd = getcwd(); $php = $this->config->get('php_bin'); putenv("TEST_PHP_EXECUTABLE=$php"); // all core PEAR tests use this constant to determine whether they should be run or not putenv("PHP_PEAR_RUNTESTS=1"); $ip = ini_get("include_path"); $ps = OS_WINDOWS ? ';' : ':'; $run_tests = $rtsts = $this->config->get('php_dir') . DIRECTORY_SEPARATOR . 'run-tests.php'; if (!file_exists($run_tests)) { $run_tests = PEAR_INSTALL_DIR . DIRECTORY_SEPARATOR . 'run-tests.php'; if (!file_exists($run_tests)) { return $this->raiseError("No run-tests.php file found. Please copy this ". "file from the sources of your PHP distribution to $rtsts"); } } if (OS_WINDOWS) { // note, this requires a slightly modified version of run-tests.php // for some setups // unofficial download location is in the pear-dev archives $argv = $params; array_unshift($argv, $run_tests); $argc = count($argv); include $run_tests; } else { $plist = implode(' ', $params); $cmd = "$php -d include_path=$cwd$ps$ip -f $run_tests -- $plist"; system($cmd); } return true; } // }}} // {{{ doPackageDependencies() function doPackageDependencies($command, $options, $params) { // $params[0] -> the PEAR package to list its information if (sizeof($params) != 1) { return $this->raiseError("bad parameter(s), try \"help $command\""); } $obj = new PEAR_Common(); if (PEAR::isError($info = $obj->infoFromAny($params[0]))) { return $this->raiseError($info); } if (is_array($info['release_deps'])) { $data = array( 'caption' => 'Dependencies for ' . $info['package'], 'border' => true, 'headline' => array("Type", "Name", "Relation", "Version"), ); foreach ($info['release_deps'] as $d) { if (isset($this->_deps_rel_trans[$d['rel']])) { $rel = $this->_deps_rel_trans[$d['rel']]; } else { $rel = $d['rel']; } if (isset($this->_deps_type_trans[$d['type']])) { $type = ucfirst($this->_deps_type_trans[$d['type']]); } else { $type = $d['type']; } if (isset($d['name'])) { $name = $d['name']; } else { $name = ''; } if (isset($d['version'])) { $version = $d['version']; } else { $version = ''; } $data['data'][] = array($type, $name, $rel, $version); } $this->ui->outputData($data, $command); return true; } // Fallback $this->ui->outputData("This package does not have any dependencies.", $command); } // }}} // {{{ doSign() function doSign($command, $options, $params) { // should move most of this code into PEAR_Packager // so it'll be easy to implement "pear package --sign" if (sizeof($params) != 1) { return $this->raiseError("bad parameter(s), try \"help $command\""); } if (!file_exists($params[0])) { return $this->raiseError("file does not exist: $params[0]"); } $obj = new PEAR_Common; $info = $obj->infoFromTgzFile($params[0]); if (PEAR::isError($info)) { return $this->raiseError($info); } include_once "Archive/Tar.php"; include_once "System.php"; $tar = new Archive_Tar($params[0]); $tmpdir = System::mktemp('-d pearsign'); if (!$tar->extractList('package.xml package.sig', $tmpdir)) { return $this->raiseError("failed to extract tar file"); } if (file_exists("$tmpdir/package.sig")) { return $this->raiseError("package already signed"); } @unlink("$tmpdir/package.sig"); $input = $this->ui->userDialog($command, array('GnuPG Passphrase'), array('password')); $gpg = popen("gpg --batch --passphrase-fd 0 --armor --detach-sign --output $tmpdir/package.sig $tmpdir/package.xml 2>/dev/null", "w"); if (!$gpg) { return $this->raiseError("gpg command failed"); } fwrite($gpg, "$input[0]\r"); if (pclose($gpg) || !file_exists("$tmpdir/package.sig")) { return $this->raiseError("gpg sign failed"); } $tar->addModify("$tmpdir/package.sig", '', $tmpdir); return true; } // }}} // {{{ doMakeRPM() /* (cox) TODO: - Fill the rpm dependencies in the template file. IDEAS: - Instead of mapping the role to rpm vars, perhaps it's better to use directly the pear cmd to install the files by itself in %postrun so: pear -d php_dir=%{_libdir}/php/pear -d test_dir=.. <package> */ function doMakeRPM($command, $options, $params) { if (sizeof($params) != 1) { return $this->raiseError("bad parameter(s), try \"help $command\""); } if (!file_exists($params[0])) { return $this->raiseError("file does not exist: $params[0]"); } include_once "Archive/Tar.php"; include_once "PEAR/Installer.php"; include_once "System.php"; $tar = new Archive_Tar($params[0]); $tmpdir = System::mktemp('-d pear2rpm'); $instroot = System::mktemp('-d pear2rpm'); $tmp = $this->config->get('verbose'); $this->config->set('verbose', 0); $installer = new PEAR_Installer($this->ui); $info = $installer->install($params[0], array('installroot' => $instroot, 'nodeps' => true)); $pkgdir = "$info[package]-$info[version]"; $info['rpm_xml_dir'] = '/var/lib/pear'; $this->config->set('verbose', $tmp); if (!$tar->extractList("package.xml", $tmpdir, $pkgdir)) { return $this->raiseError("failed to extract $params[0]"); } if (!file_exists("$tmpdir/package.xml")) { return $this->raiseError("no package.xml found in $params[0]"); } if (isset($options['spec-template'])) { $spec_template = $options['spec-template']; } else { $spec_template = $this->config->get('data_dir') . '/PEAR/template.spec'; } if (isset($options['rpm-pkgname'])) { $rpm_pkgname_format = $options['rpm-pkgname']; } else { $rpm_pkgname_format = "PEAR::%s"; } $info['extra_headers'] = ''; $info['doc_files'] = ''; $info['files'] = ''; $info['rpm_package'] = sprintf($rpm_pkgname_format, $info['package']); $srcfiles = 0; foreach ($info['filelist'] as $name => $attr) { if ($attr['role'] == 'doc') { $info['doc_files'] .= " $name"; // Map role to the rpm vars } else { $c_prefix = '%{_libdir}/php/pear'; switch ($attr['role']) { case 'php': $prefix = $c_prefix; break; case 'ext': $prefix = '%{_libdir}/php'; break; // XXX good place? case 'src': $srcfiles++; $prefix = '%{_includedir}/php'; break; // XXX good place? case 'test': $prefix = "$c_prefix/tests/" . $info['package']; break; case 'data': $prefix = "$c_prefix/data/" . $info['package']; break; case 'script': $prefix = '%{_bindir}'; break; } $info['files'] .= "$prefix/$name\n"; } } if ($srcfiles > 0) { include_once "OS/Guess.php"; $os = new OS_Guess; $arch = $os->getCpu(); } else { $arch = 'noarch'; } $cfg = array('master_server', 'php_dir', 'ext_dir', 'doc_dir', 'bin_dir', 'data_dir', 'test_dir'); foreach ($cfg as $k) { $info[$k] = $this->config->get($k); } $info['arch'] = $arch; $fp = @fopen($spec_template, "r"); if (!$fp) { return $this->raiseError("could not open RPM spec file template $spec_template: $php_errormsg"); } $spec_contents = preg_replace('/@([a-z0-9_-]+)@/e', '$info["\1"]', fread($fp, filesize($spec_template))); fclose($fp); $spec_file = "$info[rpm_package]-$info[version].spec"; $wp = fopen($spec_file, "wb"); if (!$wp) { return $this->raiseError("could not write RPM spec file $spec_file: $php_errormsg"); } fwrite($wp, $spec_contents); fclose($wp); $this->ui->outputData("Wrote RPM spec file $spec_file", $command); return true; } // }}}}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -