Changeset 361

Show
Ignore:
Timestamp:
01/27/07 22:59:28 (2 years ago)
Author:
laurentj
Message:

fix ticket #69 : jBuildTools, mkmanifest didn't show empty directory. A switch -e for the script is added

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build/mkmanifest.php

    r279 r361  
    33/** 
    44* @package     jBuildTools 
    5 * @version     $Id$ 
    65* @author      Jouanneau Laurent 
    76* @contributor 
    8 * @copyright   2006 Jouanneau laurent 
     7* @copyright   2006-2007 Jouanneau laurent 
    98* @link        http://www.jelix.org 
    109* @licence     GNU General Public Licence see LICENCE file or http://www.gnu.org/licenses/gpl.html 
    1110*/ 
     11 
     12require_once(dirname(__FILE__).'/lib/jCmdUtils.class.php'); 
    1213 
    1314// arguments :  repertoire1 [repertoire2] 
     
    1617//               on l'indique ici 
    1718 
    18 if($_SERVER['argc'] < 2){ 
    19    echo "too few arguments\n   repertoire1 [repertoire2]\n"; 
    20    exit(1); 
    21 
    22 array_shift($_SERVER['argv']); // shift the script name 
    23 $nbarg=$_SERVER['argc'] -1; 
     19try{ 
     20    $sws = array('-e'=>false); 
     21    $params = array('dirpath'=>true, 'basepath'=>false); 
     22     
     23    list($switches, $parameters) = jCmdUtils::getOptionsAndParams($_SERVER['argv'], $sws, $params); 
    2424 
    25 $options = array('verbose'=>false); 
    26  
    27 if(substr($_SERVER['argv'][0],0,1) == '-'){ 
    28   $nbarg--; 
    29   $sw = substr(array_shift($_SERVER['argv']),1); 
    30   $options['verbose'] = (strpos('v', $sw) !== false); 
     25}catch(Exception $e){ 
     26    echo "\nmkmanifest error : " , $e->getMessage(),"\n"; 
     27    echo "  options : [-e] dirpath [basepath] 
     28      -e  : include empty directory\n"; 
     29    exit(1); 
    3130} 
    3231 
    33 if($nbarg == 1){ 
    34    list($dirpath) = $_SERVER['argv']; 
    35    $basepath=''; 
    36 }elseif($nbarg == 2){ 
    37    list($dirpath, $basepath) = $_SERVER['argv']; 
    38 }else{ 
    39    echo "too few arguments\n"; 
    40    exit(1); 
    41 
    42  
    43 $hasError =false; 
     32$dirpath = $parameters['dirpath']; 
     33$basepath = $parameters['basepath']; 
    4434 
    4535if(substr($dirpath,-1) == '/'){ 
    4636   $dirpath=substr($dirpath,0,-1); 
    4737} 
    48  
    4938if($basepath == ''){ 
    5039   $basepath = $dirpath; 
     
    5544} 
    5645 
     46 
     47 
    5748function mkpath($dir, $basepath){ 
     49   global $switches; 
    5850   $output=''; 
    5951   if ($dh = opendir($dir)) { 
     
    6557         $type= filetype($dir.'/'.$file); 
    6658         if($type == 'dir'){ 
    67             if($file != '.' && $file !='..' ) 
     59            if($file != '.' && $file !='..' ){ 
    6860               $dirlist[]=$file; 
     61            } 
    6962         }else{ 
    7063            if(!$cdok){ 
     
    7770      closedir($dh); 
    7871 
     72      if(!$cdok && count($dirlist) == 0 && isset($switches['-e'])){ 
     73          $output.="cd ".$basepath."\n"; 
     74      } 
     75 
    7976      foreach($dirlist as $d){ 
    8077         $output.=mkpath( $dir.'/'.$d, $basepath.'/'.$d); 
    8178      } 
    8279   }else{ 
    83       //echo "erreur ouverture repertoire $dir\n"; 
     80      echo "erreur ouverture repertoire $dir\n"; 
     81       exit(1); 
    8482   } 
    8583   return $output; 
     
    9290   $output=mkpath($dirpath,$basepath); 
    9391}else{ 
    94      //echo "mauvais repertoire $dir\n"; 
     92     echo "mauvais repertoire $dirpath\n"; 
     93    exit(1); 
    9594} 
    9695 
    9796echo $output; 
    98  
    99 if($hasError) 
    100   exit(1); 
    101 else 
    102   exit(0); 
     97exit(0); 
    10398?> 
Download in other formats: Unified Diff Zip Archive