bldsystemtools/commonbldutils/GetDPComp/GetDPComp.pm
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 
       
    18 package GetDPComp ;
       
    19 
       
    20 use strict;
       
    21 use LWP::UserAgent;
       
    22 use Getopt::Long;
       
    23 
       
    24 # LRtrim
       
    25 #
       
    26 # Description
       
    27 # This function removes the space on the left and right
       
    28 sub LRtrim( $ ) {
       
    29   my $result = shift ;
       
    30   $result =~ s/^\s+// ;
       
    31   $result =~ s/\s+$// ;
       
    32   return $result ;
       
    33 }
       
    34 
       
    35 sub GenerateComponentVersion( $  $ ) {
       
    36   my $inputVersion = shift ;
       
    37   $inputVersion = LRtrim($inputVersion);
       
    38   my $iBaselineComponentName = shift ;
       
    39   $iBaselineComponentName = LRtrim($iBaselineComponentName);
       
    40   my %ComponentVersion = ( );
       
    41   print "envsize -vv $iBaselineComponentName $inputVersion \n" ;
       
    42   my @envsizeoutput = `envsize -vv $iBaselineComponentName $inputVersion `;
       
    43   foreach my $line ( @envsizeoutput ) {
       
    44     if ($line =~ /^Adding up size of / ) {
       
    45       $line =~ s/^Adding up size of //;
       
    46       $line = LRtrim( $line ) ;
       
    47       my ($component, $release) = split(/\s+/, $line);
       
    48       $ComponentVersion{$component} = $release ;
       
    49     }
       
    50   }
       
    51   return  %ComponentVersion ; 
       
    52 }
       
    53 
       
    54 sub ValidateVersion( $ $ ) {
       
    55   my $inputVersion = shift ;
       
    56   $inputVersion = LRtrim($inputVersion);
       
    57   my $iBaselineComponentName = shift ;
       
    58   $iBaselineComponentName = LRtrim($iBaselineComponentName);
       
    59   my $retval = 1 ;
       
    60 
       
    61   if( (!defined $inputVersion) || ($inputVersion eq "" ) ){
       
    62     $retval = 0 ;
       
    63     print "\nERROR: No valid version specified. \n";
       
    64   }elsif ( CheckBuild( $inputVersion, $iBaselineComponentName ) == 1 ){
       
    65     print "\nUser specified build: $inputVersion is using. \n";
       
    66   }elsif ( lc($inputVersion) eq "latest") {  
       
    67     $inputVersion = GetLatestBuild( $iBaselineComponentName ); 
       
    68     $inputVersion = LRtrim( $inputVersion );
       
    69     if ($inputVersion eq "nobuild" )  {
       
    70       $retval = 0 ;
       
    71       print "\nERROR: No build available. \n";
       
    72     } else {
       
    73       print "\nLatest build: $inputVersion is using.\n";
       
    74     }
       
    75   }elsif ( lc($inputVersion) eq "green" ){
       
    76     $inputVersion = GetLatestGreenBuild( $iBaselineComponentName ) ;
       
    77     $inputVersion = LRtrim( $inputVersion );
       
    78     if ($inputVersion eq "amberbuild" )  {
       
    79       $retval = 0 ;
       
    80       print "\nERROR: No green build available. \n";
       
    81     } else {  
       
    82       print "\nLatest green build: $inputVersion is using.\n";
       
    83     }
       
    84   }else {    
       
    85     $retval = 0 ;
       
    86     print "\nERROR: No Such Build: $inputVersion .\n";
       
    87   }
       
    88   return ( $inputVersion, $retval) ;
       
    89 }
       
    90 
       
    91 sub CheckBuild( $  $ ) {
       
    92   my $iVer = shift ;
       
    93   $iVer = LRtrim( $iVer );
       
    94   my $iBaselineComponentName = shift ;
       
    95   $iBaselineComponentName = LRtrim($iBaselineComponentName);
       
    96   my $iRet = 0 ;
       
    97   my @AllVersions = `latestver -a $iBaselineComponentName`; 
       
    98 
       
    99   foreach my $build ( @AllVersions ) {
       
   100     $build = LRtrim( $build );
       
   101     if (lc( $build ) eq lc( $iVer ) ) {
       
   102       $iRet = 1 ;
       
   103       last ;
       
   104     }
       
   105   }
       
   106   return $iRet ;
       
   107 }
       
   108 
       
   109 sub GetLatestBuild( $ ) {
       
   110   my $iBaselineComponentName = shift ;
       
   111   $iBaselineComponentName = LRtrim($iBaselineComponentName);
       
   112   my $latestbuild = "nobuild";
       
   113   my @AllBuilds = `latestver -a $iBaselineComponentName`; 
       
   114   
       
   115   foreach my $build ( @AllBuilds  ) {
       
   116     my $status = BragFromAutobuild2HttpInterface( $build , $iBaselineComponentName  );
       
   117     if ( ( lc( $status ) eq "green" ) or ( lc( $status ) eq "amber" )  ){
       
   118       $latestbuild = $build ;
       
   119       last ;
       
   120     }
       
   121   }
       
   122   return $latestbuild ;
       
   123 }
       
   124 
       
   125 sub GetLatestGreenBuild( $ ) {
       
   126   my $iBaselineComponentName = shift ;
       
   127   $iBaselineComponentName = LRtrim($iBaselineComponentName);
       
   128   my $greenbuild = "amberbuild";
       
   129   my @AllBuilds = `latestver -a $iBaselineComponentName`; 
       
   130 
       
   131   foreach my $build ( @AllBuilds  ) {
       
   132     my $status = BragFromAutobuild2HttpInterface( $build , $iBaselineComponentName );
       
   133     if ( lc( $status ) eq "green" ) {
       
   134       $greenbuild = $build ;
       
   135       last ;
       
   136     }
       
   137   }
       
   138   return  $greenbuild ; # buildnumber or "amberbuild"
       
   139 }
       
   140 
       
   141 # Usage
       
   142 # Just call the sub-route called BragFromAutobuild2HttpInterface like this
       
   143 # my $status = BragFromAutobuild2HttpInterface("M04735_Symbian_OS_v9.5" , "gt_techview_baseline");
       
   144 # my $status = BragFromAutobuild2HttpInterface("DP00454_DeveloperProduct" , "sf_tools_baseline");
       
   145 # $status should be green or amber etc.
       
   146 
       
   147 ## @fn BragFromAutobuild2HttpInterface($sVer)
       
   148 #
       
   149 # Queries the HTTP interface to Autobuild2 DB to determine the BRAG status of a CBR.
       
   150 #
       
   151 # @param sVer string, CBR for which the BRAG status is to be determined.
       
   152 #
       
   153 # @return string, BRAG status of the queried CBR. "TBA" if BRAG was indeterminable.
       
   154 
       
   155 sub BragFromAutobuild2HttpInterface( $  $ )
       
   156 {
       
   157 	my $sVer = shift ;
       
   158     $sVer = LRtrim( $sVer );
       
   159 	my $iBaselineComponentName = shift ;
       
   160     $iBaselineComponentName = LRtrim($iBaselineComponentName);
       
   161     my $sBrag = "TBA";
       
   162 	my $sSnapshot = "";
       
   163 	my $sProduct = "";
       
   164     if (( lc( $iBaselineComponentName ) eq "sf_tools_baseline" ) or ( lc( $iBaselineComponentName ) eq "developer_product_baseline" ) ) 
       
   165     {
       
   166     	if ( $sVer =~ /([\w\.]+)\_DeveloperProduct/i )
       
   167         {
       
   168             $sSnapshot = $1;
       
   169             $sProduct = "DP";
       
   170         }
       
   171         else
       
   172         {
       
   173             return $sBrag; # i.e. "TBA"
       
   174         }	
       
   175     }elsif  (( lc( $iBaselineComponentName ) eq "gt_techview_baseline" ) or ( lc( $iBaselineComponentName ) eq "gt_only_baseline" ) ) 
       
   176     {
       
   177     	if ( $sVer =~ /([\w\.]+)\_Symbian_OS_v([\w\.]+)/i )
       
   178         {
       
   179 		#print $1, "\n", $2, "\n";
       
   180             $sSnapshot = $1;
       
   181             $sProduct = $2;
       
   182         }
       
   183         else
       
   184         {
       
   185             return $sBrag; # i.e. "TBA"
       
   186         }
       
   187     }    
       
   188     
       
   189 	my $parameters = "snapshot=$sSnapshot&product=$sProduct";
       
   190 	# Alternative method of getting the BRAG status - use the HTTP interface to Autobuild
       
   191 	my $sLogsLocation = "http://intweb:8080/esr/query?$parameters";
       
   192 	
       
   193 	my $roUserAgent = LWP::UserAgent->new;
       
   194 	my $roResponse = $roUserAgent->get($sLogsLocation);
       
   195  
       
   196 	if ($roResponse->is_success and $roResponse->content =~ /\=\=\s*BRAG\s*\=\s*([a-z|A-Z]+)/)
       
   197 	{
       
   198 		$sBrag = $1;
       
   199 		$sBrag =~ s/\s//g;  # remove any whitespace padding
       
   200 		return $sBrag;
       
   201 	}
       
   202 	else
       
   203 	{		
       
   204 		return $sBrag; # i.e. "TBA"
       
   205 	}
       
   206 }
       
   207 
       
   208 
       
   209 1;