|
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 use File::Copy; |
|
28 |
|
29 my @files; |
|
30 |
|
31 FindDirs(".", "", \@dirs); |
|
32 |
|
33 my $option = ""; |
|
34 |
|
35 $option = shift(@ARGV) if( scalar(@ARGV) > 0 ); |
|
36 |
|
37 if( $option eq "-check" ) |
|
38 { |
|
39 # Check for missing policy files. |
|
40 print("Policy file missing from directories:\n"); |
|
41 my $count = 0; |
|
42 foreach $dir ( @dirs ) |
|
43 { |
|
44 if( !-e "$dir/distribution.policy.s60" ) |
|
45 { |
|
46 print("$dir\n"); |
|
47 $count++; |
|
48 } |
|
49 } |
|
50 print("None!\n") if( $count == 0 ); |
|
51 } |
|
52 elsif( $option eq "-len" ) |
|
53 { |
|
54 print("Too long filenames:\n"); |
|
55 foreach $dir ( @dirs ) |
|
56 { |
|
57 my @files; |
|
58 GetAllFiles( $dir, \@files ); |
|
59 foreach $file ( @files ) |
|
60 { |
|
61 if( length( $dir . "/" . $file ) > 140 ) |
|
62 { |
|
63 print("$dir/$file\n"); |
|
64 } |
|
65 } |
|
66 } |
|
67 } |
|
68 elsif( $option eq "-list" ) |
|
69 { |
|
70 foreach $dir ( @dirs ) |
|
71 { |
|
72 print("$dir\n"); |
|
73 CheckDistri( $dir ); |
|
74 } |
|
75 } |
|
76 elsif( $option eq "" ) |
|
77 { |
|
78 print("This copies distribution.policy.s60 file from current directory to all subdirectories.\n\n"); |
|
79 print("Press CTRL-C to cancel, ENTER key to continue.\n\n"); |
|
80 <>; |
|
81 |
|
82 die("policy file does not exist in current directory!") if( ! -e "distribution.policy.s60" ); |
|
83 |
|
84 foreach $dir ( @dirs ) |
|
85 { |
|
86 unlink("$dir/distribution.policy.s60"); |
|
87 copy("distribution.policy.s60", "$dir/distribution.policy.s60"); |
|
88 } |
|
89 } |
|
90 else |
|
91 { |
|
92 print("Options:\n"); |
|
93 print(" -check checks all directories for policy files.\n"); |
|
94 print(" -len checks that any path doesn't go over 140 characters.\n"); |
|
95 exit(); |
|
96 } |
|
97 |
|
98 # returns if this is internal folder |
|
99 sub CheckDistri |
|
100 { |
|
101 my ($dir) = @_; |
|
102 |
|
103 # |
|
104 # Check all subdirs but internals |
|
105 # |
|
106 |
|
107 my $isInternal = 0; |
|
108 |
|
109 if( substr($dir, rindex( $dir, "/" )+1 ) =~m/internal$/i ) |
|
110 { |
|
111 $isInternal = 1; |
|
112 } |
|
113 return $isInternal; |
|
114 } |
|
115 |
|
116 #------------------------------------------------------------------------------------ |
|
117 # FindFiles |
|
118 # Parameters: |
|
119 # $goDir, where to start finding |
|
120 # $fileSearch, filename search |
|
121 # $searchType, 0 = fullname search, 1 = filetype search |
|
122 # $refIncfiles, reference to array which will hold found files |
|
123 #------------------------------------------------------------------------------------ |
|
124 sub FindFiles |
|
125 { |
|
126 my ($godir, $fileSearch, $searchType, $refIncfiles, $fileFilter) = @_; |
|
127 |
|
128 my $startDir = cwd; |
|
129 |
|
130 chdir($godir); |
|
131 |
|
132 #print("Now in: " . cwd . "\n"); |
|
133 |
|
134 opendir(DIR, "."); |
|
135 my @filelist = sort(readdir(DIR)); |
|
136 closedir(DIR); |
|
137 |
|
138 foreach my $file(@filelist) |
|
139 { |
|
140 if($file eq "." or $file eq "..") {next}; |
|
141 |
|
142 if (-d $file) |
|
143 { |
|
144 FindFiles( $file, $fileSearch, $searchType, $refIncfiles, $fileFilter ); |
|
145 } else |
|
146 { |
|
147 if( ($file =~ m/$fileSearch/i and $searchType == 0 and $file =~m/$fileFilter/i) or ($file =~ m/$fileSearch$/i and $searchType == 1 and $file =~m/$fileFilter/i) ) |
|
148 { |
|
149 $file = cwd . "/" . $file; |
|
150 push @$refIncfiles, $file; |
|
151 #print("$file\n"); |
|
152 } |
|
153 } |
|
154 } |
|
155 |
|
156 chdir ($startDir); |
|
157 } |
|
158 |
|
159 |
|
160 #------------------------------------------------------------------------------------ |
|
161 # GetAllFiles |
|
162 # Parameters: |
|
163 # $goDir, where to start finding |
|
164 # $refIncfiles, reference to array which will hold found files |
|
165 #------------------------------------------------------------------------------------ |
|
166 sub GetAllFiles |
|
167 { |
|
168 my ($godir, $refIncfiles) = @_; |
|
169 |
|
170 my $startDir = cwd; |
|
171 |
|
172 chdir($godir); |
|
173 |
|
174 #print("Now in: " . cwd . "\n"); |
|
175 |
|
176 opendir(DIR, "."); |
|
177 my @filelist = sort(readdir(DIR)); |
|
178 closedir(DIR); |
|
179 |
|
180 foreach my $file(@filelist) |
|
181 { |
|
182 if($file eq "." or $file eq "..") {next}; |
|
183 |
|
184 if (! (-d $file) ) |
|
185 { |
|
186 push @$refIncfiles, $file; |
|
187 } |
|
188 } |
|
189 |
|
190 chdir ($startDir); |
|
191 } |
|
192 |
|
193 |
|
194 #------------------------------------------------------------------------------------ |
|
195 # FindDirs |
|
196 # Parameters: |
|
197 # $goDir, where to start finding |
|
198 # $fileSearch, filename search |
|
199 # $refIncfiles, reference to array which will hold found files |
|
200 #------------------------------------------------------------------------------------ |
|
201 sub FindDirs |
|
202 { |
|
203 my ($godir, $fileSearch, $refIncfiles) = @_; |
|
204 |
|
205 my $startDir = cwd; |
|
206 |
|
207 chdir($godir); |
|
208 |
|
209 #print("Now in: " . cwd . "\n"); |
|
210 |
|
211 opendir(DIR, "."); |
|
212 my @filelist = sort(readdir(DIR)); |
|
213 closedir(DIR); |
|
214 |
|
215 foreach my $file(@filelist) |
|
216 { |
|
217 if($file eq "." or $file eq "..") {next}; |
|
218 |
|
219 if (-d $file) |
|
220 { |
|
221 if( $file =~ m/$fileSearch/i ) |
|
222 { |
|
223 push @$refIncfiles, (cwd . "/" . $file); |
|
224 } |
|
225 FindDirs( $file, $fileSearch, $refIncfiles ); |
|
226 } |
|
227 } |
|
228 |
|
229 chdir ($startDir); |
|
230 } |