diff --git a/perl/exit_strategy.pl b/perl/exit_strategy.pl index c1188a29833ccd842c71bc42e85f802aa3b17e8d..156b750717bace660a319a3cba39e31994a300ac 100644 --- a/perl/exit_strategy.pl +++ b/perl/exit_strategy.pl @@ -394,6 +394,53 @@ sub check_if_db_conform ($string, $filename) { } } +sub searching_relevant_subdirs ($dir) { + my $first_two_levels_of_dirs = 0; + ### + my $wanted_twolevel_dircount = sub { + my $relpath = $File::Find::name; + $relpath =~ s{^\Q$dir\E/?}{}; + my $depth = File::Spec->splitdir($relpath); + + $depth >= 2 + and $File::Find::prune = 1; + if (-d $_) {$first_two_levels_of_dirs++;} + }; + ### + find($wanted_twolevel_dircount, $dir); + return $first_two_levels_of_dirs; +} + +sub searching_relevant_ie_files ($dir, $tmp_ies_unsorted_file, $first_two_levels_of_dirs) { + my $progressbar = Time::Progress->new(min => 0, max => $first_two_levels_of_dirs, smoothing => 1); + ### + my $dircount = 0; + my $wanted_process_sip = sub { + if (-f && m/V(\d+)-IE\d+\.xml$/) { + my $version = $1; + my $file = $File::Find::name; + # fake name to ue alphabetical sort + my $fakeversion = sprintf("%05i", $version); + $file =~ s/V(\d+)-IE/V$fakeversion-IE/; + $tmp_ies_unsorted_file->append($file . "\n"); + $dircount++; + $File::Find::prune = 1; + } + elsif (-d) { + my $relpath = $File::Find::name; + $relpath =~ s{^\Q$dir\E/?}{}; + my $depth = File::Spec->splitdir($relpath); + if ($depth <= 2) { + print $progressbar->report("find IE files: %40b ETA: %E \r", $dircount); + } + } + return; + }; + ### + find($wanted_process_sip, $dir); + return $dircount; +} + sub searching_ie_files ($dirs_ref, $tmp_ies_unsorted_file) { my $cnt_unsorted_files = 0; my $pass = 0; @@ -401,48 +448,12 @@ sub searching_ie_files ($dirs_ref, $tmp_ies_unsorted_file) { my $maxpass=scalar @dirs; foreach my $dir (@dirs) { $pass++; - my $first_two_levels_of_dirs = 0; - ### - my $wanted_twolevel_dircount = sub { - my $relpath = $File::Find::name; - $relpath =~ s{^\Q$dir\E/?}{}; - my $depth = File::Spec->splitdir($relpath); - - $depth >= 2 - and $File::Find::prune = 1; - if (-d $_) {$first_two_levels_of_dirs++;} - }; - ### - find($wanted_twolevel_dircount, $dir); - my $progressbar = Time::Progress->new(min => 0, max => $first_two_levels_of_dirs, smoothing => 1); - my $dircount = 0; - ### - my $wanted_process_sip = sub { - if (-f && m/V(\d+)-IE\d+\.xml$/) { - my $version = $1; - my $file = $File::Find::name; - # fake name to ue alphabetical sort - my $fakeversion = sprintf("%05i", $version); - $file =~ s/V(\d+)-IE/V$fakeversion-IE/; - $tmp_ies_unsorted_file->append($file . "\n"); - $cnt_unsorted_files++; - $File::Find::prune = 1; - } - elsif (-d) { - my $relpath = $File::Find::name; - $relpath =~ s{^\Q$dir\E/?}{}; - my $depth = File::Spec->splitdir($relpath); - if ($depth <= 2) { - print $progressbar->report("find IE files (pass $pass/$maxpass: %40b ETA: %E \r", $dircount++); - } - } - return; - }; - ### - find($wanted_process_sip, $dir); - say ""; + my $first_two_levels_of_dirs = searching_relevant_subdirs($dir); + my $count = searching_relevant_ie_files($dir, $tmp_ies_unsorted_file, $first_two_levels_of_dirs); + say "found $count IEs in pass $pass/$maxpass ($dir) "; + $cnt_unsorted_files+=$count; } - + say "\r "; return $cnt_unsorted_files; } @@ -507,7 +518,6 @@ if (0==@ARGV_tail ){ my @dirs; while (@ARGV_tail > 0) { my $dir = shift @ARGV_tail; - if (defined $dir && -d "$dir") { push @dirs, $dir; } @@ -532,8 +542,7 @@ while (<$fh_unsorted_IEs>) { write_addsql($dbh, $ret); $dbh->disconnect or warn("disconnecting problems, ", $dbh->errstr); } -say ""; -say "processed $count uniq IEs"; +say "\rprocessed $count uniq IEs "; say "";