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