bldsystemtools/commonbldutils/GenResult/GenDiamondsXml.pm
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     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 to Generate the XML file that is suitable for Diamonds
       
    15 # 
       
    16 #
       
    17 package GenDiamondsXml;
       
    18 use FindBin;
       
    19 use lib "$FindBin::Bin/lib";
       
    20 use strict;
       
    21 use Text::Template;
       
    22 use Text::Template 'fill_in_file';
       
    23 use publishDiamonds;
       
    24 use ZipDiamondsXml;
       
    25 
       
    26 my $Debug = 0;
       
    27 my $MainXML = "Main.xml";
       
    28 my @start;
       
    29 if($ENV{BuildSubType} eq "Daily")
       
    30 {
       
    31     @start = ('build.tmpl','schema.tmpl','locations.tmpl','tools.tmpl','content.tmpl','files.tmpl');
       
    32 }
       
    33 elsif($ENV{BuildSubType} eq "Test")
       
    34 {
       
    35     @start = ('build.tmpl','schema.tmpl','locations.tmpl','tools.tmpl','files.tmpl');
       
    36 }
       
    37 
       
    38 my %states = (
       
    39 'STARTBUILD' => {
       
    40             'START' => \@start
       
    41             #~ 'START' => ['files.tmpl']
       
    42         },
       
    43 'GT' => {
       
    44             'START' => ['stage.tmpl'],
       
    45             'STOP' => ['stage.tmpl', 'faults.tmpl']
       
    46         },
       
    47 'TV' => {
       
    48             'START' => ['stage.tmpl'],
       
    49             'STOP' => ['stage.tmpl','faults.tmpl']
       
    50         },
       
    51 'ROM' => {
       
    52             'START' => ['stage.tmpl'],
       
    53             'STOP' => ['stage.tmpl','faults.tmpl']
       
    54         },
       
    55 'CBR' => {
       
    56             'START' => ['stage.tmpl'],
       
    57             'STOP' => ['stage.tmpl','faults.tmpl']
       
    58         },
       
    59 'CDB' => {
       
    60             'START' => ['stage.tmpl'],
       
    61             'STOP' => ['stage.tmpl','faults.tmpl']
       
    62         },
       
    63 'BUILD' => {
       
    64             'START' => ['stage.tmpl'],
       
    65             'STOP' => ['stage.tmpl','faults.tmpl']
       
    66         },
       
    67 'ENDBUILD' => {
       
    68             'START' => ['diamonds_finish.tmpl', 'status.tmpl']
       
    69         }
       
    70 );
       
    71 
       
    72 sub main
       
    73 {
       
    74   my ($iStage, $iState, $iServer) = @_;
       
    75   print "STAGE: $iStage\t STATE: $iState\n";
       
    76   my %vars = ();
       
    77   $vars{'iStage'} = $iStage;
       
    78   $vars{$iState} = 1;
       
    79   my $LogsLocation = $ENV{LogsDir}."\\";
       
    80   my @toMerge = ();
       
    81   my $BatFile = "SendXmls.bat";
       
    82   open (BAT,">>$BatFile") or warn "$BatFile: $!\n";
       
    83 
       
    84   foreach my $tmpl (@{$states{$iStage}{$iState}})
       
    85   {
       
    86     my $suffix = "_".$iStage."_".$iState;
       
    87     my $XmlName = $tmpl;
       
    88     $XmlName =~ s/\.tmpl/$suffix\.xml/;
       
    89     my $outfile = $LogsLocation.$XmlName;
       
    90     $tmpl = "$FindBin::Bin/".$tmpl;
       
    91     open(OUT,">$outfile");
       
    92     print "Processing $tmpl...\n" if $Debug;
       
    93     my $template = Text::Template->new(TYPE => 'FILE',  SOURCE => $tmpl)or die "Couldn't construct template: $Text::Template::ERROR";
       
    94     my $success = $template->fill_in(OUTPUT => \*OUT, DELIMITERS => [ '[@--', '--@]' ], HASH => \%vars) or warn "$Text::Template::ERROR\n";
       
    95     close(OUT);
       
    96     if ($success)
       
    97     {
       
    98       print "Successfully processed $tmpl\n" if $Debug;
       
    99       &publishDiamonds::publishToDiamonds($outfile,$iServer) if($ENV{BuildSubType} eq "Daily");
       
   100       &ZipDiamondsXml::main($outfile);
       
   101       print BAT "perl -e \"use publishDiamonds; &publishDiamonds::publishToDiamonds(\'$XmlName\',\'$iServer\');\"\n";
       
   102       unlink ($outfile) or warn "Error in deleting: $!\n";
       
   103     }
       
   104   }
       
   105   close(BAT);
       
   106   if ($iStage eq "ENDBUILD")
       
   107   {
       
   108       &ZipDiamondsXml::main($BatFile);
       
   109       unlink ($BatFile) or warn "Error in deleting: $!\n";
       
   110       &ZipDiamondsXml::main($FindBin::Bin."/"."publishDiamonds.pm");
       
   111       &ZipDiamondsXml::main($FindBin::Bin."/"."send_xml_to_diamonds.pl");
       
   112   }
       
   113 }
       
   114 1;