bldsystemtools/commonbldutils/pushComp.pl
branchRCL_3
changeset 24 d90029decf65
parent 20 a9d4531388d0
child 33 54aa4a06a075
child 34 5e522efbae7b
equal deleted inserted replaced
20:a9d4531388d0 24:d90029decf65
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 #
       
    16 #!/usr/bin/perl
       
    17 use strict;
       
    18 use LWP::UserAgent;
       
    19 use Getopt::Long;
       
    20 
       
    21 
       
    22 my ($iComp, $iLoc, $iType) = ProcessCommandLine();
       
    23 my $iVersion;
       
    24 if ($iType eq "green")
       
    25 {
       
    26 	$iVersion = GetLatestGreenBuild($iComp)
       
    27 }
       
    28 elsif($iType eq "latest")
       
    29 {
       
    30 	$iVersion = GetLatestBuild($iComp);  
       
    31 }
       
    32 elsif ($iType =~ /DP/i)
       
    33 {
       
    34 	if ($iType =~ /_DeveloperProduct/i)
       
    35 	{
       
    36 		$iVersion = $iType;
       
    37 	}
       
    38 	else
       
    39 	{
       
    40 		$iVersion = $iType."_DeveloperProduct";
       
    41 	}
       
    42 }
       
    43 else{
       
    44 	$iVersion = $iType;
       
    45 }
       
    46 chomp($iVersion);
       
    47 
       
    48 my $pushreloutput = `pushrel -vv $iComp $iVersion $iLoc`;
       
    49 if (($pushreloutput =~ /^Copying $iComp $iVersion to/) || ($pushreloutput =~ /already present/)){
       
    50   print $pushreloutput;
       
    51 }else{
       
    52   print "ERROR: could not pushrel $iComp $iVersion - $pushreloutput\n";
       
    53 }
       
    54 
       
    55 
       
    56 
       
    57 # LRtrim
       
    58 #
       
    59 # Description
       
    60 # This function removes the space on the left and right
       
    61 sub LRtrim( $ ) {
       
    62   my $result = shift ;
       
    63   $result =~ s/^\s+// ;
       
    64   $result =~ s/\s+$// ;
       
    65   return $result ;
       
    66 }
       
    67 
       
    68 
       
    69 sub GetLatestBuild( $ ) {
       
    70   my $iBaselineComponentName = shift ;
       
    71   $iBaselineComponentName = LRtrim($iBaselineComponentName);
       
    72   my $latestbuild = "nobuild";
       
    73   my @AllBuilds = `latestver -a $iBaselineComponentName`; 
       
    74   
       
    75   foreach my $build ( @AllBuilds  ) {
       
    76     my $status = BragFromAutobuild2HttpInterface( $build , $iBaselineComponentName  );
       
    77     if ( ( lc( $status ) eq "green" ) or ( lc( $status ) eq "amber" )  ){
       
    78       $latestbuild = $build ;
       
    79       last ;
       
    80     }
       
    81   }
       
    82   return $latestbuild ;
       
    83 }
       
    84 
       
    85 
       
    86 sub GetLatestGreenBuild( $ ) {
       
    87   my $iBaselineComponentName = shift ;
       
    88   $iBaselineComponentName = LRtrim($iBaselineComponentName);
       
    89   my $greenbuild = "amberbuild";
       
    90   my @AllBuilds = `latestver -a $iBaselineComponentName`; 
       
    91   foreach my $build ( @AllBuilds  ) {
       
    92 	$build = LRtrim($build);
       
    93     my $status = BragFromAutobuild2HttpInterface( $build , $iBaselineComponentName );
       
    94     if ( lc( $status ) eq "green" ) {
       
    95       $greenbuild = $build ;
       
    96       last ;
       
    97     }
       
    98   }
       
    99   return  $greenbuild ; # buildnumber or "amberbuild"
       
   100 }
       
   101 
       
   102 
       
   103 
       
   104 # Usage
       
   105 # Just call the sub-route called BragFromAutobuild2HttpInterface like this
       
   106 # my $status = BragFromAutobuild2HttpInterface("M04735_Symbian_OS_v9.5" , "gt_techview_baseline");
       
   107 # my $status = BragFromAutobuild2HttpInterface("DP00454_DeveloperProduct" , "sf_tools_baseline");
       
   108 # $status should be green or amber etc.
       
   109 
       
   110 ## @fn BragFromAutobuild2HttpInterface($sVer)
       
   111 #
       
   112 # Queries the HTTP interface to Autobuild2 DB to determine the BRAG status of a CBR.
       
   113 #
       
   114 # @param sVer string, CBR for which the BRAG status is to be determined.
       
   115 #
       
   116 # @return string, BRAG status of the queried CBR. "TBA" if BRAG was indeterminable.
       
   117 
       
   118 sub BragFromAutobuild2HttpInterface( $  $ )
       
   119 {
       
   120 	my $sVer = shift ;
       
   121     $sVer = LRtrim($sVer);
       
   122 	my $iBaselineComponentName = shift ;
       
   123     $iBaselineComponentName = LRtrim($iBaselineComponentName);
       
   124     my $sBrag = "TBA";
       
   125 	my $sSnapshot = "";
       
   126 	my $sProduct = "";
       
   127     if ($sVer =~ /\_DeveloperProduct/i) 
       
   128     {
       
   129 		#DP00420_DeveloperProduct
       
   130     	if ($sVer =~ /([\w\.]+)\_DeveloperProduct/i)
       
   131         {
       
   132             $sSnapshot = $1;
       
   133             $sProduct = "DP";
       
   134         }
       
   135         else
       
   136         {
       
   137             return $sBrag; # i.e. "TBA"
       
   138         }	
       
   139     }    
       
   140     
       
   141 	my $parameters = "snapshot=$sSnapshot&product=$sProduct";
       
   142 	# Alternative method of getting the BRAG status - use the HTTP interface to Autobuild
       
   143 	my $sLogsLocation = "http://intweb:8080/esr/query?$parameters";
       
   144 	
       
   145 	my $roUserAgent = LWP::UserAgent->new;
       
   146 	my $roResponse = $roUserAgent->get($sLogsLocation);
       
   147  
       
   148 	if ($roResponse->is_success and $roResponse->content =~ /BRAG\s*\=\s*([a-z|A-Z]+)/)
       
   149 	{
       
   150 		$sBrag = $1;
       
   151 		$sBrag =~ s/\s//g;  # remove any whitespace padding
       
   152 		return $sBrag;
       
   153 	}
       
   154 	else
       
   155 	{		
       
   156 		return $sBrag; # i.e. "TBA"
       
   157 	}
       
   158 }
       
   159 
       
   160 
       
   161 
       
   162 # ProcessCommandLine
       
   163 #
       
   164 # Inputs
       
   165 #
       
   166 # Outputs
       
   167 # $iComp - Name of the component to push
       
   168 # $iLoc -  Remote site reltools.ini location
       
   169 #
       
   170 # Description
       
   171 # This function processes the commandline
       
   172 sub ProcessCommandLine {
       
   173 
       
   174   my ($iHelp, $iComp, $iLoc, $iLatest, $iGreen, $iVer);
       
   175   GetOptions('h' => \$iHelp, 'c=s' => \$iComp, 'r=s' => \$iLoc, 'g' => \$iGreen, 'l' => \$iLatest, 'version=s'=>\$iVer);
       
   176 
       
   177   if (($iHelp) || (!defined $iComp) || (!defined $iLoc) || ($iVer && $iLatest)|| ($iVer && $iGreen)| ($iGreen && $iLatest))
       
   178   {
       
   179     &Usage();
       
   180   } 
       
   181   
       
   182   my $iType = ($iGreen)? "green" : "latest";
       
   183   $iType = ($iVer)? $iVer:$iType;
       
   184 
       
   185   return($iComp,$iLoc,$iType);
       
   186 }
       
   187 
       
   188 # Usage
       
   189 #
       
   190 # Output Usage Information.
       
   191 #
       
   192 sub Usage {
       
   193   print <<USAGE_EOF;
       
   194 
       
   195   Usage: pushComp.pl [Args/options]
       
   196 
       
   197   Args: (required)
       
   198   
       
   199   -c  [Component name]  Name of component to push 
       
   200   -r [Remote reltools.ini location] Remote site reltools.ini location (Target location reltools.ini file)
       
   201   -l Latest Build  or -g Latest Green Build or -v specify a build
       
   202   
       
   203   options:
       
   204 
       
   205   -h                    help
       
   206   
       
   207   Example Commandline
       
   208   pushComp.pl -c tools_testexecute -r C:\\epoc32\\relinfo\\reltools.ini -g
       
   209   pushComp.pl -c tools_testexecute -r C:\\epoc32\\relinfo\\reltools.ini -l
       
   210   pushComp.pl -c tools_testexecute -r C:\\epoc32\\relinfo\\reltools.ini -version DP00500
       
   211   
       
   212 
       
   213 USAGE_EOF
       
   214 	exit 1;
       
   215 }