From 55142eae55645d3fbf870e1ad030883c3083d6ff Mon Sep 17 00:00:00 2001 From: Andreas Romeyke <art1@andreas-romeyke.de> Date: Mon, 2 Aug 2021 08:55:40 +0200 Subject: [PATCH] - added support for multiple search dirs --- perl/exit_strategy.pl | 147 ++++++++++++++++++++++++------------------ 1 file changed, 83 insertions(+), 64 deletions(-) diff --git a/perl/exit_strategy.pl b/perl/exit_strategy.pl index 1a323f3..c1188a2 100644 --- a/perl/exit_strategy.pl +++ b/perl/exit_strategy.pl @@ -394,47 +394,55 @@ sub check_if_db_conform ($string, $filename) { } } -sub searching_ie_files ($dir, $tmp_ies_unsorted_file) { +sub searching_ie_files ($dirs_ref, $tmp_ies_unsorted_file) { my $cnt_unsorted_files = 0; - 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 $pass = 0; + my @dirs = @{ $dirs_ref }; + 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); - if ($depth <= 2) { - print $progressbar->report("find IE files: %40b ETA: %E \r", $dircount++); + + $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; } - } - return; - }; - ### - find($wanted_process_sip, $dir); - say ""; + 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 ""; + } + return $cnt_unsorted_files; } @@ -482,40 +490,51 @@ if ($#ARGV_tail < 0) { die "you need a directory as argument\n"; } -my $dir = shift @ARGV_tail; - -if (defined $dir && -d "$dir") { - say "preparing SQL"; - $tmp_ies_unsorted_file->touch(); - say "searching IE files"; - my $cnt_unsorted_files = searching_ie_files($dir, $tmp_ies_unsorted_file); - # /permanent_storage/2020/04/02/IE201080/V1-FL201091.xml - # /permanent_storage/2020/04/02/IE201080/V2-FL201091.xml - my $fh_unsorted_IEs = $tmp_ies_unsorted_file->openr(); - my $count = 0; - my $progressbar = Time::Progress->new(min => 0, max => $cnt_unsorted_files, smoothing => 1); +say "preparing SQL"; +my $dbh = DBI->connect("dbi:SQLite:dbname=$db_filename", "", "", { + RaiseError => 1, + sqlite_unicode => 1, +}) or die "could not connect to database (file '$db_filename')", $DBI::errstr; +write_database_creation($dbh); +write_tables_creation($dbh); +write_prepare_insert($dbh); +write_index_creation($dbh); +$dbh->disconnect or warn("disconnecting problems, ", $dbh->errstr); + +if (0==@ARGV_tail ){ + die "no directory given on commandline" +} +my @dirs; +while (@ARGV_tail > 0) { + my $dir = shift @ARGV_tail; + + if (defined $dir && -d "$dir") { + push @dirs, $dir; + } +} +$tmp_ies_unsorted_file->touch(); +say "searching IE files"; +my $cnt_unsorted_files = searching_ie_files(\@dirs, $tmp_ies_unsorted_file); +# /permanent_storage/2020/04/02/IE201080/V1-FL201091.xml +# /permanent_storage/2020/04/02/IE201080/V2-FL201091.xml +my $fh_unsorted_IEs = $tmp_ies_unsorted_file->openr(); +my $count = 0; +my $progressbar = Time::Progress->new(min => 0, max => $cnt_unsorted_files, smoothing => 1); +while (<$fh_unsorted_IEs>) { + chomp; + print $progressbar->report("parse IE files: %40b ETA: %E \r", $count++); + s/V0*(\d+-IE)/V$1/; # revert fake version + my $ret = parse_iexml($_, $flag_recovery); my $dbh = DBI->connect("dbi:SQLite:dbname=$db_filename", "", "", { RaiseError => 1, sqlite_unicode => 1, }) or die "could not connect to database (file '$db_filename')", $DBI::errstr; - write_database_creation($dbh); - write_tables_creation($dbh); - write_prepare_insert($dbh); - write_index_creation($dbh); - while (<$fh_unsorted_IEs>) { - chomp; - print $progressbar->report("parse IE files: %40b ETA: %E \r", $count++); - s/V0*(\d+-IE)/V$1/; # revert fake version - my $ret = parse_iexml($_, $flag_recovery); - write_addsql($dbh, $ret); - } - say ""; + write_addsql($dbh, $ret); $dbh->disconnect or warn("disconnecting problems, ", $dbh->errstr); - say "processed $count uniq IEs"; -} -else { - die "no directory given on commandline" } +say ""; +say "processed $count uniq IEs"; + say ""; 1; -- GitLab