Skip to content
Snippets Groups Projects
Commit 55142eae authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- added support for multiple search dirs

parent 63e18fa0
Branches
Tags
No related merge requests found
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment