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
|
#!/usr/bin/php
<?php
// Find the base file path of Horde.
@define('HORDE_BASE', dirname(__FILE__) . '/..');
// Configuration.
// Enter directories without trailing slashes.
// The directory with the CVS checkout.
$srcDir = HORDE_BASE . '/framework';
// The directory where the softlinks are created.
// This is also the directory which you should put in your include path
// after creating the links.
$destDir = HORDE_BASE . '/libs';
/**
* This script creates softlinks to the library files you retrieved from
* the CVS "framework" module.
*
* It creates the same directory structure the packages would have if they
* were installed with "pear install package.xml".
* For creating this structure it uses the information given in the
* package.xml files inside each package directory.
*
* $Horde: horde/scripts/create-symlinks.php,v 1.14.10.3 2005/01/03 12:25:44 jan Exp $
*
* Copyright 2002 Wolfram Kriesing <wolfram@kriesing.de>
* Copyright 2003-2005 Jan Schneider <jan@horde.org>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Wolfram Kriesing <wolfram@kriesing.de>
* @author Jan Schneider <jan@horde.org>
* @version $Revision: 1.14.10.3 $
* @since Horde 3.0
*/
$copy = false;
if (isset($argv)) {
/* Get rid of the first arg which is the script name. */
array_shift($argv);
while ($arg = array_shift($argv)) {
if ($arg == '--help') {
print_usage();
} elseif ($arg == '--copy') {
$copy = true;
} elseif (strstr($arg, '--src')) {
list(,$srcDir) = explode('=', $arg);
} elseif (strstr($arg, '--dest')) {
list(,$destDir) = explode('=', $arg);
} else {
print_usage("Unrecognised option $arg");
}
}
}
// Do CLI checks and environment setup first.
require_once $srcDir . '/CLI/CLI.php';
// Make sure no one runs this from the web.
if (!Horde_CLI::runningFromCLI()) {
exit("Must be run from the command line\n");
}
// Load the CLI environment - make sure there's no time limit, init
// some variables, etc.
Horde_CLI::init();
@include_once 'Tree/Tree.php';
if (!class_exists('Tree')) {
exit("You need the PEAR 'Tree' package installed\n");
}
$linker = &new Linker($copy);
if ($handle = opendir($srcDir)) {
while ($file = readdir($handle)) {
if ($file != '.' &&
$file != '..' &&
$file != 'CVS' &&
is_dir("$srcDir/$file")) {
$linker->process("$srcDir/$file", $destDir);
}
}
closedir($handle);
}
echo "\n";
// possible xml-structs
// <filelist>
// <dir name="/" baseinstalldir="XML">
// <file role="php">Parser.php</file>
// <file role="php" name="RSS.php" />
// </dir>
// </filelist>
//
// <filelist>
// <file role="php" baseinstalldir="/">DB.php</file>
// <dir name="DB">
// <file role="php">common.php</file>
// </dir>
// </filelist>
class Linker {
var $_srcDir;
var $_baseInstallDir;
var $_fileroles = array('php');
var $_role;
var $_copy;
function Linker($copy = false)
{
$this->_copy = $copy;
}
function process($srcDir, $destDir)
{
$this->_srcDir = $srcDir;
$packageFile = $this->_srcDir . '/package.xml';
$cli = &Horde_CLI::singleton();
if (!is_file($packageFile)) {
$cli->message('No package.xml in ' . $this->_srcDir, 'cli.warning');
return false;
}
$tree = Tree::setupMemory('XML', $packageFile);
$tree->setup();
// read package name
$packageName = trim($tree->getElementContent('/package/name', 'cdata'));
$cli->writeln("Processing package $packageName.");
// look for filelist in '/package/release/filelist'
$filelist = $tree->getElementByPath('/package/release/filelist');
if ($filelist) {
// do this better, make the tree class work case insensitive
$baseInstallDir = $filelist['child']['attributes']['baseinstalldir'];
$this->_baseInstallDir = $destDir;
if ($baseInstallDir != '/') {
$this->_baseInstallDir .= '/' . $baseInstallDir;
}
if (!is_dir($this->_baseInstallDir)) {
require_once 'System.php';
System::mkdir('-p ' . $this->_baseInstallDir);
}
$this->_handleFilelistTag($filelist);
} else {
$cli->message('No filelist tag found inside: ' . $packageFile, 'cli.warning');
}
}
function _handleFilelistTag($element, $curDir = '')
{
foreach ($element['children'] as $child) {
switch ($child['name']) {
case 'file':
$this->_handleFileTag($child, $curDir);
break;
case 'dir':
$this->_handleDirTag($child, $curDir);
break;
default:
$cli = &Horde_CLI::singleton();
$cli->message('Got no handler for tag: ' . $child['name'], 'cli-warning');
break;
}
}
}
function _handleDirTag($element, $curDir)
{
if ($element['attributes']['name'] != '/') {
if (substr($curDir, -1) != '/') {
$curDir = $curDir . '/';
}
$curDir = $curDir . $element['attributes']['name'];
}
if (!empty($element['attributes']['role'])) {
$this->_role = $element['attributes']['role'];
}
if (!is_dir($this->_baseInstallDir . $curDir)) {
require_once 'System.php';
System::mkdir('-p ' . $this->_baseInstallDir . $curDir);
}
$this->_handleFilelistTag($element, $curDir);
}
function _handleFileTag($element, $dir)
{
if (!empty($element['attributes']['role'])) {
$this->_role = $element['attributes']['role'];
}
if (!in_array($this->_role, $this->_fileroles)) {
return;
}
if (!empty($element['attributes']['name'])) {
$filename = $element['attributes']['name'];
} else {
$filename = $element['cdata'];
}
$filename = trim($filename);
if ($this->_copy) {
$cmd = "cp {$this->_srcDir}$dir/$filename {$this->_baseInstallDir}$dir/$filename";
} else {
$cmd = "ln -sf {$this->_srcDir}$dir/$filename {$this->_baseInstallDir}$dir/$filename";
}
exec($cmd);
}
}
function print_usage($message = '') {
if (!empty($message)) {
print "create-symlinks.php: $message\n\n";
}
print <<<USAGE
Usage: create-symlinks.php [OPTION]
Possible options:
--copy Do not create symbolic links, but actually copy the libraries.
--src=DIR The source directory for the framework libraries.
--dest=DIR The destination directory for the framework libraries.
USAGE;
exit;
}
|