Development

Changeset 30083

You must first sign up to be able to contribute.

Changeset 30083

Show
Ignore:
Timestamp:
07/01/10 09:59:45 (3 years ago)
Author:
slava.hatnuke
Message:

handle any path

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/fpBuildPlugin/trunk/lib/task/ProjectBuildTask.class.php

    r30075 r30083  
    1616    new sfCommandArgument( 
    1717      'profile', 
    18       sfCommandArgument::OPTIONAL,  
     18      sfCommandArgument::REQUIRED,  
    1919      'Build profile'))); 
    2020 
     21  } 
     22 
     23 
     24  protected function execute($arguments = array(), $options = array()) 
     25  { 
     26    $totalTimer = $this->getTimer(); 
     27    chdir(sfConfig::get('sf_root_dir')); 
     28    foreach ($this->_prepareCommands($arguments['profile']) as $command) { 
     29      $this->_doCommand($command); 
     30    } 
     31 
     32    $this->showTime($totalTimer, 'Total time: '); 
     33  } 
     34   
     35  protected function _doCommand($command) 
     36  { 
     37    $command = trim($command); 
     38    if(empty($command)) return; 
     39 
     40    $this->logSection("Command :", $command); 
     41     
     42    $timer = $this->getTimer(); 
     43    $result = 0; 
     44     
     45    passthru($command, $result); 
     46 
     47    $this->showTime($timer); 
     48 
     49    if((int)$result > 0) { 
     50      $this->showTime($totalTimer, 'Total time: '); 
     51       
     52      throw new Exception('Command: `' . $command . '`. Exit with error code: `'.$result.'`'); 
     53    } 
     54  } 
     55   
     56  /** 
     57   *  
     58   * @param string $source 
     59   *  
     60   * @throws Exceptino if the source cannot be found. 
     61   *  
     62   * @return array 
     63   */ 
     64  protected function _prepareCommands($source) 
     65  { 
     66    // guess file form project root config directory. 
     67    $relativeConfigPath = sfConfig::get('sf_root_dir').'/config/'.$source; 
     68    if (file_exists($relativeConfigPath)) { 
     69      return file($relativeConfigPath); 
     70    } 
     71 
     72    // guess relative from project root 
     73    $relativeRootPath = sfConfig::get('sf_root_dir') . '/'. $source; 
     74    if (file_exists($relativeRootPath)) { 
     75      return file($relativeRootPath); 
     76    } 
     77     
     78    // guess absolute 
     79    $absolutePath = $source; 
     80    if (file_exists($absolutePath)) { 
     81      return file($absolutePath); 
     82    } 
     83     
     84    throw new Exception("Provided path to build profile is not exist or invalid. Given parameter is `{$source}`. The next pathes were tried: " .  
     85      "\nRelative from config `{$relativeConfigPath}`," . 
     86      "\nRelative from root - `{$relativeRootPath}`," . 
     87      "\nAbsolute - `{$absolutePath}`"); 
    2188  } 
    2289 
     
    2491   * @return sfTimer 
    2592   */ 
    26   private function getTimer() 
     93  protected function getTimer() 
    2794  { 
    2895    $timer = new sfTimer(); 
     
    3299  } 
    33100 
    34   private function showTime(sfTimer $timer, $message = '', $afterMessage = "\n\n") 
     101  protected function showTime(sfTimer $timer, $message = 'Time : ', $afterMessage = "\n\n") 
    35102  { 
    36103    $timer->addTime(); 
    37      
    38     echo $message; 
    39     echo (int)$timer->getElapsedTime() . " second(s)\n"; 
    40     echo $afterMessage; 
    41   } 
    42  
    43   protected function execute($arguments = array(), $options = array()) 
    44   { 
    45     $profile = $arguments['profile']; 
    46     $configProfile = sfConfig::get('sf_root_dir').'/config/'.$profile; 
    47     if (file_exists($configProfile)) { 
    48       $profile = $configProfile; 
    49     } 
    50     if (!(file_exists($profile) && is_readable($profile))) { 
    51       throw new Exception('Provided path to build profile is not exist or invalid. Given path is `'.$arguments['profile'].'`'); 
    52     } 
    53  
    54     chdir(sfConfig::get('sf_root_dir')); 
    55  
    56     $totalTimer = $this->getTimer(); 
    57  
    58     foreach (file($profile) as $task) 
    59     { 
    60  
    61       $timer = $this->getTimer(); 
    62  
    63       $task = trim($task); 
    64  
    65       if(!empty($task)) 
    66       { 
    67         $taskName = 'Task: ' . $task; 
    68  
    69         $result = 0; 
    70         echo $taskName . "\n\n"; 
    71         passthru($task, $result); 
    72         echo "\n"; 
    73  
    74         $this->showTime($timer); 
    75  
    76         if((int)$result > 0) 
    77         { 
    78           $this->showTime($totalTimer, 'Total time: '); 
    79           throw new Exception('`' . $taskName . '`. Running with error #ID: `'.$result.'`'); 
    80         } 
    81  
    82       } 
    83  
    84     } 
    85  
    86     $this->showTime($totalTimer, 'Total time: '); 
    87  
     104    $this->log(''); 
     105    $this->logSection($message, date('i:s', (int) $timer->getElapsedTime())); 
     106    $this->log(''); 
     107    $this->log(''); 
    88108  } 
    89109}