|
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 # Includes |
|
19 #------------------------------------------------------------------------------------ |
|
20 #use strict; |
|
21 use warnings; |
|
22 use Cwd; # for cwd |
|
23 use FindBin; # for FindBin:Bin |
|
24 use File::Path; # for mkpath |
|
25 use Date::Calc; |
|
26 |
|
27 while(scalar(@ARGV) >= 1) |
|
28 { |
|
29 my $argument = shift(@ARGV); |
|
30 |
|
31 if($argument eq "-release") |
|
32 { |
|
33 #$paramRelease = shift(@ARGV); |
|
34 } |
|
35 else |
|
36 { |
|
37 print "arg: $argument\n"; |
|
38 Help(); |
|
39 } |
|
40 } |
|
41 |
|
42 sub Help |
|
43 { |
|
44 print <<USAGE_EOF; |
|
45 |
|
46 USAGE_EOF |
|
47 |
|
48 exit(); |
|
49 } |
|
50 |
|
51 #------------------------------------------------------------------------------------ |
|
52 # Main code |
|
53 #------------------------------------------------------------------------------------ |
|
54 |
|
55 my $startDir = cwd; |
|
56 |
|
57 print("here: $startDir\n"); |
|
58 |
|
59 opendir(DIR, "."); |
|
60 my @dirs = sort( readdir(DIR) ); |
|
61 closedir(DIR); |
|
62 |
|
63 foreach my $dir(@dirs) |
|
64 { |
|
65 print("search $dir\n"); |
|
66 if($dir eq "." or $dir eq "..") {next}; |
|
67 |
|
68 if (-d $dir) |
|
69 { |
|
70 if($file eq "." or $file eq "..") {next}; |
|
71 |
|
72 my $log = FindFile($dir, "iptvlog.txt", 0); |
|
73 my $report = FindFile($dir, "testreport.txt", 0); |
|
74 my $ctcdata = FindFile($dir, "ctcdata.txt", 0); |
|
75 $log =~ s/\//\\/; |
|
76 $report =~ s/\//\\/; |
|
77 $ctcdata =~ s/\//\\/; |
|
78 |
|
79 print("found $log\n"); |
|
80 print("found $report\n"); |
|
81 if($report ne "" and $log ne "") |
|
82 { |
|
83 my $file = GetFilename($log); |
|
84 my $pos = rindex($file, "."); |
|
85 my $ext = substr($file, $pos); |
|
86 my $file = substr($file, 0, $pos); |
|
87 $file = $file . "_" . $dir . $ext; |
|
88 my $logdest = $startDir . "\\" . $file; |
|
89 $logdest =~ s/\//\\/; |
|
90 system("copy \"$log\" \"$logdest\"\n\n"); |
|
91 |
|
92 $file = GetFilename($report); |
|
93 $pos = rindex($file, "."); |
|
94 $ext = substr($file, $pos); |
|
95 $file = substr($file, 0, $pos); |
|
96 $file = $file . "_" . $dir . $ext; |
|
97 my $reportdest = $startDir . "\\" . $file; |
|
98 $reportdest =~ s/\//\\/; |
|
99 system("copy \"$report\" \"$reportdest\"\n\n"); |
|
100 |
|
101 if( $ctcdata ne "" ) |
|
102 { |
|
103 $file = GetFilename($ctcdata); |
|
104 $pos = rindex($file, "."); |
|
105 $ext = substr($file, $pos); |
|
106 $file = substr($file, 0, $pos); |
|
107 $file = $file . "_" . $dir . $ext; |
|
108 my $ctcdest = $startDir . "\\" . $file; |
|
109 $ctcdest =~ s/\//\\/; |
|
110 system("copy \"$ctcdata\" \"$ctcdest\"\n\n"); |
|
111 } |
|
112 } |
|
113 } |
|
114 } |
|
115 |
|
116 chdir ($startDir); |
|
117 |
|
118 exit(); |
|
119 |
|
120 |
|
121 #------------------------------------------------------------------------------------ |
|
122 # FindFiles |
|
123 # Parameters: |
|
124 # $goDir, where to start finding |
|
125 # $fileSearch, filename search |
|
126 # $searchType, 0 = fullname search, 1 = filetype search |
|
127 # $refFiles, reference to array which will hold found files |
|
128 #------------------------------------------------------------------------------------ |
|
129 sub FindFiles |
|
130 { |
|
131 my ($godir, $fileSearch, $searchType, $refFiles) = @_; |
|
132 |
|
133 my $startDir = cwd; |
|
134 |
|
135 chdir($godir); |
|
136 |
|
137 #print("Now in: " . cwd . "\n"); |
|
138 |
|
139 opendir(DIR, "."); |
|
140 my @filelist = sort(readdir(DIR)); |
|
141 closedir(DIR); |
|
142 |
|
143 foreach my $file(@filelist) |
|
144 { |
|
145 if($file eq "." or $file eq "..") {next}; |
|
146 |
|
147 if (-d $file) |
|
148 { |
|
149 FindFiles( $file, $fileSearch, $searchType, $refFiles ); |
|
150 } else |
|
151 { |
|
152 if( ($file =~ m/$fileSearch/i and $searchType == 0) or ($file =~ m/$fileSearch$/i and $searchType == 1) ) |
|
153 { |
|
154 $file = cwd . "/" . $file; |
|
155 push @$refFiles, $file; |
|
156 print("$file\n"); |
|
157 } |
|
158 } |
|
159 } |
|
160 |
|
161 chdir ($startDir); |
|
162 } |
|
163 |
|
164 |
|
165 |
|
166 #------------------------------------------------------------------------------------ |
|
167 # FindDirectory |
|
168 # |
|
169 # Parameters: |
|
170 # $goDir, where to start finding |
|
171 # $fileSearch, filename search |
|
172 # $minSize, minimum size for the directory |
|
173 # |
|
174 # Returns the directory found. |
|
175 #------------------------------------------------------------------------------------ |
|
176 sub FindDirectory |
|
177 { |
|
178 my ($godir, $fileSearch, $dontCheckSubFolders, $minSize) = @_; |
|
179 |
|
180 my $startDir = cwd; |
|
181 |
|
182 #print("Now in $startDir\n"); |
|
183 print("minsize: $minSize for $fileSearch\n") if($minSize); |
|
184 |
|
185 chdir($godir); |
|
186 |
|
187 opendir(DIR, "."); |
|
188 my @filelist = sort(readdir(DIR)); |
|
189 closedir(DIR); |
|
190 |
|
191 foreach my $file(@filelist) |
|
192 { |
|
193 if($file eq "." or $file eq "..") {next}; |
|
194 |
|
195 if (-d $file) |
|
196 { |
|
197 print("($file - $fileSearch)\n"); |
|
198 if( $file =~ m/$fileSearch/i ) |
|
199 { |
|
200 if(!$minSize or DirSize($file) > $minSize) |
|
201 { |
|
202 $file = cwd . "/" . $file; |
|
203 $file =~ s/\//\\/g; |
|
204 chdir ($startDir); |
|
205 return $file; |
|
206 } |
|
207 } |
|
208 } |
|
209 } |
|
210 |
|
211 return "" if($dontCheckSubFolders); |
|
212 |
|
213 # Find subfolders |
|
214 foreach my $file(@filelist) |
|
215 { |
|
216 if($file eq "." or $file eq "..") {next}; |
|
217 |
|
218 if (-d $file) |
|
219 { |
|
220 my $found = FindDirectory( $file, $fileSearch ); |
|
221 if($found ne "") |
|
222 { |
|
223 chdir ($startDir); |
|
224 $found =~ s/\//\\/g; |
|
225 return $found; |
|
226 } |
|
227 } |
|
228 } |
|
229 |
|
230 chdir ($startDir); |
|
231 return ""; |
|
232 } |
|
233 |
|
234 |
|
235 #------------------------------------------------------------------------------------ |
|
236 # FindFile |
|
237 # |
|
238 # Parameters: |
|
239 # $goDir, where to start finding |
|
240 # $fileSearch, filename search |
|
241 # $minSize, minimum size for the file |
|
242 # |
|
243 # Returns the file found. |
|
244 #------------------------------------------------------------------------------------ |
|
245 sub FindFile |
|
246 { |
|
247 my ($godir, $fileSearch, $dontCheckSubFolders, $minSize) = @_; |
|
248 |
|
249 my $startDir = cwd; |
|
250 |
|
251 #print("Now in $startDir\n"); |
|
252 |
|
253 chdir($godir); |
|
254 |
|
255 opendir(DIR, "."); |
|
256 my @filelist = sort(readdir(DIR)); |
|
257 closedir(DIR); |
|
258 |
|
259 foreach my $file(@filelist) |
|
260 { |
|
261 if($file eq "." or $file eq "..") {next}; |
|
262 |
|
263 if( $file =~ m/$fileSearch/i and !(-d $file) ) |
|
264 { |
|
265 if(!$minSize or -s $file > $minSize) |
|
266 { |
|
267 $file = cwd . "/" . $file; |
|
268 $file =~ s/\//\\/g; |
|
269 chdir ($startDir); |
|
270 return $file; |
|
271 } |
|
272 } |
|
273 } |
|
274 |
|
275 return "" if($dontCheckSubFolders); |
|
276 |
|
277 # Find subfolders |
|
278 foreach my $file(@filelist) |
|
279 { |
|
280 if($file eq "." or $file eq "..") {next}; |
|
281 |
|
282 if (-d $file) |
|
283 { |
|
284 my $found = FindFile( $file, $fileSearch ); |
|
285 if($found ne "") |
|
286 { |
|
287 chdir ($startDir); |
|
288 $found =~ s/\//\\/g; |
|
289 return $found; |
|
290 } |
|
291 } |
|
292 } |
|
293 |
|
294 chdir ($startDir); |
|
295 return ""; |
|
296 } |
|
297 |
|
298 #------------------------------------------------------------------------------------ |
|
299 # DirSize |
|
300 # |
|
301 # Parameters: |
|
302 # $goDir, directory |
|
303 # |
|
304 # Returns the size of directory |
|
305 #------------------------------------------------------------------------------------ |
|
306 sub DirSize |
|
307 { |
|
308 my ($godir) = @_; |
|
309 |
|
310 my $startDir = cwd; |
|
311 |
|
312 chdir($godir); |
|
313 |
|
314 opendir(DIR, "."); |
|
315 my @filelist = sort(readdir(DIR)); |
|
316 closedir(DIR); |
|
317 |
|
318 my $size = 0; |
|
319 |
|
320 foreach my $file(@filelist) |
|
321 { |
|
322 if($file eq "." or $file eq "..") {next}; |
|
323 |
|
324 if (-d $file) |
|
325 { |
|
326 $size += DirSize($file); |
|
327 } |
|
328 else |
|
329 { |
|
330 $size += -s $file; |
|
331 } |
|
332 } |
|
333 |
|
334 chdir ($startDir); |
|
335 return $size; |
|
336 } |
|
337 |
|
338 #------------------------------------------------------------------------------------ |
|
339 # GetFilename |
|
340 # |
|
341 # Parameters: |
|
342 # $text |
|
343 #------------------------------------------------------------------------------------ |
|
344 sub GetFilename |
|
345 { |
|
346 my ($file) = @_; |
|
347 $file =~ s/\//\\/g; # / -> \ |
|
348 my $pos = rindex($file, "\\"); |
|
349 die("Invalid path: $file\n") if($pos == -1); |
|
350 return substr($file, $pos+1); |
|
351 } |
|
352 |
|
353 #------------------------------------------------------------------------------------ |
|
354 # RemoveWhiteSpaces |
|
355 # |
|
356 # Parameters: |
|
357 # $text |
|
358 #------------------------------------------------------------------------------------ |
|
359 sub RemoveWhiteSpaces() |
|
360 { |
|
361 my ($text) = @_; |
|
362 ${$text} =~ s/\s+$//; #whitespaces in the end |
|
363 ${$text} =~ s/^\s+//; #whitespaces at the start |
|
364 } |
|
365 |
|
366 #------------------------------------------------------------------------------------ |
|
367 # Timestamp |
|
368 # |
|
369 # Parameters: |
|
370 #------------------------------------------------------------------------------------ |
|
371 sub Timestamp |
|
372 { |
|
373 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); |
|
374 |
|
375 return "" . ($year+1900) . "-" . ($mon+1) . "-" . $mday . "-" . $hour . "-" . $min; |
|
376 } |