common/tools/ats/ats_specialise_test_drop.pl
changeset 821 b24df46a3102
parent 820 2a9e6403efaf
child 823 65dc12e0fcac
equal deleted inserted replaced
820:2a9e6403efaf 821:b24df46a3102
    60           'dest=s',
    60           'dest=s',
    61           'help!',
    61           'help!',
    62           'publish=s') 
    62           'publish=s') 
    63           or usage_error();
    63           or usage_error();
    64 
    64 
       
    65 # Check if Tie::File module installed
       
    66 eval("use Tie::File");
       
    67 if ($@) { $publish = '' };
       
    68 		  
    65 if ($help) {
    69 if ($help) {
    66 	help();
    70 	help();
    67 }
    71 }
    68 
    72 
    69 # --src is mandatory.
    73 # --src is mandatory.
   125 $test_drop->{'test'}->{'name'}->[0] = $test_drop_name, if $test_drop_name;
   129 $test_drop->{'test'}->{'name'}->[0] = $test_drop_name, if $test_drop_name;
   126 # Insert the specified build id, if any.
   130 # Insert the specified build id, if any.
   127 $test_drop->{'test'}->{'buildid'}->[0] = $build_id, if $build_id;
   131 $test_drop->{'test'}->{'buildid'}->[0] = $build_id, if $build_id;
   128 # Insert the FileStoreAction parameter
   132 # Insert the FileStoreAction parameter
   129 my $postaction_params = $test_drop->{'test'}->{'postAction'}->[0]->{'params'}->{'param'}, if $publish;
   133 my $postaction_params = $test_drop->{'test'}->{'postAction'}->[0]->{'params'}->{'param'}, if $publish;
   130 $postaction_params->[1] = { 'name' => "to-folder", 'value' => $publish . "\\ats_reports" }, if $publish;
   134 $postaction_params->[1] = { 'name' => "to-folder", 'value' => $publish }, if $publish;
   131 
   135 
   132 if ($host_name) { # Also insert specified host name
   136 if ($host_name) { # Also insert specified host name
   133 	my $devices = $test_drop->{'test'}->{'target'}->[0]->{'device'};
   137 	my $devices = $test_drop->{'test'}->{'target'}->[0]->{'device'};
   134     
   138     
   135     foreach my $device (@{$devices}) {
   139     foreach my $device (@{$devices}) {
   150 else { #Input file was a zip.
   154 else { #Input file was a zip.
   151     # Write new XML to test.xml
   155     # Write new XML to test.xml
   152     open OUT,">test.xml" or die("Cannot open file \"test.xml\" for writing. $!\n");
   156     open OUT,">test.xml" or die("Cannot open file \"test.xml\" for writing. $!\n");
   153     print OUT XMLout($test_drop, keeproot => 1);
   157     print OUT XMLout($test_drop, keeproot => 1);
   154     close OUT;
   158     close OUT;
       
   159 	if ($publish) { #Move <type>FileStoreAction</type> above <params>
       
   160 		my @lines;
       
   161 		tie @lines, 'Tie::File', "test.xml" or die("Cannot tie file \"test.xml\". $!\n");
       
   162 		my $current_line = 0;
       
   163 		for (@lines) {
       
   164 			if (/FileStoreAction/) {
       
   165 				my $line_to_move = @lines[$current_line];
       
   166 				splice @lines, $current_line, 1;
       
   167 				splice @lines, $current_line-4, 0, $line_to_move;
       
   168 				last;
       
   169 			}
       
   170 		  $current_line++;
       
   171 	    }
       
   172 	untie @lines;
       
   173 	}
   155     if ( -f "$destfile.zip") {
   174     if ( -f "$destfile.zip") {
   156         unlink("$destfile.zip") or die("Could not delete \"$destfile.zip\": $!\n");
   175         unlink("$destfile.zip") or die("Could not delete \"$destfile.zip\": $!\n");
   157     } 
   176     } 
   158     copy("$srcfile","$destfile.zip") or die("Could not copy \"$srcfile\" -> \"$destfile.zip\": $!\n");
   177     copy("$srcfile","$destfile.zip") or die("Could not copy \"$srcfile\" -> \"$destfile.zip\": $!\n");
   159     system("$zipper > $dev_null") and die("Could not zip \"test.xml\" into \"$destfile\"\n");    
   178     system("$zipper > $dev_null") and die("Could not zip \"test.xml\" into \"$destfile\"\n");