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