diff -r 000000000000 -r 96612d01cf9f tsrc/testing/tools/copylogsfromdirs.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tsrc/testing/tools/copylogsfromdirs.pl Mon Jan 18 20:21:12 2010 +0200 @@ -0,0 +1,376 @@ +# +# Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Initial Contributors: +# Nokia Corporation - initial contribution. +# +# Contributors: +# +# Description: +# + +#------------------------------------------------------------------------------------ +# Includes +#------------------------------------------------------------------------------------ +#use strict; +use warnings; +use Cwd; # for cwd +use FindBin; # for FindBin:Bin +use File::Path; # for mkpath +use Date::Calc; + +while(scalar(@ARGV) >= 1) +{ + my $argument = shift(@ARGV); + + if($argument eq "-release") + { + #$paramRelease = shift(@ARGV); + } + else + { + print "arg: $argument\n"; + Help(); + } +} + +sub Help +{ + print < $minSize) + { + $file = cwd . "/" . $file; + $file =~ s/\//\\/g; + chdir ($startDir); + return $file; + } + } + } + } + + return "" if($dontCheckSubFolders); + + # Find subfolders + foreach my $file(@filelist) + { + if($file eq "." or $file eq "..") {next}; + + if (-d $file) + { + my $found = FindDirectory( $file, $fileSearch ); + if($found ne "") + { + chdir ($startDir); + $found =~ s/\//\\/g; + return $found; + } + } + } + + chdir ($startDir); + return ""; +} + + +#------------------------------------------------------------------------------------ +# FindFile +# +# Parameters: +# $goDir, where to start finding +# $fileSearch, filename search +# $minSize, minimum size for the file +# +# Returns the file found. +#------------------------------------------------------------------------------------ +sub FindFile +{ + my ($godir, $fileSearch, $dontCheckSubFolders, $minSize) = @_; + + my $startDir = cwd; + + #print("Now in $startDir\n"); + + chdir($godir); + + opendir(DIR, "."); + my @filelist = sort(readdir(DIR)); + closedir(DIR); + + foreach my $file(@filelist) + { + if($file eq "." or $file eq "..") {next}; + + if( $file =~ m/$fileSearch/i and !(-d $file) ) + { + if(!$minSize or -s $file > $minSize) + { + $file = cwd . "/" . $file; + $file =~ s/\//\\/g; + chdir ($startDir); + return $file; + } + } + } + + return "" if($dontCheckSubFolders); + + # Find subfolders + foreach my $file(@filelist) + { + if($file eq "." or $file eq "..") {next}; + + if (-d $file) + { + my $found = FindFile( $file, $fileSearch ); + if($found ne "") + { + chdir ($startDir); + $found =~ s/\//\\/g; + return $found; + } + } + } + + chdir ($startDir); + return ""; +} + +#------------------------------------------------------------------------------------ +# DirSize +# +# Parameters: +# $goDir, directory +# +# Returns the size of directory +#------------------------------------------------------------------------------------ +sub DirSize +{ + my ($godir) = @_; + + my $startDir = cwd; + + chdir($godir); + + opendir(DIR, "."); + my @filelist = sort(readdir(DIR)); + closedir(DIR); + + my $size = 0; + + foreach my $file(@filelist) + { + if($file eq "." or $file eq "..") {next}; + + if (-d $file) + { + $size += DirSize($file); + } + else + { + $size += -s $file; + } + } + + chdir ($startDir); + return $size; +} + +#------------------------------------------------------------------------------------ +# GetFilename +# +# Parameters: +# $text +#------------------------------------------------------------------------------------ +sub GetFilename +{ + my ($file) = @_; + $file =~ s/\//\\/g; # / -> \ + my $pos = rindex($file, "\\"); + die("Invalid path: $file\n") if($pos == -1); + return substr($file, $pos+1); +} + +#------------------------------------------------------------------------------------ +# RemoveWhiteSpaces +# +# Parameters: +# $text +#------------------------------------------------------------------------------------ +sub RemoveWhiteSpaces() +{ + my ($text) = @_; + ${$text} =~ s/\s+$//; #whitespaces in the end + ${$text} =~ s/^\s+//; #whitespaces at the start +} + +#------------------------------------------------------------------------------------ +# Timestamp +# +# Parameters: +#------------------------------------------------------------------------------------ +sub Timestamp +{ + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); + + return "" . ($year+1900) . "-" . ($mon+1) . "-" . $mday . "-" . $hour . "-" . $min; +}