|
1 # Copyright (c) 2009 Symbian Foundation Ltd |
|
2 # This component and the accompanying materials are made available |
|
3 # under the terms of the License "Eclipse Public License v1.0" |
|
4 # which accompanies this distribution, and is available |
|
5 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
6 # |
|
7 # Initial Contributors: |
|
8 # Symbian Foundation Ltd - initial contribution. |
|
9 # |
|
10 # Contributors: |
|
11 # |
|
12 # Description: |
|
13 # Translates envinfo report to a Diamonds file |
|
14 |
|
15 use strict; |
|
16 |
|
17 use Getopt::Long; |
|
18 |
|
19 my $input = "\\output\\logs\\envinfo.txt"; |
|
20 my $output = "\\output\\logs\\envinfo_diamonds.xml"; |
|
21 my $help = 0; |
|
22 GetOptions(( |
|
23 'in=s' => \$input, |
|
24 'out=s' => \$output, |
|
25 'help!' => \$help |
|
26 )); |
|
27 |
|
28 if ($help) |
|
29 { |
|
30 print "Translates envinfo report to a Diamonds file\n"; |
|
31 print "Usage: perl envinfo2diamonds.pl [-i INFILE] [-o OUTFILE]\n"; |
|
32 print "\n"; |
|
33 print "INFILE is optional, its default is \\output\\logs\\envinfo.txt\n"; |
|
34 print "OUTFILE is optional, its default is \\output\\logs\\envinfo_diamonds.xml\n"; |
|
35 exit(0); |
|
36 } |
|
37 |
|
38 my @environment_info = (); |
|
39 |
|
40 open(INFILE, $input) or die "Can't open $input for reading"; |
|
41 while (<INFILE>) |
|
42 { |
|
43 my $line = $_; |
|
44 if ($line =~ /([^\t]*)\t([^\t]*)/) |
|
45 { |
|
46 my $name = $1; |
|
47 my $version = $2; |
|
48 chomp $name; |
|
49 chomp $version; |
|
50 push @environment_info, {name=>$name, version=>$version}; |
|
51 } |
|
52 } |
|
53 close(INFILE); |
|
54 |
|
55 # write diamonds file |
|
56 @environment_info = reverse(@environment_info); |
|
57 |
|
58 my $xml_content = <<_EOX; |
|
59 <?xml version=\"1.0\" encoding=\"UTF-8\"?> |
|
60 <diamonds-build> |
|
61 <schema>10</schema> |
|
62 <tools> |
|
63 _HERE_TOOLS_LINES_ |
|
64 </tools> |
|
65 </diamonds-build> |
|
66 _EOX |
|
67 |
|
68 my $tools_lines = ''; |
|
69 for my $tool_info (@environment_info) |
|
70 { |
|
71 $tools_lines .= " <tool><name>$tool_info->{name}</name><version>$tool_info->{version}</version></tool>\n"; |
|
72 } |
|
73 |
|
74 $xml_content =~ s/_HERE_TOOLS_LINES_/$tools_lines/; |
|
75 |
|
76 if (open(ENVINFO, ">$output")) |
|
77 { |
|
78 print ENVINFO $xml_content; |
|
79 close(ENVINFO); |
|
80 print "Wrote Diamonds file: $output\n"; |
|
81 } |
|
82 else |
|
83 { |
|
84 warn "Could not write to file: $output\n"; |
|
85 } |