Esempio n. 1
0
 /**
  * delete files indicated in the given manifest file, from the indicated target
  * directory.
  *
  * @param string $ficlist  manifest file name
  * @param string $distpath directory were files are copied
  */
 public static function removeFiles($ficlist, $distpath)
 {
     $distdir = Fs\DirUtils::normalizeDir($distpath);
     $fs = self::getFileSystem($distdir);
     $script = file($ficlist);
     $currentdestdir = '';
     foreach ($script as $nbline => $line) {
         ++$nbline;
         if (preg_match(';^(cd|rmd)?\\s+([a-zA-Z0-9\\/.\\-_]+)\\s*$;m', $line, $m)) {
             if ($m[1] == 'rmd') {
                 $fs->removeDir(Fs\DirUtils::normalizeDir($m[2]));
             } elseif ($m[1] == 'cd') {
                 $currentdestdir = Fs\DirUtils::normalizeDir($m[2]);
             } else {
                 if ($m[2] == '') {
                     throw new \Exception("{$ficlist} : file required on line {$nbline} \n");
                 }
                 $destfile = $currentdestdir . $m[2];
                 if (!file_exists($distdir . $destfile)) {
                     if (self::$verbose) {
                         echo "cannot remove {$destfile}. It doesn't exist anymore.\n";
                     }
                     continue;
                 }
                 if (self::$verbose) {
                     echo 'remove  ' . $destfile . "\n";
                 }
                 if (!$fs->removeFile($destfile)) {
                     throw new \Exception(" {$ficlist}: cannot remove file " . $m[2] . ", line {$nbline} \n");
                 }
             }
         } elseif (preg_match("!^\\s*(\\#.*)?\$!", $line)) {
             // we ignore comments
         } else {
             throw new \Exception("{$ficlist} : syntax error on line {$nbline} \n");
         }
     }
 }
Esempio n. 2
0
 /**
  * @param array $preprocvars     list of key/value representing variables for the preprocessor
  * @param bool  $preprocmanifest if true, the manifest file is preprocessed then the manifest
  *                               reader will used the generated manifest file instead of the given manifest file.
  */
 public function process($preprocvars, $preprocmanifest = false)
 {
     $this->preprocvars = $preprocvars;
     if ($preprocmanifest) {
         $this->preproc->setVars($preprocvars);
         try {
             $content = $this->preproc->parseFile($this->ficlist);
         } catch (\Exception $e) {
             throw new \Exception('cannot preprocess the manifest file ' . $this->ficlist . ' (' . $e . ")\n");
         }
         $script = explode("\n", $content);
     } else {
         $script = file($this->ficlist);
     }
     $currentdestdir = '';
     $currentsrcdir = '';
     foreach ($script as $nbline => $line) {
         ++$nbline;
         if (preg_match(';^(cd|sd|dd|\\*|!|\\*!|c|\\*c|cch)?\\s+([a-zA-Z0-9\\/.\\-_]+)\\s*(?:\\(([a-zA-Z0-9\\%\\/.\\-_]*)\\))?\\s*$;m', $line, $m)) {
             if ($m[1] == 'dd') {
                 // set destination dir
                 $currentdestdir = DirUtils::normalizeDir($m[2]);
                 $this->fs->createDir($currentdestdir);
             } elseif ($m[1] == 'sd') {
                 // set source dir
                 $currentsrcdir = DirUtils::normalizeDir($m[2]);
             } elseif ($m[1] == 'cd') {
                 // set source dir and destination dir (same sub path)
                 $currentsrcdir = DirUtils::normalizeDir($m[2]);
                 $currentdestdir = DirUtils::normalizeDir($m[2]);
                 $this->fs->createDir($currentdestdir);
             } else {
                 // copy a file
                 // should we do processing on the file?
                 $doPreprocessing = strpos($m[1], '*') !== false;
                 // should we compress files or generate encoded files?
                 $doCompression = strpos($m[1], 'c') !== false && $m[1] != 'cch' || $this->stripComment && strpos($m[1], '!') === false;
                 if ($m[2] == '') {
                     throw new \Exception($this->ficlist . ": file required on line {$nbline} \n");
                 }
                 if (!isset($m[3]) || $m[3] == '') {
                     $m[3] = $m[2];
                 }
                 if ($m[2] == '__ALL__') {
                     $dir = new \DirectoryIterator($this->sourcedir . $currentsrcdir);
                     foreach ($dir as $dirContent) {
                         if (!$dirContent->isFile()) {
                             continue;
                         }
                         $m[2] = $m[3] = $dirContent->getFileName();
                         $destfile = $currentdestdir . $m[3];
                         $sourcefile = $this->sourcedir . $currentsrcdir . $m[2];
                         $this->processFile($sourcefile, $destfile, $nbline, $m, $doPreprocessing, $doCompression);
                     }
                 } elseif ($m[2] == '__ALL_RECURSIVELY__') {
                     $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->sourcedir . $currentsrcdir));
                     $it->rewind();
                     while ($it->valid()) {
                         if (!$it->isDot()) {
                             $this->fs->createDir($currentdestdir . $it->getSubPath());
                             $sourcefile = $this->sourcedir . $currentsrcdir . $it->getSubPath() . '/' . $it->getBaseName();
                             $destfile = $currentdestdir . $it->getSubPath() . '/' . $it->getBaseName();
                             $this->processFile($sourcefile, $destfile, $nbline, $m, $doPreprocessing, $doCompression);
                         }
                         $it->next();
                     }
                 } else {
                     $destfile = $currentdestdir . $m[3];
                     $sourcefile = $this->sourcedir . $currentsrcdir . $m[2];
                     $this->processFile($sourcefile, $destfile, $nbline, $m, $doPreprocessing, $doCompression);
                 }
             }
         } elseif (preg_match("!^\\s*(\\#.*)?\$!", $line)) {
             // we ignore comments
         } else {
             throw new \Exception($this->ficlist . ": syntax error on line {$nbline} \n");
         }
     }
 }