Changeset 185 for trunk/trax/trax.php

Show
Ignore:
Timestamp:
03/23/06 09:45:48 (6 years ago)
Author:
haas
Message:

more adaptable

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/trax/trax.php

    r183 r185  
    11<?php 
    22/** 
    3  *  Copy Pear directory data_dir/PHPonTrax/data/ to user's work area 
     3 *  Create Trax application work area 
    44 * 
    55 *  (PHP 5) 
     
    1212 */ 
    1313 
     14/** 
     15 *  Define where to find files to copy to the work area 
     16 * 
     17 *  Set automatically by the Pear installer when you install Trax with 
     18 *  the <b>pear install</b> command.  If you are prevented from using 
     19 *  <b>pear install</b>, change "@DATA-DIR@/PHPonTrax" by hand to the 
     20 *  full filesystem path of the location where you installed the Trax 
     21 *  distribution  
     22 */ 
     23define("SOURCE_DIR", "@DATA-DIR@/PHPonTrax/data/"); 
     24 
    1425function trax() { 
    15     //  Set default destination directory 
    16     $dstdir = "./"; 
    1726 
    1827    //  Get command line argument, if any 
    19     if (array_key_exists('argc',$GLOBALS) && ($GLOBALS['argc'] > 1)) { 
    20  
    21         //  Check for excess arguments 
    22         if ($GLOBALS['argc'] > 2) { 
    23             echo "unrecognized command argument ".$GLOBALS['argv'][2]."\n"; 
    24             return; 
    25         } 
    26  
    27         //  Destination directory on command line 
    28         $dstdir = $GLOBALS['argv'][1]; 
    29  
    30         //  Guarantee it ends with '/' 
    31         if (substr($dstdir,-1,1) != '/') { 
    32             $dstdir .= '/'; 
    33         } 
    34         if (!create_dir($dstdir)) { 
    35             return; 
    36         } 
    37     } 
    38     $srcdir = "@DATA-DIR@/PHPonTrax/data/"; 
     28    if (!array_key_exists('argc',$GLOBALS) 
     29        || ($GLOBALS['argc'] < 2)) { 
     30        usage();                // print Usage message and exit 
     31    } 
     32 
     33    //  Check for excess arguments 
     34    if ($GLOBALS['argc'] > 2) { 
     35        echo "unrecognized command argument ".$GLOBALS['argv'][2]."\n"; 
     36        usage(); 
     37    } 
     38 
     39    //  Destination directory on command line 
     40    $dstdir = $GLOBALS['argv'][1]; 
     41 
     42    //  Guarantee it ends with '/' 
     43    if (substr($dstdir,-1,1) != '/') { 
     44        $dstdir .= '/'; 
     45    } 
     46    if (!create_dir($dstdir)) { 
     47        return; 
     48    } 
     49 
     50    $srcdir = SOURCE_DIR; 
    3951    //  copy source directory to destination directory 
    4052    copy_dir($srcdir,$dstdir); 
     
    4355/** 
    4456 *  Copy a directory with all its contents 
     57 * 
     58 *  When a file whose filename ends '.log' is created, its permissions 
     59 *  are set to be world writable. 
    4560 *  @param string $src_path  Path to source directory 
    4661 *  @param string $dst_path  Path to destination directory 
     
    108123                return false; 
    109124            } 
     125 
     126            //  Log files need to be world writeable 
     127            if (substr($src_file,-4,4) == '.log') { 
     128                chmod($dst_path . $src_file, 0666); 
     129            } 
    110130            echo  "$dst_path$src_file created\n"; 
    111131        } else { 
     
    170190 
    171191/** 
     192 *  Output a Usage message and exit 
     193 */ 
     194function usage() { 
     195    echo <<<END 
     196Usage: @BIN-DIR@/trax /path/to/your/app 
     197 
     198Description: 
     199    The 'trax' command creates a new Trax application with a default 
     200    directory structure and configuration at the path you specify. 
     201 
     202Example: 
     203    trax /var/www/html 
     204 
     205    This generates a skeletal Trax installation in /var/www/html. 
     206    See the README in the newly created application to get going. 
     207 
     208END; 
     209    exit; 
     210} 
     211 
     212/** 
    172213 *  Main program 
    173214 */