bldsystemtools/commonbldutils/GenResult/Changelists.pm
branchRCL_3
changeset 5 d90029decf65
parent 4 a9d4531388d0
child 6 5e522efbae7b
equal deleted inserted replaced
4:a9d4531388d0 5:d90029decf65
     1 # Copyright (c) 2003-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 that return a list of Perforce Change lists that are associated to a build snapshot.
       
    15 # 
       
    16 #
       
    17 package Changelists;
       
    18 use DBI;
       
    19 my $dbh; #connection handle
       
    20 sub connectDB()
       
    21 {
       
    22   my $dBase = "autobuild2";
       
    23   my $serverPort = "intweb:3306";
       
    24   my $user = "autobuild2";
       
    25   my $password = "autobuild2";
       
    26   $dbh->disconnect if ($dbh); #disconnect if already connected
       
    27   $dbh = DBI->connect("DBI:mysql:$dBase:$serverPort", $user, $password, {PrintError => 0, RaiseError => 0}); # should use a username which has read-only credentials only.
       
    28   if (!$dbh)
       
    29   {
       
    30     print "Cannot connect to the AutoBuild2 server:$DBI::errstr\n";
       
    31     exit;
       
    32   }
       
    33   else
       
    34   {
       
    35     print "Connected to AutoBuild\n";
       
    36   }
       
    37 }
       
    38 
       
    39 
       
    40 sub queryHandler #handle querying the database.
       
    41 {
       
    42   my $query = shift;
       
    43   my $handle;
       
    44   $handle = $dbh->prepare($query);
       
    45   $handle->execute;
       
    46   if($handle->err())
       
    47   {
       
    48     Logit(2,"could not execute Query:".$handle->errstr());
       
    49     if ($handle->errstr() =~ m/(Lost connection|MySQL server has gone away)/i) #sometimes the connection to server is lost, 
       
    50     {
       
    51       Logit(0,"Lost connection, ".$handle->errstr());
       
    52       exit;
       
    53     }
       
    54   }
       
    55   return $handle;
       
    56 }
       
    57 
       
    58 my $snapshot = $ENV{SnapshotNumber};
       
    59 my $buildShortName = $ENV{BuildShortName};
       
    60 sub main {
       
    61 	
       
    62 	print "$snapshot \t $buildShortName\n";
       
    63 	my $query = "select distinct(sub3.changelist), snap.name as Name, sub3.description as Description
       
    64 	from codeline, Submission as sub, Submission as sub3
       
    65 		left join Snapshot    as snap  on (snap.Submission_id  = sub.id )
       
    66 		left join Build       as bld   on (bld.Snapshot_id     = snap.id)
       
    67 		left join Spec        as spec  on (bld.Spec_id         = spec.id)
       
    68 		left join Product     as prod  on (spec.Product_id     = prod.id)
       
    69 		left join Build       as bld2  on (bld2.id             = bld.BCPrevious_id)
       
    70 		left join Snapshot    as snap2 on (bld2.Snapshot_id    = snap2.id)
       
    71 		left join Submission  as sub2  on (snap2.Submission_id = sub2.id)
       
    72 	where snap.name = \"$snapshot\" and prod.build_short_name=\"$buildShortName\" and sub3.Codeline_id = (SELECT codeline_id FROM `spec` , codeline cl where Product_id=(select id from product where build_short_name = \"$buildShortName\") and pool_id = \"1\" and cl.name = \"MCLsfRO\" and spec.codeline_id= cl.id and end_date > CURDATE() ORDER by spec.id LIMIT 1) and sub3.changelist between sub2.changelist and sub.changelist order by sub3.changelist;";
       
    73 
       
    74 	&connectDB();
       
    75 	my $ClInfo = &queryHandler($query);
       
    76 	my @AllCls = ();
       
    77 	my %CLhash = ();
       
    78 	while (my $Data = $ClInfo->fetchrow_hashref)
       
    79 	{
       
    80 		my @Cl = ();
       
    81 		my $changelist = ${$Data}{'changelist'};
       
    82 		my ($submitter) = ${$Data}{'Description'} =~ /<detail submitter=\s*\"(.*?)\"/;
       
    83 		my ($team) = ${$Data}{'Description'} =~ /<detail team=\s*\"(.*?)\"/;
       
    84 		my ($sub_time) = ${$Data}{'Description'} =~ /<detail submissionTime=\s*\"(.*?)\"/;
       
    85 		${$Data}{'Description'} =~ s/\n/##/g;
       
    86 		my ($desc) = ${$Data}{'Description'} =~ /<EXTERNAL>####(.*?)####<\/EXTERNAL>/i;
       
    87 		$desc =~ s/##/\n/g;
       
    88 		$CLhash{$changelist}{'submitter'} = $submitter;
       
    89 		$CLhash{$changelist}{'team'} = $team;
       
    90 		$CLhash{$changelist}{'sub_time'} = $sub_time;
       
    91 		$CLhash{$changelist}{'desc'} = $desc;
       
    92 		#~ print "#################${$Data}{'changelist'}#####################\n";
       
    93 		#~ print "$submitter\t$team\t$sub_time\n$desc\n";
       
    94 	}
       
    95 	return (\%CLhash);
       
    96 }
       
    97 1;