Skip to content

Commit

Permalink
Abstract pear package parsing into separate file for framework utils
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Oct 14, 2014
1 parent ae18467 commit c7f078c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 59 deletions.
58 changes: 11 additions & 47 deletions framework/bin/install_framework
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ $debug = $dryrun = false;
// Default to copying if this is run on Windows.
$copy = strncasecmp(PHP_OS, 'WIN', 3) ? false : true;

// All packages by default.
$pkg = null;

for ($i = 1; $i < count($argv); ++$i) {
switch ($argv[$i]) {
case '--copy':
Expand Down Expand Up @@ -75,11 +72,7 @@ for ($i = 1; $i < count($argv); ++$i) {
break;

case '--pkg':
$pkg = $argv[++$i];
if (!is_dir($pkg) || !file_exists($pkg . '/package.xml')) {
exit("$pkg is not a valid package directory.\n");
}
$pkg = preg_replace('|/+$|', '', $pkg);
$srcDir = preg_replace('|/+$|', '', $argv[++$i]);
break;

default:
Expand All @@ -93,7 +86,7 @@ if (is_null($hordeDir)) {

// Try to auto-detect the source and dest dirs.
$cwd = getcwd();
if (is_null($srcDir) && is_null($pkg)) {
if (is_null($srcDir)) {
$srcDir = is_dir($cwd . '/framework')
? $cwd . DIRECTORY_SEPARATOR . 'framework'
: __DIR__ . '/..';
Expand All @@ -102,7 +95,7 @@ if (is_null($destDir) && is_dir($cwd . '/lib')) {
$destDir = $cwd . DIRECTORY_SEPARATOR . 'lib';
}

if ((is_null($srcDir) && is_null($pkg)) || is_null($destDir)) {
if (is_null($srcDir) || is_null($destDir)) {
print_usage('Failed to auto-detect source and destination directories,');
}

Expand Down Expand Up @@ -157,54 +150,25 @@ $cli->message('Framework destination directory: ' . $destDir);
$cli->message('Horde directory: ' . $hordeDir);
$cli->message('Create symbolic links: ' . ($copy ? 'NO' : 'Yes'));

// Create the local PEAR config.
if (!(@include_once 'PEAR/Config.php') ||
!(@include_once 'PEAR/PackageFile.php')) {
print_usage('PEAR libraries are not in the PHP include_path.');
}

/* We are heavily relying on the PEAR libraries which are not clean with regard
* to E_STRICT. */
if (defined('E_DEPRECATED')) {
error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED);
} else {
error_reporting(E_ALL & ~E_STRICT);
}

$pear_config = PEAR_Config::singleton();
$pear_pkg = new PEAR_PackageFile($pear_config);

if ($pkg) {
$pkgs = array(basename($pkg) => realpath($pkg));
} else {
$di = new DirectoryIterator($srcDir);
$pkgs = array();
foreach ($di as $val) {
$pathname = $val->getPathname();
if ($val->isDir() &&
!$di->isDot() &&
file_exists($pathname . '/package.xml')) {
$pkgs[basename($val)] = $pathname;
}
}
asort($pkgs);
}
require_once __DIR__ . '/lib/pear_package_parse.php';
$pkg_ob = new PEAR_Package_Parse();
$pkgs = $pkg_ob->getPackages(array($srcDir));

$cli->writeLn();
$cli->message('Package(s) to install: ' . ($pkg ? $pkg : 'ALL (' . count($pkgs) . ' packages)'));
$cli->message('Package(s) to install: ' . ((count($pkgs) === 1) ? reset($pkg) : 'ALL (' . count($pkgs) . ' packages)'));

foreach ($pkgs as $key => $val) {
if ($debug) {
$cli->writeLn();
}
$cli->message('Installing package ' . $key);

$pkg_ob = $pear_pkg->fromPackageFile($val . '/package.xml', 0);
if ($pkg_ob instanceof PEAR_Error) {
$cli->message('Could not install package ' . $key . ': ' . $pkg_ob->getMessage(), 'cli.error');
$pkg = $pkg_ob->pear_pkg->fromPackageFile($val . '/package.xml', 0);
if ($pkg instanceof PEAR_Error) {
$cli->message('Could not install package ' . $key . ': ' . $pkg->getMessage(), 'cli.error');
continue;
}
foreach ($pkg_ob->getInstallationFilelist() as $file) {
foreach ($pkg->getInstallationFilelist() as $file) {
if (!isset($file['attribs']['name'])) {
$cli->message('Invalid <install> entry: ' . print_r($file['attribs'], true), 'cli.error');
continue;
Expand Down
52 changes: 52 additions & 0 deletions framework/bin/lib/pear_package_parse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

class PEAR_Package_Parse
{
public $pear_pkg;

public function __construct()
{
// Create the local PEAR config.
if (!(@include_once 'PEAR/Config.php') ||
!(@include_once 'PEAR/PackageFile.php')) {
throw new Exception('PEAR libraries are not in the PHP include_path.');
}

/* We are heavily relying on the PEAR libraries which are not clean
* with regard to E_STRICT. */
if (defined('E_DEPRECATED')) {
error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED);
} else {
error_reporting(E_ALL & ~E_STRICT);
}

$pear_config = PEAR_Config::singleton();
$this->pear_pkg = new PEAR_PackageFile($pear_config);
}

public function getPackages(array $srcDirs)
{
$pkgs = array();

foreach ($srcDirs as $dir) {
$di = new DirectoryIterator($dir);
foreach ($di as $val) {
$pathname = $val->getPathname();
if ($val->isDir() &&
!$di->isDot() &&
file_exists($pathname . '/package.xml')) {
$pkgs[basename($val)] = $pathname;
} elseif ($val->isFile() &&
($val == 'package.xml')) {
$pkgs[basename($val->getPath())] = $val->getPath();
}
}
}

asort($pkgs);

return $pkgs;
}

}

19 changes: 7 additions & 12 deletions framework/bin/pear_batch_install
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,13 @@ if (!empty($packages)) {
}
} else {
/* Installing everything. */
$dh = opendir($dir);
while (($entry = readdir($dh)) !== false) {
if ($entry == '.' || $entry == '..' || !is_dir($dir . '/' . $entry)) {
continue;
}
require_once __DIR__ . '/lib/pear_package_parse.php';
$pkg_ob = new PEAR_Package_Parse();
$pkgs = $pkg_ob->getPackages(array($dir));

$package = $dir . '/' . $entry . '/' . 'package.xml';
if (file_exists($package)) {
echo "Installing $entry:\n";
system("$pear \"$package\"");
echo "\n\n";
}
foreach ($pkgs as $key => $val) {
echo "Installing $key:\n";
system("$pear \"$val\"");
echo "\n\n";
}
closedir($dh);
}

0 comments on commit c7f078c

Please sign in to comment.