bldsystemtools/commonbldutils/BxCopy.pl
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 # Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 # Script to get Source from Perforce
       
    15 # 
       
    16 #
       
    17 
       
    18 use strict;
       
    19 use Getopt::Long;
       
    20 
       
    21 use FindBin;
       
    22 use lib "$FindBin::Bin";
       
    23 use BxCopy;
       
    24 
       
    25 
       
    26 # Process the commandline
       
    27 my ($iSource, $iTarget, $iExclude, $iInclude, $iVerbose, $iNoAction) = ProcessCommandLine();
       
    28 
       
    29 # Get list of files
       
    30 my $iCopyFiles = &BxCopy::FilterDir($iSource,$iExclude,$iInclude);
       
    31 
       
    32 # Copy Function
       
    33 &BxCopy::CopyFiles($iSource, $iTarget, $iCopyFiles, $iVerbose, $iNoAction);
       
    34 
       
    35 
       
    36 # ProcessCommandLine
       
    37 #
       
    38 # Inputs
       
    39 #
       
    40 # Outputs
       
    41 #
       
    42 # Description
       
    43 # This function processes the commandline
       
    44 
       
    45 sub ProcessCommandLine {
       
    46   my ($iHelp, $iSource, $iTarget, @iExclude, @iInclude, $iVerbose, $iNoAction);
       
    47   GetOptions('h' => \$iHelp, 's=s' => \$iSource, 't=s' => \$iTarget, 'x=s' => \@iExclude, 'i=s' => \@iInclude, 'v' => \$iVerbose, 'n' => \$iNoAction);
       
    48 
       
    49   if (($iHelp) || (!defined $iSource) || (!defined $iTarget))
       
    50   {
       
    51     Usage();
       
    52   } elsif (! -d $iSource) {
       
    53     print "$iSource is not a directory\n";
       
    54     Usage();
       
    55   } elsif ( -d $iTarget) {
       
    56     print "$iTarget already exist\n";
       
    57     Usage();
       
    58   } else {
       
    59     # Remove any trailing \ or from dirs
       
    60     $iSource =~ s#[\\\/]$##;
       
    61     $iTarget =~ s#[\\\/]$##;
       
    62     # Make sure all the \ are /
       
    63     $iSource =~ s/\\/\//g;
       
    64     $iTarget =~ s/\\/\//g;
       
    65     return($iSource, $iTarget, \@iExclude, \@iInclude, $iVerbose, $iNoAction);
       
    66   }
       
    67 }
       
    68 
       
    69 # Usage
       
    70 #
       
    71 # Output Usage Information.
       
    72 #
       
    73 
       
    74 sub Usage {
       
    75   print <<USAGE_EOF;
       
    76 
       
    77   Usage: BxCopy.pl [options]
       
    78 
       
    79   options:
       
    80 
       
    81   -h         -- help
       
    82   -s  source -- source directory
       
    83   -t  target -- target directory
       
    84   -x  regexp -- exclude a reqular expression from the list of files
       
    85   -i  regexp -- include a regular expression in to the list of files
       
    86   -v         -- Verbose mode
       
    87   -n         -- No Copy
       
    88 
       
    89   Note:  The inclusion takes precedence over the exclusion.
       
    90   Note:  This will not overwrite files as target cannot exist.
       
    91 USAGE_EOF
       
    92   exit 1;
       
    93 }