Changeset 242

Show
Ignore:
Timestamp:
09/26/07 15:39:45 (10 months ago)
Author:
mrook
Message:

Add 'verbose' option to chmod task (patch by Travis Swicegood)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/2.3/classes/phing/tasks/system/ChmodTask.php

    r144 r242  
    4343        private $quiet = false;  
    4444        private $failonerror = true; 
    45          
     45        private $verbose = true; 
     46     
    4647        /** 
    4748         * This flag means 'note errors to the output, but keep going' 
     
    6162            $this->failonerror = false; 
    6263        } 
     64    } 
     65     
     66    /** 
     67     * Set verbosity, which if set to false surpresses all but an overview 
     68     * of what happened. 
     69     */ 
     70    function setVerbose($bool) { 
     71        $this->verbose = (bool)$bool; 
    6372    } 
    6473         
     
    127136                } 
    128137         
     138        // counters for non-verbose output 
     139        $total_files = 0; 
     140        $total_dirs = 0; 
     141         
    129142        // one file 
    130143        if ($this->file !== null) { 
     144            $total_files = 1; 
    131145            $this->chmodFile($this->file, $mode); 
    132146        } 
     
    141155            $srcDirs = $ds->getIncludedDirectories(); 
    142156 
    143             for ($j = 0, $filecount = count($srcFiles); $j < $filecount; $j++) { 
     157            $filecount = count($srcFiles); 
     158            $total_files = $total_files + $filecount; 
     159            for ($j = 0; $j < $filecount; $j++) { 
    144160                $this->chmodFile(new PhingFile($fromDir, $srcFiles[$j]), $mode); 
    145161            } 
    146162 
    147             for ($j = 0, $dircount = count($srcDirs); $j <  $dircount; $j++) { 
     163            $dircount = count($srcDirs); 
     164            $total_dirs = $total_dirs + $dircount; 
     165            for ($j = 0; $j <  $dircount; $j++) { 
    148166                $this->chmodFile(new PhingFile($fromDir, $srcDirs[$j]), $mode); 
    149167            } 
     168        } 
     169 
     170        if (!$this->verbose) { 
     171            $this->log('Total files changed to ' . vsprintf('%o', $mode) . ': ' . $total_files); 
     172            $this->log('Total directories changed to ' . vsprintf('%o', $mode) . ': ' . $total_dirs); 
    150173        } 
    151174 
     
    164187                try { 
    165188                        $file->setMode($mode); 
    166                         $this->log("Changed file mode on '" . $file->__toString() ."' to " . vsprintf("%o", $mode)); 
     189                        if ($this->verbose) { 
     190                                $this->log("Changed file mode on '" . $file->__toString() ."' to " . vsprintf("%o", $mode)); 
     191                        } 
    167192                } catch (Exception $e) { 
    168193                        if($this->failonerror) { 
     
    176201} 
    177202 
     203 
  • trunk/classes/phing/tasks/system/ChmodTask.php

    r144 r242  
    4343        private $quiet = false;  
    4444        private $failonerror = true; 
    45          
     45        private $verbose = true; 
     46     
    4647        /** 
    4748         * This flag means 'note errors to the output, but keep going' 
     
    6162            $this->failonerror = false; 
    6263        } 
     64    } 
     65     
     66    /** 
     67     * Set verbosity, which if set to false surpresses all but an overview 
     68     * of what happened. 
     69     */ 
     70    function setVerbose($bool) { 
     71        $this->verbose = (bool)$bool; 
    6372    } 
    6473         
     
    127136                } 
    128137         
     138        // counters for non-verbose output 
     139        $total_files = 0; 
     140        $total_dirs = 0; 
     141         
    129142        // one file 
    130143        if ($this->file !== null) { 
     144            $total_files = 1; 
    131145            $this->chmodFile($this->file, $mode); 
    132146        } 
     
    141155            $srcDirs = $ds->getIncludedDirectories(); 
    142156 
    143             for ($j = 0, $filecount = count($srcFiles); $j < $filecount; $j++) { 
     157            $filecount = count($srcFiles); 
     158            $total_files = $total_files + $filecount; 
     159            for ($j = 0; $j < $filecount; $j++) { 
    144160                $this->chmodFile(new PhingFile($fromDir, $srcFiles[$j]), $mode); 
    145161            } 
    146162 
    147             for ($j = 0, $dircount = count($srcDirs); $j <  $dircount; $j++) { 
     163            $dircount = count($srcDirs); 
     164            $total_dirs = $total_dirs + $dircount; 
     165            for ($j = 0; $j <  $dircount; $j++) { 
    148166                $this->chmodFile(new PhingFile($fromDir, $srcDirs[$j]), $mode); 
    149167            } 
     168        } 
     169 
     170        if (!$this->verbose) { 
     171            $this->log('Total files changed to ' . vsprintf('%o', $mode) . ': ' . $total_files); 
     172            $this->log('Total directories changed to ' . vsprintf('%o', $mode) . ': ' . $total_dirs); 
    150173        } 
    151174 
     
    164187                try { 
    165188                        $file->setMode($mode); 
    166                         $this->log("Changed file mode on '" . $file->__toString() ."' to " . vsprintf("%o", $mode)); 
     189                        if ($this->verbose) { 
     190                                $this->log("Changed file mode on '" . $file->__toString() ."' to " . vsprintf("%o", $mode)); 
     191                        } 
    167192                } catch (Exception $e) { 
    168193                        if($this->failonerror) { 
     
    176201} 
    177202 
     203