/usr/share/php/PEAR/Command/Package.php is in php-pear 1:1.10.1+submodules+notgz-9+deb9u1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 | <?php
/**
* PEAR_Command_Package (package, package-validate, cvsdiff, cvstag, package-dependencies,
* sign, makerpm, convert commands)
*
* PHP versions 4 and 5
*
* @category pear
* @package PEAR
* @author Stig Bakken <ssb@php.net>
* @author Martin Jansen <mj@php.net>
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
/**
* base class
*/
require_once 'PEAR/Command/Common.php';
/**
* PEAR commands for login/logout
*
* @category pear
* @package PEAR
* @author Stig Bakken <ssb@php.net>
* @author Martin Jansen <mj@php.net>
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
class PEAR_Command_Package extends PEAR_Command_Common
{
var $commands = array(
'package' => array(
'summary' => 'Build Package',
'function' => 'doPackage',
'shortcut' => 'p',
'options' => array(
'nocompress' => array(
'shortopt' => 'Z',
'doc' => 'Do not gzip the package file'
),
'showname' => array(
'shortopt' => 'n',
'doc' => 'Print the name of the packaged file.',
),
),
'doc' => '[descfile] [descfile2]
Creates a PEAR package from its description file (usually called
package.xml). If a second packagefile is passed in, then
the packager will check to make sure that one is a package.xml
version 1.0, and the other is a package.xml version 2.0. The
package.xml version 1.0 will be saved as "package.xml" in the archive,
and the other as "package2.xml" in the archive"
'
),
'package-validate' => array(
'summary' => 'Validate Package Consistency',
'function' => 'doPackageValidate',
'shortcut' => 'pv',
'options' => array(),
'doc' => '
',
),
'cvsdiff' => array(
'summary' => 'Run a "cvs diff" for all files in a package',
'function' => 'doCvsDiff',
'shortcut' => 'cd',
'options' => array(
'quiet' => array(
'shortopt' => 'q',
'doc' => 'Be quiet',
),
'reallyquiet' => array(
'shortopt' => 'Q',
'doc' => 'Be really quiet',
),
'date' => array(
'shortopt' => 'D',
'doc' => 'Diff against revision of DATE',
'arg' => 'DATE',
),
'release' => array(
'shortopt' => 'R',
'doc' => 'Diff against tag for package release REL',
'arg' => 'REL',
),
'revision' => array(
'shortopt' => 'r',
'doc' => 'Diff against revision REV',
'arg' => 'REV',
),
'context' => array(
'shortopt' => 'c',
'doc' => 'Generate context diff',
),
'unified' => array(
'shortopt' => 'u',
'doc' => 'Generate unified diff',
),
'ignore-case' => array(
'shortopt' => 'i',
'doc' => 'Ignore case, consider upper- and lower-case letters equivalent',
),
'ignore-whitespace' => array(
'shortopt' => 'b',
'doc' => 'Ignore changes in amount of white space',
),
'ignore-blank-lines' => array(
'shortopt' => 'B',
'doc' => 'Ignore changes that insert or delete blank lines',
),
'brief' => array(
'doc' => 'Report only whether the files differ, no details',
),
'dry-run' => array(
'shortopt' => 'n',
'doc' => 'Don\'t do anything, just pretend',
),
),
'doc' => '<package.xml>
Compares all the files in a package. Without any options, this
command will compare the current code with the last checked-in code.
Using the -r or -R option you may compare the current code with that
of a specific release.
',
),
'svntag' => array(
'summary' => 'Set SVN Release Tag',
'function' => 'doSvnTag',
'shortcut' => 'sv',
'options' => array(
'quiet' => array(
'shortopt' => 'q',
'doc' => 'Be quiet',
),
'slide' => array(
'shortopt' => 'F',
'doc' => 'Move (slide) tag if it exists',
),
'delete' => array(
'shortopt' => 'd',
'doc' => 'Remove tag',
),
'dry-run' => array(
'shortopt' => 'n',
'doc' => 'Don\'t do anything, just pretend',
),
),
'doc' => '<package.xml> [files...]
Sets a SVN tag on all files in a package. Use this command after you have
packaged a distribution tarball with the "package" command to tag what
revisions of what files were in that release. If need to fix something
after running svntag once, but before the tarball is released to the public,
use the "slide" option to move the release tag.
to include files (such as a second package.xml, or tests not included in the
release), pass them as additional parameters.
',
),
'cvstag' => array(
'summary' => 'Set CVS Release Tag',
'function' => 'doCvsTag',
'shortcut' => 'ct',
'options' => array(
'quiet' => array(
'shortopt' => 'q',
'doc' => 'Be quiet',
),
'reallyquiet' => array(
'shortopt' => 'Q',
'doc' => 'Be really quiet',
),
'slide' => array(
'shortopt' => 'F',
'doc' => 'Move (slide) tag if it exists',
),
'delete' => array(
'shortopt' => 'd',
'doc' => 'Remove tag',
),
'dry-run' => array(
'shortopt' => 'n',
'doc' => 'Don\'t do anything, just pretend',
),
),
'doc' => '<package.xml> [files...]
Sets a CVS tag on all files in a package. Use this command after you have
packaged a distribution tarball with the "package" command to tag what
revisions of what files were in that release. If need to fix something
after running cvstag once, but before the tarball is released to the public,
use the "slide" option to move the release tag.
to include files (such as a second package.xml, or tests not included in the
release), pass them as additional parameters.
',
),
'package-dependencies' => array(
'summary' => 'Show package dependencies',
'function' => 'doPackageDependencies',
'shortcut' => 'pd',
'options' => array(),
'doc' => '<package-file> or <package.xml> or <install-package-name>
List all dependencies the package has.
Can take a tgz / tar file, package.xml or a package name of an installed package.'
),
'sign' => array(
'summary' => 'Sign a package distribution file',
'function' => 'doSign',
'shortcut' => 'si',
'options' => array(
'verbose' => array(
'shortopt' => 'v',
'doc' => 'Display GnuPG output',
),
),
'doc' => '<package-file>
Signs a package distribution (.tar or .tgz) file with GnuPG.',
),
'makerpm' => array(
'summary' => 'Builds an RPM spec file from a PEAR package',
'function' => 'doMakeRPM',
'shortcut' => 'rpm',
'options' => array(
'spec-template' => array(
'shortopt' => 't',
'arg' => 'FILE',
'doc' => 'Use FILE as RPM spec file template'
),
'rpm-pkgname' => array(
'shortopt' => 'p',
'arg' => 'FORMAT',
'doc' => 'Use FORMAT as format string for RPM package name, %s is replaced
by the PEAR package name, defaults to "PEAR::%s".',
),
),
'doc' => '<package-file>
Creates an RPM .spec file for wrapping a PEAR package inside an RPM
package. Intended to be used from the SPECS directory, with the PEAR
package tarball in the SOURCES directory:
$ pear makerpm ../SOURCES/Net_Socket-1.0.tgz
Wrote RPM spec file PEAR::Net_Geo-1.0.spec
$ rpm -bb PEAR::Net_Socket-1.0.spec
...
Wrote: /usr/src/redhat/RPMS/i386/PEAR::Net_Socket-1.0-1.i386.rpm
',
),
'convert' => array(
'summary' => 'Convert a package.xml 1.0 to package.xml 2.0 format',
'function' => 'doConvert',
'shortcut' => 'c2',
'options' => array(
'flat' => array(
'shortopt' => 'f',
'doc' => 'do not beautify the filelist.',
),
),
'doc' => '[descfile] [descfile2]
Converts a package.xml in 1.0 format into a package.xml
in 2.0 format. The new file will be named package2.xml by default,
and package.xml will be used as the old file by default.
This is not the most intelligent conversion, and should only be
used for automated conversion or learning the format.
'
),
);
var $output;
/**
* PEAR_Command_Package constructor.
*
* @access public
*/
function __construct(&$ui, &$config)
{
parent::__construct($ui, $config);
}
function _displayValidationResults($err, $warn, $strict = false)
{
foreach ($err as $e) {
$this->output .= "Error: $e\n";
}
foreach ($warn as $w) {
$this->output .= "Warning: $w\n";
}
$this->output .= sprintf('Validation: %d error(s), %d warning(s)'."\n",
sizeof($err), sizeof($warn));
if ($strict && count($err) > 0) {
$this->output .= "Fix these errors and try again.";
return false;
}
return true;
}
function &getPackager()
{
if (!class_exists('PEAR_Packager')) {
require_once 'PEAR/Packager.php';
}
$a = new PEAR_Packager;
return $a;
}
function &getPackageFile($config, $debug = false)
{
if (!class_exists('PEAR_Common')) {
require_once 'PEAR/Common.php';
}
if (!class_exists('PEAR_PackageFile')) {
require_once 'PEAR/PackageFile.php';
}
$a = new PEAR_PackageFile($config, $debug);
$common = new PEAR_Common;
$common->ui = $this->ui;
$a->setLogger($common);
return $a;
}
function doPackage($command, $options, $params)
{
$this->output = '';
$pkginfofile = isset($params[0]) ? $params[0] : 'package.xml';
$pkg2 = isset($params[1]) ? $params[1] : null;
if (!$pkg2 && !isset($params[0]) && file_exists('package2.xml')) {
$pkg2 = 'package2.xml';
}
$packager = &$this->getPackager();
$compress = empty($options['nocompress']) ? true : false;
$result = $packager->package($pkginfofile, $compress, $pkg2);
if (PEAR::isError($result)) {
return $this->raiseError($result);
}
// Don't want output, only the package file name just created
if (isset($options['showname'])) {
$this->output = $result;
}
if ($this->output) {
$this->ui->outputData($this->output, $command);
}
return true;
}
function doPackageValidate($command, $options, $params)
{
$this->output = '';
if (count($params) < 1) {
$params[0] = 'package.xml';
}
$obj = &$this->getPackageFile($this->config, $this->_debug);
$obj->rawReturn();
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$info = $obj->fromTgzFile($params[0], PEAR_VALIDATE_NORMAL);
if (PEAR::isError($info)) {
$info = $obj->fromPackageFile($params[0], PEAR_VALIDATE_NORMAL);
} else {
$archive = $info->getArchiveFile();
$tar = new Archive_Tar($archive);
$tar->extract(dirname($info->getPackageFile()));
$info->setPackageFile(dirname($info->getPackageFile()) . DIRECTORY_SEPARATOR .
$info->getPackage() . '-' . $info->getVersion() . DIRECTORY_SEPARATOR .
basename($info->getPackageFile()));
}
PEAR::staticPopErrorHandling();
if (PEAR::isError($info)) {
return $this->raiseError($info);
}
$valid = false;
if ($info->getPackagexmlVersion() == '2.0') {
if ($valid = $info->validate(PEAR_VALIDATE_NORMAL)) {
$info->flattenFileList();
$valid = $info->validate(PEAR_VALIDATE_PACKAGING);
}
} else {
$valid = $info->validate(PEAR_VALIDATE_PACKAGING);
}
$err = $warn = array();
if ($errors = $info->getValidationWarnings()) {
foreach ($errors as $error) {
if ($error['level'] == 'warning') {
$warn[] = $error['message'];
} else {
$err[] = $error['message'];
}
}
}
$this->_displayValidationResults($err, $warn);
$this->ui->outputData($this->output, $command);
return true;
}
function doSvnTag($command, $options, $params)
{
$this->output = '';
$_cmd = $command;
if (count($params) < 1) {
$help = $this->getHelp($command);
return $this->raiseError("$command: missing parameter: $help[0]");
}
$packageFile = realpath($params[0]);
$dir = dirname($packageFile);
$dir = substr($dir, strrpos($dir, DIRECTORY_SEPARATOR) + 1);
$obj = &$this->getPackageFile($this->config, $this->_debug);
$info = $obj->fromAnyFile($packageFile, PEAR_VALIDATE_NORMAL);
if (PEAR::isError($info)) {
return $this->raiseError($info);
}
$err = $warn = array();
if (!$info->validate()) {
foreach ($info->getValidationWarnings() as $error) {
if ($error['level'] == 'warning') {
$warn[] = $error['message'];
} else {
$err[] = $error['message'];
}
}
}
if (!$this->_displayValidationResults($err, $warn, true)) {
$this->ui->outputData($this->output, $command);
return $this->raiseError('SVN tag failed');
}
$version = $info->getVersion();
$package = $info->getName();
$svntag = "$package-$version";
if (isset($options['delete'])) {
return $this->_svnRemoveTag($version, $package, $svntag, $packageFile, $options);
}
$path = $this->_svnFindPath($packageFile);
// Check if there are any modified files
$fp = popen('svn st --xml ' . dirname($packageFile), "r");
$out = '';
while ($line = fgets($fp, 1024)) {
$out .= rtrim($line)."\n";
}
pclose($fp);
if (!isset($options['quiet']) && strpos($out, 'item="modified"')) {
$params = array(array(
'name' => 'modified',
'type' => 'yesno',
'default' => 'no',
'prompt' => 'You have files in your SVN checkout (' . $path['from'] . ') that have been modified but not committed, do you still want to tag ' . $version . '?',
));
$answers = $this->ui->confirmDialog($params);
if (!in_array($answers['modified'], array('y', 'yes', 'on', '1'))) {
return true;
}
}
if (isset($options['slide'])) {
$this->_svnRemoveTag($version, $package, $svntag, $packageFile, $options);
}
// Check if tag already exists
$releaseTag = $path['local']['base'] . 'tags' . DIRECTORY_SEPARATOR . $svntag;
$existsCommand = 'svn ls ' . $path['base'] . 'tags/';
$fp = popen($existsCommand, "r");
$out = '';
while ($line = fgets($fp, 1024)) {
$out .= rtrim($line)."\n";
}
pclose($fp);
if (in_array($svntag . DIRECTORY_SEPARATOR, explode("\n", $out))) {
$this->ui->outputData($this->output, $command);
return $this->raiseError('SVN tag ' . $svntag . ' for ' . $package . ' already exists.');
} elseif (file_exists($path['local']['base'] . 'tags') === false) {
return $this->raiseError('Can not locate the tags directory at ' . $path['local']['base'] . 'tags');
} elseif (is_writeable($path['local']['base'] . 'tags') === false) {
return $this->raiseError('Can not write to the tag directory at ' . $path['local']['base'] . 'tags');
} else {
$makeCommand = 'svn mkdir ' . $releaseTag;
$this->output .= "+ $makeCommand\n";
if (empty($options['dry-run'])) {
// We need to create the tag dir.
$fp = popen($makeCommand, "r");
$out = '';
while ($line = fgets($fp, 1024)) {
$out .= rtrim($line)."\n";
}
pclose($fp);
$this->output .= "$out\n";
}
}
$command = 'svn';
if (isset($options['quiet'])) {
$command .= ' -q';
}
$command .= ' copy --parents ';
$dir = dirname($packageFile);
$dir = substr($dir, strrpos($dir, DIRECTORY_SEPARATOR) + 1);
$files = array_keys($info->getFilelist());
if (!in_array(basename($packageFile), $files)) {
$files[] = basename($packageFile);
}
array_shift($params);
if (count($params)) {
// add in additional files to be tagged (package files and such)
$files = array_merge($files, $params);
}
$commands = array();
foreach ($files as $file) {
if (!file_exists($file)) {
$file = $dir . DIRECTORY_SEPARATOR . $file;
}
$commands[] = $command . ' ' . escapeshellarg($file) . ' ' .
escapeshellarg($releaseTag . DIRECTORY_SEPARATOR . $file);
}
$this->output .= implode("\n", $commands) . "\n";
if (empty($options['dry-run'])) {
foreach ($commands as $command) {
$fp = popen($command, "r");
while ($line = fgets($fp, 1024)) {
$this->output .= rtrim($line)."\n";
}
pclose($fp);
}
}
$command = 'svn ci -m "Tagging the ' . $version . ' release" ' . $releaseTag . "\n";
$this->output .= "+ $command\n";
if (empty($options['dry-run'])) {
$fp = popen($command, "r");
while ($line = fgets($fp, 1024)) {
$this->output .= rtrim($line)."\n";
}
pclose($fp);
}
$this->ui->outputData($this->output, $_cmd);
return true;
}
function _svnFindPath($file)
{
$xml = '';
$command = "svn info --xml $file";
$fp = popen($command, "r");
while ($line = fgets($fp, 1024)) {
$xml .= rtrim($line)."\n";
}
pclose($fp);
$url_tag = strpos($xml, '<url>');
$url = substr($xml, $url_tag + 5, strpos($xml, '</url>', $url_tag + 5) - ($url_tag + 5));
$path = array();
$path['from'] = substr($url, 0, strrpos($url, '/'));
$path['base'] = substr($path['from'], 0, strrpos($path['from'], '/') + 1);
// Figure out the local paths - see http://pear.php.net/bugs/17463
$pos = strpos($file, DIRECTORY_SEPARATOR . 'trunk' . DIRECTORY_SEPARATOR);
if ($pos === false) {
$pos = strpos($file, DIRECTORY_SEPARATOR . 'branches' . DIRECTORY_SEPARATOR);
}
$path['local']['base'] = substr($file, 0, $pos + 1);
return $path;
}
function _svnRemoveTag($version, $package, $tag, $packageFile, $options)
{
$command = 'svn';
if (isset($options['quiet'])) {
$command .= ' -q';
}
$command .= ' remove';
$command .= ' -m "Removing tag for the ' . $version . ' release."';
$path = $this->_svnFindPath($packageFile);
$command .= ' ' . $path['base'] . 'tags/' . $tag;
if ($this->config->get('verbose') > 1) {
$this->output .= "+ $command\n";
}
$this->output .= "+ $command\n";
if (empty($options['dry-run'])) {
$fp = popen($command, "r");
while ($line = fgets($fp, 1024)) {
$this->output .= rtrim($line)."\n";
}
pclose($fp);
}
$this->ui->outputData($this->output, $command);
return true;
}
function doCvsTag($command, $options, $params)
{
$this->output = '';
$_cmd = $command;
if (count($params) < 1) {
$help = $this->getHelp($command);
return $this->raiseError("$command: missing parameter: $help[0]");
}
$packageFile = realpath($params[0]);
$obj = &$this->getPackageFile($this->config, $this->_debug);
$info = $obj->fromAnyFile($packageFile, PEAR_VALIDATE_NORMAL);
if (PEAR::isError($info)) {
return $this->raiseError($info);
}
$err = $warn = array();
if (!$info->validate()) {
foreach ($info->getValidationWarnings() as $error) {
if ($error['level'] == 'warning') {
$warn[] = $error['message'];
} else {
$err[] = $error['message'];
}
}
}
if (!$this->_displayValidationResults($err, $warn, true)) {
$this->ui->outputData($this->output, $command);
return $this->raiseError('CVS tag failed');
}
$version = $info->getVersion();
$cvsversion = preg_replace('/[^a-z0-9]/i', '_', $version);
$cvstag = "RELEASE_$cvsversion";
$files = array_keys($info->getFilelist());
$command = 'cvs';
if (isset($options['quiet'])) {
$command .= ' -q';
}
if (isset($options['reallyquiet'])) {
$command .= ' -Q';
}
$command .= ' tag';
if (isset($options['slide'])) {
$command .= ' -F';
}
if (isset($options['delete'])) {
$command .= ' -d';
}
$command .= ' ' . $cvstag . ' ' . escapeshellarg($params[0]);
array_shift($params);
if (count($params)) {
// add in additional files to be tagged
$files = array_merge($files, $params);
}
$dir = dirname($packageFile);
$dir = substr($dir, strrpos($dir, '/') + 1);
foreach ($files as $file) {
if (!file_exists($file)) {
$file = $dir . DIRECTORY_SEPARATOR . $file;
}
$command .= ' ' . escapeshellarg($file);
}
if ($this->config->get('verbose') > 1) {
$this->output .= "+ $command\n";
}
$this->output .= "+ $command\n";
if (empty($options['dry-run'])) {
$fp = popen($command, "r");
while ($line = fgets($fp, 1024)) {
$this->output .= rtrim($line)."\n";
}
pclose($fp);
}
$this->ui->outputData($this->output, $_cmd);
return true;
}
function doCvsDiff($command, $options, $params)
{
$this->output = '';
if (sizeof($params) < 1) {
$help = $this->getHelp($command);
return $this->raiseError("$command: missing parameter: $help[0]");
}
$file = realpath($params[0]);
$obj = &$this->getPackageFile($this->config, $this->_debug);
$info = $obj->fromAnyFile($file, PEAR_VALIDATE_NORMAL);
if (PEAR::isError($info)) {
return $this->raiseError($info);
}
$err = $warn = array();
if (!$info->validate()) {
foreach ($info->getValidationWarnings() as $error) {
if ($error['level'] == 'warning') {
$warn[] = $error['message'];
} else {
$err[] = $error['message'];
}
}
}
if (!$this->_displayValidationResults($err, $warn, true)) {
$this->ui->outputData($this->output, $command);
return $this->raiseError('CVS diff failed');
}
$info1 = $info->getFilelist();
$files = $info1;
$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 = $short = false;
if (isset($this->commands[$command]['options'][$option])) {
$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['name']);
}
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;
}
function doPackageDependencies($command, $options, $params)
{
// $params[0] -> the PEAR package to list its information
if (count($params) !== 1) {
return $this->raiseError("bad parameter(s), try \"help $command\"");
}
$obj = &$this->getPackageFile($this->config, $this->_debug);
if (is_file($params[0]) || strpos($params[0], '.xml') > 0) {
$info = $obj->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
} else {
$reg = $this->config->getRegistry();
$info = $obj->fromArray($reg->packageInfo($params[0]));
}
if (PEAR::isError($info)) {
return $this->raiseError($info);
}
$deps = $info->getDeps();
if (is_array($deps)) {
if ($info->getPackagexmlVersion() == '1.0') {
$data = array(
'caption' => 'Dependencies for pear/' . $info->getPackage(),
'border' => true,
'headline' => array("Required?", "Type", "Name", "Relation", "Version"),
);
foreach ($deps as $d) {
if (isset($d['optional'])) {
if ($d['optional'] == 'yes') {
$req = 'No';
} else {
$req = 'Yes';
}
} else {
$req = 'Yes';
}
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($req, $type, $name, $rel, $version);
}
} else { // package.xml 2.0 dependencies display
require_once 'PEAR/Dependency2.php';
$deps = $info->getDependencies();
$reg = &$this->config->getRegistry();
if (is_array($deps)) {
$d = new PEAR_Dependency2($this->config, array(), '');
$data = array(
'caption' => 'Dependencies for ' . $info->getPackage(),
'border' => true,
'headline' => array("Required?", "Type", "Name", 'Versioning', 'Group'),
);
foreach ($deps as $type => $subd) {
$req = ($type == 'required') ? 'Yes' : 'No';
if ($type == 'group' && isset($subd['attribs']['name'])) {
$group = $subd['attribs']['name'];
} else {
$group = '';
}
if (!isset($subd[0])) {
$subd = array($subd);
}
foreach ($subd as $groupa) {
foreach ($groupa as $deptype => $depinfo) {
if ($deptype == 'attribs') {
continue;
}
if ($deptype == 'pearinstaller') {
$deptype = 'pear Installer';
}
if (!isset($depinfo[0])) {
$depinfo = array($depinfo);
}
foreach ($depinfo as $inf) {
$name = '';
if (isset($inf['channel'])) {
$alias = $reg->channelAlias($inf['channel']);
if (!$alias) {
$alias = '(channel?) ' .$inf['channel'];
}
$name = $alias . '/';
}
if (isset($inf['name'])) {
$name .= $inf['name'];
} elseif (isset($inf['pattern'])) {
$name .= $inf['pattern'];
} else {
$name .= '';
}
if (isset($inf['uri'])) {
$name .= ' [' . $inf['uri'] . ']';
}
if (isset($inf['conflicts'])) {
$ver = 'conflicts';
} else {
$ver = $d->_getExtraString($inf);
}
$data['data'][] = array($req, ucfirst($deptype), $name,
$ver, $group);
}
}
}
}
}
}
$this->ui->outputData($data, $command);
return true;
}
// Fallback
$this->ui->outputData("This package does not have any dependencies.", $command);
}
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 (count($params) !== 1) {
return $this->raiseError("bad parameter(s), try \"help $command\"");
}
require_once 'System.php';
require_once 'Archive/Tar.php';
if (!file_exists($params[0])) {
return $this->raiseError("file does not exist: $params[0]");
}
$obj = $this->getPackageFile($this->config, $this->_debug);
$info = $obj->fromTgzFile($params[0], PEAR_VALIDATE_NORMAL);
if (PEAR::isError($info)) {
return $this->raiseError($info);
}
$tar = new Archive_Tar($params[0]);
$tmpdir = $this->config->get('temp_dir');
$tmpdir = System::mktemp(' -t "' . $tmpdir . '" -d pearsign');
if (!$tar->extractList('package2.xml 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");
}
$packagexml = 'package.xml';
if (file_exists("$tmpdir/package2.xml")) {
$packagexml = 'package2.xml';
}
if (file_exists("$tmpdir/package.sig")) {
unlink("$tmpdir/package.sig");
}
if (!file_exists("$tmpdir/$packagexml")) {
return $this->raiseError("Extracted file $tmpdir/$packagexml not found.");
}
$input = $this->ui->userDialog($command,
array('GnuPG Passphrase'),
array('password'));
if (!isset($input[0])) {
//use empty passphrase
$input[0] = '';
}
$devnull = (isset($options['verbose'])) ? '' : ' 2>/dev/null';
$gpg = popen("gpg --batch --passphrase-fd 0 --armor --detach-sign --output $tmpdir/package.sig $tmpdir/$packagexml" . $devnull, "w");
if (!$gpg) {
return $this->raiseError("gpg command failed");
}
fwrite($gpg, "$input[0]\n");
if (pclose($gpg) || !file_exists("$tmpdir/package.sig")) {
return $this->raiseError("gpg sign failed");
}
if (!$tar->addModify("$tmpdir/package.sig", '', $tmpdir)) {
return $this->raiseError('failed adding signature to file');
}
$this->ui->outputData("Package signed.", $command);
return true;
}
/**
* For unit testing purposes
*/
function &getInstaller(&$ui)
{
if (!class_exists('PEAR_Installer')) {
require_once 'PEAR/Installer.php';
}
$a = new PEAR_Installer($ui);
return $a;
}
/**
* For unit testing purposes
*/
function &getCommandPackaging(&$ui, &$config)
{
if (!class_exists('PEAR_Command_Packaging')) {
if ($fp = @fopen('PEAR/Command/Packaging.php', 'r', true)) {
fclose($fp);
include_once 'PEAR/Command/Packaging.php';
}
}
if (class_exists('PEAR_Command_Packaging')) {
$a = new PEAR_Command_Packaging($ui, $config);
} else {
$a = null;
}
return $a;
}
function doMakeRPM($command, $options, $params)
{
// Check to see if PEAR_Command_Packaging is installed, and
// transparently switch to use the "make-rpm-spec" command from it
// instead, if it does. Otherwise, continue to use the old version
// of "makerpm" supplied with this package (PEAR).
$packaging_cmd = $this->getCommandPackaging($this->ui, $this->config);
if ($packaging_cmd !== null) {
$this->ui->outputData('PEAR_Command_Packaging is installed; using '.
'newer "make-rpm-spec" command instead');
return $packaging_cmd->run('make-rpm-spec', $options, $params);
}
$this->ui->outputData('WARNING: "pear makerpm" is no longer available; an '.
'improved version is available via "pear make-rpm-spec", which '.
'is available by installing PEAR_Command_Packaging');
return true;
}
function doConvert($command, $options, $params)
{
$packagexml = isset($params[0]) ? $params[0] : 'package.xml';
$newpackagexml = isset($params[1]) ? $params[1] : dirname($packagexml) .
DIRECTORY_SEPARATOR . 'package2.xml';
$pkg = &$this->getPackageFile($this->config, $this->_debug);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$pf = $pkg->fromPackageFile($packagexml, PEAR_VALIDATE_NORMAL);
PEAR::staticPopErrorHandling();
if (PEAR::isError($pf)) {
if (is_array($pf->getUserInfo())) {
foreach ($pf->getUserInfo() as $warning) {
$this->ui->outputData($warning['message']);
}
}
return $this->raiseError($pf);
}
if (is_a($pf, 'PEAR_PackageFile_v2')) {
$this->ui->outputData($packagexml . ' is already a package.xml version 2.0');
return true;
}
$gen = &$pf->getDefaultGenerator();
$newpf = &$gen->toV2();
$newpf->setPackagefile($newpackagexml);
$gen = &$newpf->getDefaultGenerator();
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$state = (isset($options['flat']) ? PEAR_VALIDATE_PACKAGING : PEAR_VALIDATE_NORMAL);
$saved = $gen->toPackageFile(dirname($newpackagexml), $state, basename($newpackagexml));
PEAR::staticPopErrorHandling();
if (PEAR::isError($saved)) {
if (is_array($saved->getUserInfo())) {
foreach ($saved->getUserInfo() as $warning) {
$this->ui->outputData($warning['message']);
}
}
$this->ui->outputData($saved->getMessage());
return true;
}
$this->ui->outputData('Wrote new version 2.0 package.xml to "' . $saved . '"');
return true;
}
}
|