1 # |
|
2 # Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # |
|
16 |
|
17 use strict; |
|
18 use File::Find; # for finding |
|
19 use File::Basename; # for fileparse |
|
20 use File::Copy 'copy'; |
|
21 use File::Path; |
|
22 use Getopt::Long; |
|
23 |
|
24 my (@sysdeffiles, @filters); |
|
25 |
|
26 if ( !GetOptions( |
|
27 'i=s' => \@sysdeffiles, |
|
28 'f:s' => \@filters |
|
29 )) |
|
30 { |
|
31 &error_msg("Invalid arguments!\n"); |
|
32 } |
|
33 |
|
34 if (!scalar (@filters)){ &error_msg("No filter(s) to set!\n")}; |
|
35 if (!scalar (@sysdeffiles)){ &error_msg("No files to set filters\n")}; |
|
36 |
|
37 my $checkfilters = ""; |
|
38 foreach (@filters) { |
|
39 next if ($_ !~ /\w/i); |
|
40 $checkfilters .=$_; |
|
41 $checkfilters .=","; |
|
42 } |
|
43 # no filters to add |
|
44 if ($checkfilters eq "") {die "nothing to do\n";}; |
|
45 |
|
46 foreach my $file (@sysdeffiles) { |
|
47 eval {set_filters($file);}; |
|
48 if ($@) { |
|
49 print "failed $@ \n"; |
|
50 } |
|
51 } |
|
52 |
|
53 sub set_filters { |
|
54 my $sysdeffile = shift; |
|
55 my @updated_data; |
|
56 |
|
57 open (ORIG,"${sysdeffile}") or die("Cannot open $sysdeffile"); |
|
58 my @orig_data=<ORIG>; |
|
59 close ORIG; |
|
60 |
|
61 copy($sysdeffile, $sysdeffile.".orig"); |
|
62 |
|
63 foreach (@orig_data) { |
|
64 chomp; |
|
65 if ($_ =~ /(<configuration)/i) { |
|
66 my $filterline = getfilterline($_); |
|
67 $_ =~ s/^.*filter=?\"/$&${filterline}/i; |
|
68 $_ =~ s/,\"/\"/i; |
|
69 } |
|
70 push @updated_data, $_."\n"; |
|
71 } |
|
72 |
|
73 open (UPDATED, ">${sysdeffile}"); |
|
74 print UPDATED @updated_data; |
|
75 close UPDATED; |
|
76 } |
|
77 |
|
78 sub getfilterline { |
|
79 my $conffilter = shift; |
|
80 my $newfilterline = ""; |
|
81 |
|
82 $conffilter =~ s/.*filter=\"//i; |
|
83 $conffilter =~ s/\".*//i; |
|
84 |
|
85 my @oldfilters = split(',', $conffilter); |
|
86 |
|
87 foreach (@filters) { |
|
88 my $match = 0; |
|
89 next if ($_ !~ /\w/i); |
|
90 # check if filter is defined already |
|
91 foreach my $old (@oldfilters) { |
|
92 if ($old eq $_) { |
|
93 $match = 1; |
|
94 last; |
|
95 } |
|
96 } |
|
97 # add filter only if it is new |
|
98 if (!$match) { |
|
99 $newfilterline .= $_; |
|
100 $newfilterline .=","; |
|
101 } |
|
102 |
|
103 } |
|
104 |
|
105 # remove last ',' if filters are not existed before |
|
106 if (! scalar (@oldfilters) && $newfilterline ne "") { |
|
107 $newfilterline =~ s/,$//i |
|
108 } |
|
109 |
|
110 return $newfilterline; |
|
111 } |
|
112 |
|
113 sub error_msg ($){ |
|
114 my($ErrorMsg); |
|
115 ($ErrorMsg)=@_; |
|
116 my $given_command=$0; |
|
117 $given_command =~ s/.*\\(\w+\.\w+)$/$1/; |
|
118 print "Error: $ErrorMsg \n"; |
|
119 print "Usage: \n$given_command -f <filter> -i <systemdefinition xml file>\n"; |
|
120 print " -f <filter> (multible allowed)\n"; |
|
121 print " -i <sysdef file> (multible allowed)\n"; |
|
122 print "Example: \n$given_command -f test -i \\S60_SystemBuild.xml\n"; |
|
123 print "\n"; |
|
124 die "\n"; |
|
125 } |
|