[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/scripts/ -> create-symlinks.php (source)

   1  #!/usr/bin/php
   2  <?php
   3  /**
   4   * This script creates softlinks to the library files you retrieved from
   5   * the CVS "framework" module.
   6   *
   7   * It creates the same directory structure the packages would have if they
   8   * were installed with "pear install package.xml".
   9   * For creating this structure it uses the information given in the
  10   * package.xml files inside each package directory.
  11   *
  12   * $Horde: horde/scripts/create-symlinks.php,v 1.14.10.7 2006/01/01 21:29:09 jan Exp $
  13   *
  14   * Copyright 2002 Wolfram Kriesing <wolfram@kriesing.de>
  15   * Copyright 2003-2006 Jan Schneider <jan@horde.org>
  16   *
  17   * See the enclosed file COPYING for license information (LGPL). If you
  18   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  19   *
  20   * @author Wolfram Kriesing <wolfram@kriesing.de>
  21   * @author Jan Schneider <jan@horde.org>
  22   * @since Horde 3.0
  23   */
  24  
  25  // Find the base file path of Horde.
  26  @define('HORDE_BASE', dirname(__FILE__) . '/..');
  27  
  28  // Configuration.
  29  // Enter directories without trailing slashes.
  30  
  31  // The directory with the CVS checkout.
  32  $srcDir = HORDE_BASE . '/framework';
  33  
  34  // The directory where the softlinks are created.
  35  // This is also the directory which you should put in your include path
  36  // after creating the links.
  37  $destDir = HORDE_BASE . '/libs';
  38  
  39  $copy = false;
  40  
  41  if (isset($argv)) {
  42      /* Get rid of the first arg which is the script name. */
  43      array_shift($argv);
  44      while ($arg = array_shift($argv)) {
  45          if ($arg == '--help') {
  46              print_usage();
  47          } elseif ($arg == '--copy') {
  48              $copy = true;
  49          } elseif (strstr($arg, '--src')) {
  50              list(,$srcDir) = explode('=', $arg);
  51          } elseif (strstr($arg, '--dest')) {
  52              list(,$destDir) = explode('=', $arg);
  53          } else {
  54              print_usage("Unrecognised option $arg");
  55          }
  56      }
  57  }
  58  
  59  // Do CLI checks and environment setup first.
  60  require_once $srcDir . '/CLI/CLI.php';
  61  
  62  // Make sure no one runs this from the web.
  63  if (!Horde_CLI::runningFromCLI()) {
  64      exit("Must be run from the command line\n");
  65  }
  66  
  67  // Load the CLI environment - make sure there's no time limit, init
  68  // some variables, etc.
  69  Horde_CLI::init();
  70  
  71  @include_once 'Tree/Tree.php';
  72  if (!class_exists('Tree')) {
  73      exit("You need the PEAR 'Tree' package installed\n");
  74  }
  75  
  76  $linker = &new Linker($copy);
  77  if ($handle = opendir($srcDir)) {
  78      while ($file = readdir($handle)) {
  79          if ($file != '.' &&
  80              $file != '..' &&
  81              $file != 'CVS' &&
  82              is_dir("$srcDir/$file")) {
  83              $linker->process("$srcDir/$file", $destDir);
  84          }
  85      }
  86      closedir($handle);
  87   }
  88  
  89  echo "\n";
  90  
  91  //  possible xml-structs
  92  //  <filelist>
  93  //      <dir name="/" baseinstalldir="XML">
  94  //          <file role="php">Parser.php</file>
  95  //          <file role="php" name="RSS.php" />
  96  //      </dir>
  97  //  </filelist>
  98  //
  99  //  <filelist>
 100  //      <file role="php" baseinstalldir="/">DB.php</file>
 101  //      <dir name="DB">
 102  //          <file role="php">common.php</file>
 103  //      </dir>
 104  //  </filelist>
 105  class Linker {
 106  
 107      var $_srcDir;
 108  
 109      var $_baseInstallDir;
 110  
 111      var $_fileroles = array('php');
 112  
 113      var $_role;
 114  
 115      var $_copy;
 116  
 117      function Linker($copy = false)
 118      {
 119          $this->_copy = $copy;
 120      }
 121  
 122      function process($srcDir, $destDir)
 123      {
 124          $this->_srcDir = $srcDir;
 125          $packageFile = $this->_srcDir . '/package.xml';
 126          $cli = &Horde_CLI::singleton();
 127  
 128          if (!is_file($packageFile)) {
 129              $cli->message('No package.xml in ' . $this->_srcDir, 'cli.warning');
 130              return false;
 131          }
 132  
 133          $tree = Tree::setupMemory('XML', $packageFile);
 134          $tree->setup();
 135  
 136          // read package name
 137          $packageName = trim($tree->getElementContent('/package/name', 'cdata'));
 138          $cli->writeln("Processing package $packageName.");
 139  
 140          // look for filelist in '/package/release/filelist'
 141          $filelist = $tree->getElementByPath('/package/release/filelist');
 142  
 143          if ($filelist) {
 144              // do this better, make the tree class work case insensitive
 145              $baseInstallDir = $filelist['child']['attributes']['baseinstalldir'];
 146  
 147              $this->_baseInstallDir = $destDir;
 148              if ($baseInstallDir != '/') {
 149                  $this->_baseInstallDir .= '/' . $baseInstallDir;
 150              }
 151              $this->_baseInstallDir = preg_replace('|/+|', '/', $this->_baseInstallDir);
 152  
 153              if (!is_dir($this->_baseInstallDir)) {
 154                  require_once 'System.php';
 155                  System::mkdir('-p ' . $this->_baseInstallDir);
 156              }
 157  
 158              $this->_handleFilelistTag($filelist);
 159          } else {
 160              $cli->message('No filelist tag found inside: ' . $packageFile, 'cli.warning');
 161          }
 162      }
 163  
 164      function _handleFilelistTag($element, $curDir = '')
 165      {
 166          foreach ($element['children'] as $child) {
 167              switch ($child['name']) {
 168              case 'file':
 169                  $this->_handleFileTag($child, $curDir);
 170                  break;
 171              case 'dir':
 172                  $this->_handleDirTag($child, $curDir);
 173                  break;
 174              default:
 175                  $cli = &Horde_CLI::singleton();
 176                  $cli->message('Got no handler for tag: ' . $child['name'], 'cli-warning');
 177                  break;
 178              }
 179          }
 180  
 181      }
 182  
 183      function _handleDirTag($element, $curDir)
 184      {
 185          if ($element['attributes']['name'] != '/') {
 186              if (substr($curDir, -1) != '/') {
 187                  $curDir = $curDir . '/';
 188              }
 189              $curDir = $curDir . $element['attributes']['name'];
 190          }
 191  
 192          if (!empty($element['attributes']['role'])) {
 193              $this->_role = $element['attributes']['role'];
 194          }
 195  
 196          if (!is_dir($this->_baseInstallDir . $curDir)) {
 197              require_once 'System.php';
 198              System::mkdir('-p ' . $this->_baseInstallDir . $curDir);
 199          }
 200  
 201          $this->_handleFilelistTag($element, $curDir);
 202      }
 203  
 204      function _handleFileTag($element, $dir)
 205      {
 206          if (!empty($element['attributes']['role'])) {
 207              $this->_role = $element['attributes']['role'];
 208          }
 209  
 210          if (!in_array($this->_role, $this->_fileroles)) {
 211              return;
 212          }
 213  
 214          if (!empty($element['attributes']['name'])) {
 215              $filename = $element['attributes']['name'];
 216          } else {
 217              $filename = $element['cdata'];
 218          }
 219          $filename = trim($filename);
 220  
 221          if ($this->_copy) {
 222              $cmd = "cp {$this->_srcDir}$dir/$filename {$this->_baseInstallDir}$dir/$filename";
 223          } else {
 224              $parent = $this->_findCommonParent($this->_srcDir . $dir,
 225                                                 $this->_baseInstallDir . $dir);
 226              $dirs = substr_count(substr($this->_baseInstallDir . $dir,
 227                                          strlen($parent)),
 228                                   '/');
 229              $src = str_repeat('../', $dirs) .
 230                  substr($this->_srcDir . $dir, strlen($parent) + 1);
 231              $cmd = "ln -sf $src/$filename {$this->_baseInstallDir}$dir/$filename";
 232          }
 233          exec($cmd);
 234      }
 235  
 236      function _findCommonParent($a, $b)
 237      {
 238          for ($common = '', $lastpos = 0, $pos = strpos($a, '/', 1);
 239               $pos !== false && strpos($b, substr($a, 0, $pos)) === 0;
 240               $pos = strpos($a, '/', $pos + 1)) {
 241              $common .= substr($a, $lastpos, $pos - $lastpos);
 242              $lastpos = $pos;
 243          }
 244          return $common;
 245      }
 246  
 247  }
 248  
 249  function print_usage($message = '') {
 250  
 251      if (!empty($message)) {
 252          print "create-symlinks.php: $message\n\n";
 253      }
 254  
 255      print <<<USAGE
 256  Usage: create-symlinks.php [OPTION]
 257  
 258  Possible options:
 259    --copy        Do not create symbolic links, but actually copy the libraries.
 260    --src=DIR     The source directory for the framework libraries.
 261    --dest=DIR    The destination directory for the framework libraries.
 262  
 263  USAGE;
 264      exit;
 265  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7