|
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 |
|
18 #------------------------------------------------------------------------------------ |
|
19 # Includes |
|
20 #------------------------------------------------------------------------------------ |
|
21 #use strict; |
|
22 use warnings; |
|
23 use Cwd; # for cwd |
|
24 use FindBin; # for FindBin:Bin |
|
25 use File::Path; # for mkpath |
|
26 use Date::Calc; |
|
27 |
|
28 #------------------------------------------------------------------------------------ |
|
29 # GLOBAL CODE |
|
30 #------------------------------------------------------------------------------------ |
|
31 |
|
32 my $option = ""; |
|
33 $option = shift(@ARGV) if( scalar(@ARGV) > 0 ); |
|
34 |
|
35 if( $option =~ m/\-h/i ) |
|
36 { |
|
37 print( |
|
38 "tsrcpkgtool.pl\n" . |
|
39 " Toggles comments in all pkgs under tsrc folders for lines \n" . |
|
40 " which have testframework.ini or cccccc00.cre cenrep.\n" . |
|
41 " Options:\n" . |
|
42 " -h help\n -r remove only\n -a add only\n" ); |
|
43 exit; |
|
44 } |
|
45 |
|
46 my @files; |
|
47 FindFiles(".", ".pkg", 1, \@files); |
|
48 FindFiles(".", ".inf", 1, \@files); |
|
49 |
|
50 my $comment = ";TEMPCOMMENT "; |
|
51 my $comment_inf = "//TEMPCOMMENT "; |
|
52 |
|
53 |
|
54 foreach my $file ( @files ) |
|
55 { |
|
56 if( $file =~ m/\/tsrc\//i ) |
|
57 { |
|
58 open(FILE_HANDLE, $file) or die ("Could not read file '$file'\n"); |
|
59 my @lines = <FILE_HANDLE>; |
|
60 close(FILE_HANDLE); |
|
61 |
|
62 open(FILE_HANDLE, ">$file") or die ("Could not write file '$file'\n"); |
|
63 foreach my $line ( @lines ) |
|
64 { |
|
65 if( $line =~ /\.\.\/init\/testframework\.ini/i or $line =~ /\/cccccc00\.cre/i or |
|
66 $line =~ /\.\.\\init\\testframework\.ini/i or $line =~ /\\cccccc00\.cre/i ) |
|
67 { |
|
68 my $filename = $file; |
|
69 $filename =~ s/\//\\/g; |
|
70 $filename = substr( $filename, rindex( $filename, "\\" )+1 ); |
|
71 |
|
72 if( $line =~ /$comment/ ) |
|
73 { |
|
74 if( $option ne "-a" ) |
|
75 { |
|
76 # Remove comment. |
|
77 $line = substr( $line, length( $comment ) ); |
|
78 print("Removed comment: $filename.\n"); |
|
79 } |
|
80 } |
|
81 elsif( $line =~ /$comment_inf/ ) |
|
82 { |
|
83 if( $option ne "-a" ) |
|
84 { |
|
85 # Remove comment. |
|
86 $line = substr( $line, length( $comment_inf ) ); |
|
87 print("Removed comment: $filename.\n"); |
|
88 } |
|
89 } |
|
90 else |
|
91 { |
|
92 if( $option ne "-r" ) |
|
93 { |
|
94 # Add comment. |
|
95 if( $filename =~ /\.inf/ ) { |
|
96 $line = $comment_inf . $line; |
|
97 } |
|
98 else { |
|
99 $line = $comment . $line; |
|
100 } |
|
101 print("Added comment: $filename.\n"); |
|
102 } |
|
103 } |
|
104 } |
|
105 print FILE_HANDLE $line; |
|
106 } |
|
107 close(FILE_HANDLE); |
|
108 } |
|
109 } |
|
110 |
|
111 #------------------------------------------------------------------------------------ |
|
112 # FindFiles |
|
113 # Parameters: |
|
114 # $goDir, where to start finding |
|
115 # $fileSearch, filename search |
|
116 # $searchType, 0 = fullname search, 1 = filetype search |
|
117 # $refIncfiles, reference to array which will hold found files |
|
118 #------------------------------------------------------------------------------------ |
|
119 sub FindFiles |
|
120 { |
|
121 my ($godir, $fileSearch, $searchType, $refIncfiles) = @_; |
|
122 |
|
123 my $startDir = cwd; |
|
124 |
|
125 chdir($godir); |
|
126 |
|
127 #print("Now in: " . cwd . "\n"); |
|
128 |
|
129 opendir(DIR, "."); |
|
130 my @filelist = sort(readdir(DIR)); |
|
131 closedir(DIR); |
|
132 |
|
133 foreach my $file(@filelist) |
|
134 { |
|
135 if($file eq "." or $file eq "..") {next}; |
|
136 |
|
137 if (-d $file) |
|
138 { |
|
139 FindFiles( $file, $fileSearch, $searchType, $refIncfiles); |
|
140 } else |
|
141 { |
|
142 if( ($file =~ m/$fileSearch/i and $searchType == 0 ) or ($file =~ m/$fileSearch$/i and $searchType == 1 ) ) |
|
143 { |
|
144 $file = cwd . "/" . $file; |
|
145 push @$refIncfiles, $file; |
|
146 #print("$file\n"); |
|
147 } |
|
148 } |
|
149 } |
|
150 |
|
151 chdir ($startDir); |
|
152 } |