bldsystemtools/commonbldutils/ExportCBR.pl
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 # Copyright (c) 2005-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 export CBRs to the ODC
       
    15 # 
       
    16 #
       
    17 
       
    18 use strict;
       
    19 use Getopt::Long;
       
    20 use File::Copy;
       
    21 use File::Path;
       
    22 
       
    23 use FindBin;
       
    24 use lib $FindBin::Bin; # Pickup local modules
       
    25 
       
    26 use record_delivery;
       
    27 
       
    28 # location of text file on devbuilds
       
    29 my $aODCBuilds = "\\\\builds01\\odcbuilds\\CBR_Export";
       
    30 
       
    31 # location of templates and email cfg
       
    32 my $aSupportLoc = "\\\\builds01\\devbuilds\\BuildTeam\\record_delivery";
       
    33 
       
    34 # Process the commandline
       
    35 my (%args) = ProcessCommandLine();
       
    36 # run the export
       
    37 &Main(%args);
       
    38 
       
    39 # ProcessCommandLine
       
    40 #
       
    41 # Description
       
    42 # This function processes the commandline
       
    43 
       
    44 sub ProcessCommandLine
       
    45 {
       
    46 	my ($iHelp);
       
    47 	
       
    48 	my ($iSnapshot, $iDir, $iProduct, $iNotify, @iComponents, @iTemplates);
       
    49 	
       
    50 	GetOptions('h' => \$iHelp, 'c=s' => \@iComponents, 's=s' => \$iSnapshot, 'd=s' => \$iDir, 'p=s' => \$iProduct, 'n' => \$iNotify, 't=s' => \@iTemplates);
       
    51 	
       
    52 	if (($iHelp) || (scalar(@iComponents) < 1) || (!defined $iSnapshot) || (!defined $iDir) || (!defined $iProduct))
       
    53 	{
       
    54 		Usage();
       
    55 	}
       
    56 	
       
    57 	my %args = ('Snapshot' => $iSnapshot, 'Dir' => $iDir, 'Product' => $iProduct, 'Notify' => $iNotify,
       
    58 				'Components' => [@iComponents], 'Templates' => [@iTemplates]);
       
    59 	
       
    60 	return %args;
       
    61 }
       
    62 
       
    63 # Usage
       
    64 #
       
    65 # Output Usage Information.
       
    66 #
       
    67 
       
    68 sub Usage
       
    69 {
       
    70 	print <<USAGE_EOF;
       
    71 	
       
    72 	Usage: ExportCBR.pl [switches]
       
    73 	
       
    74 	[Switches]
       
    75 	-c component (e.g gt_techview_baseline) [multiple allowed]
       
    76 	-s snapshot number (e.g. 03445_Symbian_OS_v9.1)
       
    77 	-d Directory of epoc32 (e.g. M: or CBRGT)
       
    78 	-p Product (e.g.9.1)
       
    79 	
       
    80 	[Optional]
       
    81 	-h help
       
    82 	-n Notify ODC by logging that the export has been completed
       
    83 	-t Templates for recording deliveries [multiple allowed]
       
    84 
       
    85 USAGE_EOF
       
    86 	exit 1;
       
    87 }
       
    88 
       
    89 # Main
       
    90 #
       
    91 # Runs the export of CBRs
       
    92 #
       
    93 sub Main
       
    94 {
       
    95 	my (%args) = @_;
       
    96 	
       
    97 	my $aExportCount;
       
    98 	
       
    99 	# Check to see if this is a TestBuild by looking at the Publish Location Environment variable
       
   100 	# Do no export if a Test Build
       
   101 	if ($ENV{'PublishLocation'} =~ /Test_Builds$/i)
       
   102 	{
       
   103 		print "Not exporting the Test Build\n";
       
   104 		exit 0;
       
   105 	}
       
   106 
       
   107 	# Open Log file for writing
       
   108 	my $logname = $ENV{'LogsDir'}."\\Export_CBR.log";
       
   109 	open (LOGFILE, ">> $logname");
       
   110 	
       
   111 	foreach my $aComponent(@{$args{'Components'}})
       
   112   {
       
   113 		my $line;
       
   114 		
       
   115 		print "\nAbout to export $aComponent ".$args{'Snapshot'}." from ".$args{'Dir'}."\n";
       
   116 
       
   117 		my $iCmd = "exportenv -vv ".$aComponent." ".$args{'Snapshot'}." 2>&1";
       
   118 		print LOGFILE "\nCommand: $iCmd\n";
       
   119 		open (CMD, "$iCmd |");
       
   120 		while ($line = <CMD>)
       
   121 		{
       
   122 			print LOGFILE $line;
       
   123 			# Count the number of components exported
       
   124 			if ( $line =~ /successfully exported/)
       
   125 			{
       
   126 				$aExportCount++;
       
   127 			}
       
   128 		}
       
   129 		# Write time stamp to logfile
       
   130 		print LOGFILE $aComponent." exportenv finsihed at ".localtime()."\n"; 
       
   131 		print "\nExport Complete\n";
       
   132 	}
       
   133 	
       
   134 	# Record export of components
       
   135 	if (($aExportCount >0) && (scalar(@{$args{'Templates'}}) > 0))
       
   136 	{
       
   137 		my $delivery = record_delivery->new(config_file => $aSupportLoc."\\email.cfg");
       
   138 		foreach my $iTemplate (@{$args{'Templates'}})
       
   139 		{
       
   140                          eval {			
       
   141 				$delivery->send(Template => $aSupportLoc."\\".$iTemplate, BuildNumber => $args{'Snapshot'}, BuildShortName => $args{'Product'});
       
   142                         };
       
   143                         if($@)
       
   144                         {
       
   145 				print LOGFILE "ERROR: Failed to record delivery using template ".$aSupportLoc."\\".$iTemplate."\n";
       
   146                         } else
       
   147 			{			
       
   148 				print LOGFILE "Sending email to record delivery using template ".$aSupportLoc."\\".$iTemplate."\n";
       
   149 			}
       
   150 		}
       
   151 	}
       
   152 	
       
   153 	close LOGFILE;
       
   154 
       
   155 	if ((defined$args{'Notify'}) && ($aExportCount >0))
       
   156 	{
       
   157 		&copyFile($logname, $args{'Snapshot'}, $args{'Product'});
       
   158 	}
       
   159 	
       
   160 	
       
   161 	
       
   162 	exit 0;
       
   163 }
       
   164 
       
   165 # copyFile
       
   166 #
       
   167 # Copies a file with the snapshot to devbuilds
       
   168 sub copyFile
       
   169 {
       
   170 	my ($logname, $aSnapShot, $aProduct) = @_;
       
   171 
       
   172 	# check there is an "Export_CBR.log" present to be copied across before deleting the previous one(s).
       
   173 	unless ( -e $logname )
       
   174 	{
       
   175 		print "WARNING: $logname not found when trying to copy to $aODCBuilds\\$aSnapShot.txt $!\n";
       
   176 		return;
       
   177 	}
       
   178 
       
   179 	# now delete the older text files
       
   180 	print "\nCMD: del /F /Q $aODCBuilds\\*$aProduct.txt\n";
       
   181 	system("del /F /Q $aODCBuilds\\*$aProduct.txt");
       
   182 	print "REMARK: deleting old notify files failed with return of ".($?>>8)."($?)\n" if ($? > 0);
       
   183 	
       
   184 	# and copy the new file
       
   185 	print "\ncopying $logname to $aODCBuilds\\$aSnapShot.txt\n";
       
   186 	mkpath($aODCBuilds) if (! -d $aODCBuilds);
       
   187 	copy($logname, "$aODCBuilds\\$aSnapShot.txt") || print "WARNING: Copy of $logname to $aODCBuilds\\$aSnapShot.txt failed $!\n";
       
   188 }