Changeset 13121

Show
Ignore:
Timestamp:
12/26/11 12:58:00 (1 year ago)
Author:
mbrevda
Message:

dd auto-bump, *=all modules, longopts, variable checkin messeages;

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.10/featurecodeadmin/functions.inc.php

    r13091 r13121  
    118118            $description = _($description); 
    119119        } 
    120  
    121120        $thisexten = ($result['customcode'] != '')?$result['customcode']:$result['defaultcode']; 
    122121        $extens[] = array('destination' => 'ext-featurecodes,'.$result['defaultcode'].',1', 'description' => $description.' <'.$thisexten.'>'); 
  • modules/branches/2.10/logfiles/assets/css/logfiles.css

    r12265 r13121  
    1616.appargs{color:magenta;} 
    1717.context{color:blue;} 
     18 
     19#logfiles_header{ 
     20  position: fixed; 
     21  width: 100%; 
     22  background: white; 
     23  z-index: 100; 
     24} 
     25.rnav{ 
     26  z-index: 101; 
     27  position: fixed; 
     28} 
  • modules/branches/2.10/package.php

    r13120 r13121  
    1919//get cli opts 
    2020$longopts = array( 
    21   "modules:", 
    22   "debug::", 
    23   "checkphp::", 
     21  'bump::', 
     22  'checkphp::', 
     23  'debug::', 
     24  'help::', 
     25  'log::', 
     26  'modules:', 
     27  'msg::', 
     28  're::', 
    2429  'verbose::' 
    2530); 
    26 $vars = getopt('m:d::L::v::'); 
    27  
     31$vars = getopt('m:d::L::v::', $longopts); 
     32 
     33 
     34if (isset($vars['d']) || isset($vars['L'])) { 
     35  echo package_show_help(true); 
     36  sleep(3); 
     37
    2838 
    2939//set up some other settings 
     
    3848$vars['php_-l']   = 'php -l'; 
    3949$vars['php_extens'] = array('php', 'agi'); //extens to be considered as php for syntax checking 
     50$final_status   = array();//status message to be printed after script is run 
    4051 
    4152//move cli args to longopts for clarity throught the script 
     
    4455if (isset($vars['m'])) { 
    4556  $vars['modules'] = (array) $vars['m']; 
     57  sort($vars['modules']); 
    4658  unset($vars['m']); 
     59} elseif(isset($vars['modules'])) { 
     60  $vars['modules'] = (array) $vars['modules']; 
     61  sort($vars['modules']); 
    4762} else { 
    4863  $vars['modules'] = false; 
     64} 
     65//set all modules if --modules was set to * 
     66if (isset($vars['modules']) && is_array($vars['modules']) && in_array('*', $vars['modules'])) { 
     67  $vars['modules'] = array(); 
     68  $ls = scandir(dirname(__FILE__)); 
     69  foreach($ls as $item) { 
     70    if (strpos($item, '.') !== 0 && is_dir($item)) { 
     71      $vars['modules'][] = $item; 
     72    } 
     73  } 
     74  sort($vars['modules']); 
     75} 
     76 
     77if (isset($vars['bump']) && $vars['debug'] != 'false') { 
     78  $vars['bump'] = ctype_digit($vars['bump']) ? $vars['bump'] : true; 
     79} else { 
     80  $vars['bump'] = false; 
    4981} 
    5082 
     
    5284  $vars['debug'] = true; 
    5385  unset($vars['d']); 
     86} elseif (isset($vars['debug']) && $vars['debug'] != 'false') { 
     87  $vars['debug'] = true; 
    5488} else { 
    5589  $vars['debug'] = false; 
     90} 
     91 
     92if (isset($vars['help']) && $vars['help'] != 'help') { 
     93  $vars['help'] = true; 
     94} else { 
     95  $vars['help'] = false; 
    5696} 
    5797 
     
    5999  $vars['checkphp'] = false; 
    60100  unset($vars['L']); 
     101} elseif (isset($vars['checkphp']) && $vars['checkphp'] != 'false') { 
     102  $vars['checkphp'] = true; 
     103} 
     104 
     105if (isset($vars['log']) && $vars['log'] != 'log') { 
     106  $vars['log'] = true; 
    61107} else { 
    62   $vars['checkphp'] = true; 
     108  $vars['log'] = false; 
    63109} 
    64110 
    65111if (isset($vars['v'])) { 
    66   $vars['verbose'] = true; 
     112  $vars['verbose'] = true; 
    67113  unset($vars['L']); 
     114} elseif (isset($vars['verbose']) && $vars['verbose'] != 'false') { 
     115  $vars['verbose'] = true; 
    68116} else { 
    69117  $vars['verbose'] = false; 
    70118} 
    71119 
     120//set re 
     121//move re to an array if there are commas as part of the value 
     122/*if (isset($vars['re']) && strpos($vars['re'], ',') !== false) { 
     123  $vars['re'] = explode(',', $vars['re']); 
     124}*///while a nice idea, this is inconsistant with the rest of the script. use multiple --re options insread 
     125if (isset($vars['re'])) { 
     126  switch (true) { 
     127    case is_array($vars['re']): 
     128      foreach ($vars['re'] as $k => $v) { 
     129        if ($v) { 
     130          $vars['re'][$k] = '#' . preg_replace("/[^0-9]/", '', $v); 
     131        } else { 
     132          unset($vars['re'][$k]); 
     133        } 
     134      } 
     135      $vars['re'] = 're ' . implode(', ' . $vars['re']) . ' '; 
     136      break; 
     137    case is_string($vars['re']): 
     138      $vars['re'] = 're #' . preg_replace("/[^0-9]/", '', $vars['re']) . ' '; 
     139      break; 
     140    default: 
     141      break; 
     142  } 
     143} else { 
     144  $vars['re'] = ''; 
     145} 
     146 
     147$vars['msg'] = isset($vars['msg']) ? trim($vars['msg']) . ' ' : ''; 
     148$vars['msg'] = $vars['re'] ? $vars['re'] . '- ' . $vars['msg'] : ''; 
     149 
     150//if help was requested, show help and exit 
     151if ($vars['help']) { 
     152  echo package_show_help(); 
     153  exit(); 
     154} 
    72155//ensure we have modules to package 
    73156if (!$vars['modules']) { 
    74   die("No modules specified. Please specify them one with the -m option (use multiple switches for more than one module)\n"); 
     157  die("No modules specified. Please specify at least one module" . PHP_EOL); 
     158  echo package_show_help(); 
     159  exit(); 
    75160} 
    76161 
     
    100185  $file_scan_exclude_list = array(); 
    101186   
     187   
    102188  echo 'Packaging ' . $mod . '...' . PHP_EOL; 
    103189  if (!file_exists($mod_dir . '/module.xml')) { 
     
    122208  $xmlarray = $parser->parseAdvanced($xml); 
    123209   
     210  //bump version if requested, and reset $ver 
     211  if ($vars['bump']) { 
     212    package_bump_version($mod, $vars['bump']); 
     213    //test xml file and get some of its values 
     214    list($rawname, $ver) = check_xml($mod, $xml); 
     215    $vars['log'] = true; 
     216  } 
     217   
     218  //add changelog if requested 
     219  if ($vars['log']) { 
     220    $msg = $vars['msg'] ? $vars['msg'] : 'Packaging of ver ' . $ver; 
     221    package_update_changelog($mod, $msg); 
     222  } 
     223   
    124224  //include module specifc hook, if present 
    125225  if (file_exists($mod_dir . '/' . 'package_hook.php')) { 
     
    128228    //test include so that includes can return false and prevent further execution if it fail 
    129229    if (!include($mod_dir . '/' . 'package_hook.php')) { 
    130       echo '[FATAL] retrurned from ' . $mod_dir . '/' . 'package_hook.php with an error, '  
     230      $final_status[$mod] = '[FATAL] retrurned from ' . $mod_dir . '/' . 'package_hook.php with an error, '  
    131231        . $mod . ' wont be built' . PHP_EOL; 
    132         continue; 
     232      echo $final_status[$mod]; 
     233      continue; 
    133234    } 
    134235  } 
     
    140241    //test include so that includes can return false and prevent further execution if it fail 
    141242    if (!include('package_hook.php')) { 
    142       echo '[FATAL] retrurned from  package_hook.php with an error, '  
     243      $final_status[$mod] = '[FATAL] retrurned from  package_hook.php with an error, '  
    143244        . $mod . ' wont be built' . PHP_EOL; 
    144         continue; 
     245       echo $final_status[$mod]; 
     246      continue; 
    145247    } 
    146248  } 
     
    181283  run_cmd('svn st ' . $mod_dir . '|wc -l', $lines); 
    182284  if ( $lines > 0) { 
    183     run_cmd('svn ci -m "Auto Check-in of any outstanding changes in ' . $mod . '" ' . $mod_dir); 
     285    run_cmd('svn ci -m "[Auto Check-in of any outstanding changes in ' . $mod . '] ' . $vars['msg'] . '" ' . $mod_dir); 
    184286  } 
    185287   
     
    200302  if ($vars['verbose'] || $vars['debug']) { 
    201303    echo "excluding patterns:\n"; 
    202     print_r($exclude); 
     304    //print_r($exclude); 
    203305  } 
    204306 
     
    252354  //check in new tarball and module.xml 
    253355  run_cmd('svn ci ../../release/' . $vars['rver'] . '/' . $filename . ' ' . $mod_dir  
    254           . ' -m"Module package script: ' . $rawname . ' ' . $ver . '"'); 
     356          . ' -m"[Module package script: ' . $rawname . ' ' . $ver . '] ' . $vars['msg'] . '"'); 
    255357           
    256358  //cleanup any remaining files 
    257359  foreach($vars['rm_files'] as $f) { 
    258360    if (file_exists($f)) { 
    259       //run_cmd('rm -rf ' . $f); 
    260     } 
    261   } 
    262   echo $mod . ' version ' . $ver . ' has been sucsessfuly packaged!' . PHP_EOL; 
    263    
     361      run_cmd('rm -rf ' . $f); 
     362    } 
     363  } 
     364  $final_status[$mod] = $mod . ' version ' . $ver . ' has been sucsessfuly packaged!' . PHP_EOL; 
     365  echo $final_status[$mod]; 
     366   
     367
     368 
     369//print report 
     370echo PHP_EOL . PHP_EOL . PHP_EOL . PHP_EOL . PHP_EOL; 
     371echo 'Package Script Report:' . PHP_EOL; 
     372echo '---------------------' . PHP_EOL; 
     373foreach ($final_status as $mod => $status) { 
     374  echo $status; 
    264375} 
    265376 
     
    316427} 
    317428 
     429//auto-bump module version, bumps last part by defualt 
     430function package_bump_version($mod, $pos = '') { 
     431  global $mod_dir, $vars; 
     432  $xml = simplexml_load_file($mod_dir . '/module.xml'); 
     433  $ver = explode('.', (string) $xml->version); 
     434   
     435  //if $pos === true, reset it 
     436  if ($pos === true) { 
     437    $pos = ''; 
     438  } 
     439  //pick last part if requested part isn't found 
     440  if (!isset($ver[$pos - 1])) { 
     441    $pos = count($ver);  
     442  } 
     443  $pos = $pos - 1; //array start at 0, but people will count from 1. 
     444 
     445  //if we have only digits in this part, add 1 
     446  if (ctype_digit($ver[$pos])) { 
     447    $ver[$pos] = $ver[$pos] + 1; 
     448  } else {//find last groupe of digits and +1 them 
     449    $num = preg_split('/[0-9]+$/', $ver[$pos], 1); 
     450    $replace = strrpos($ver[$pos], $num); 
     451    $num = $num[0] + 1; 
     452    $ver[$pos] = substr($ver[$pos], 0, $replace -1) . $num; 
     453  } 
     454   
     455  echo 'Bumping ' . $mod . '\s verison to ' . (string) $xml->version . PHP_EOL; 
     456   
     457  $xml->version = implode('.', $ver); 
     458   
     459  if ($vars['debug'] || $vars['verbose']) { 
     460    echo 'Writing to ' . $mod_dir . '/module.xml :' . PHP_EOL; 
     461    echo $xml->asXML(); 
     462  } 
     463  if (!$vars['debug']) { 
     464    file_put_contents($mod_dir . '/module.xml', $xml->asXML()); 
     465  } 
     466 
     467  return true; 
     468} 
     469 
     470//update module's changelog 
     471function package_update_changelog($mod, $msg) { 
     472  global $mod_dir, $vars, $ver; 
     473  $xml = simplexml_load_file($mod_dir . '/module.xml'); 
     474  $log = explode("\n", (string) $xml->changelog); 
     475   
     476  //firt element is ususally blank, remove it 
     477  array_shift($log); 
     478   
     479  //prune to last 5 entreis 
     480  $log = array_slice($log, 0, 4); 
     481  array_unshift($log, $ver . ' ' . $msg); 
     482   
     483  echo 'Adding to ' . $mod . '\s changelog: ' . $ver . ' ' . $msg; 
     484   
     485  $xml->changelog = "\n\t\t" . trim(implode("\n", $log)) . "\n\t"; 
     486   
     487  if ($vars['verbose']) { 
     488    echo 'Writing to ' . $mod_dir . '/module.xml :' . PHP_EOL; 
     489  } 
     490  if ($vars['debug']) { 
     491    echo 'Writing to ' . $mod_dir . '/module.xml :' . PHP_EOL; 
     492    echo $xml->asXML(); 
     493  } 
     494  if (!$vars['debug']) { 
     495    file_put_contents($mod_dir . '/module.xml', $xml->asXML()); 
     496  } 
     497 
     498  return true; 
     499} 
     500 
    318501// if $duplex set to true and in debug mode, it will echo the command AND run it 
    319502function run_cmd($cmd, &$outline='', $quiet = false, $duplex = false) { 
     
    368551} 
    369552 
     553//show help menu 
     554function package_show_help($short = false) { 
     555  $final = ''; 
     556  $ret[] = 'Package.php'; 
     557  $ret[] = '-----------'; 
     558  $ret[] = ''; 
     559  if ($short) { 
     560    $ret[] = 'SHORT OPS HAVE BEEN DEPRICATED - PLEASE USE ONLY LONG OPTS!'; 
     561  } 
     562  $ret[] = 'Short options MUST come after all the long options, or the long options will be ignored'; 
     563  $ret[] = ''; 
     564   
     565  //args 
     566  $ret[] = array('--bump', 'Bump a modules version. You can specify the "octet" by adding a position ' 
     567        . 'I.e. --bump=2 will turn 3.4.5.6 in to 3.5.5.6. Leaving the position blank will bump the last "octet"'); 
     568  $ret[] = array('--debug = false', 'Debug only - just run through the command but don\'t make any changes'); 
     569  $ret[] = array('--checkphp = true', 'Run PHP syntaxt check on php files (php -l <file name>)'); 
     570  $ret[] = array('--help', 'Show this menu and exit'); 
     571  $ret[] = array('--log', 'Update module.xml\'s changelog.'); 
     572  $ret[] = array('-m, --modules', 'Modules to be packaged. One module per --module argument, or * for all'); 
     573  $ret[] = array('--msg', 'Optional commit message.'); 
     574  $ret[] = array('--re', 'A ticket number to be referenced in all checkins (i.e. "re #627...")'); 
     575  $ret[] = array('--verbose', 'Run with extra verbosity and print each command before it\'s executed'); 
     576   
     577  $ret[] = ''; 
     578   
     579  //generate formated help message 
     580  foreach ($ret as $r) { 
     581    if (is_array($r)) { 
     582      //pad the option 
     583      $option = '  ' . str_pad($r[0], 20); 
     584       
     585      //explode the definition to manageable chunks 
     586      $def = explode('§', wordwrap($r[1], 55, "§", true)); 
     587       
     588      //split definition in to chucks  
     589      //and pad the with whitespace 20 chars to the left stating from the second line 
     590      if (count($def) > 1) { 
     591        $first = array_shift($def); 
     592        foreach ($def as $my => $item) { 
     593          $def[$my] = str_pad('', 22) . $item . PHP_EOL; 
     594        } 
     595      } elseif (count($def) == 1) { 
     596        $first = implode($def); 
     597        $def = array(); 
     598      } else { 
     599        $first = ''; 
     600        $def = array(); 
     601      } 
     602       
     603      $definition = $first . PHP_EOL . implode($def); 
     604      $final .= $option . $definition; 
     605    } else { 
     606      $final .=  $r . PHP_EOL; 
     607    } 
     608  } 
     609  return $final; 
     610} 
    370611?>