package Ernad::Recon; use strict; use warnings; use base 'Ernad'; use Carp qw(confess); use Data::Dumper; # use Ernad::Rix; use File::Basename; use File::Path; sub init { my $r=shift(); my $e=$r->{'e'} // $main::e // confess "I have no erimp"; my $etc_dir; if (not $etc_dir=$e->{'dir'}->{'etc'}) { confess "I need the etc directory set here."; } my $conf; if (not $conf=$e->{'conf'}) { confess "I need the ernad configuration set here."; } ## FixMe, there should be a general file lister my $amf_ext=$e->{'const'}->{'amf_ext'} // confess "I need this here"; my $enabled_dir="$etc_dir/reports/enabled"; my $available_dir="$etc_dir/reports/available"; my $glob="$enabled_dir/*$amf_ext"; $r->{'dir'}->{'enabled'}=$enabled_dir; $r->{'dir'}->{'available'}=$available_dir; $r->{'glob'}=$glob; $r->{'e'}=$e; } sub enabled_link { my $r=shift; my $repcode=shift // $main::repcode // confess "I need a repcode here."; my $amf_ext=$r->{'e'}->{'const'}->{'amf_ext'} // confess "I need this here"; my $enabled_dir=$r->{'dir'}->{'enabled'} // confess 'I have no enabled dir'; my $enabled_link=$enabled_dir."/$repcode$amf_ext"; return $enabled_link; } sub available_file { my $r=shift; my $repcode=shift // $main::repcode // confess "I need a repcode here."; my $amf_ext=$r->{'e'}->{'const'}->{'amf_ext'} // confess "I need this here"; my $available_dir=$r->{'dir'}->{'available'} // confess 'I have no available dir'; my $available_file=$available_dir."/$repcode$amf_ext"; return $available_file; } sub real_file { my $r=shift; my $enabled_link=shift // confess "I need a file."; if (not -l $enabled_link) { return ''; } my $file=readlink($enabled_link); my $bana=basename($file); my $real_file=$r->{'dir'}->{'available'}.'/'.$bana; return $real_file; } sub is_it_enabled { my $r=shift; my $repcode=shift // $main::repcode // confess "I need a repcode here."; my $enabled_link=$r->enabled_link($repcode); if(not -l $enabled_link) { return ''; } my $available_file=$r->available_file($repcode); if(not -f $available_file) { return ''; } return $enabled_link; } sub is_it_available { my $r=shift; my $repcode=shift // $main::repcode // confess "I need a repcode here."; my $available_file=$r->available_file($repcode); if(not -f $available_file) { return ''; } return $available_file; } ## <-- just by removing the enabled link sub enable { my $r=shift; $r->init(); my $repcode=shift // confess 'I need a repcode here.'; my $enabled_link=$r->enabled_link($repcode); if(-l $enabled_link) { return 0; } my $file=$r->available_file($repcode); if(not -f $file) { $r->{'e'}->echo(__LINE__,"I don't see '$file'."); return ''; } my $dir=$r->{'dir'}->{'enabled'}; my $bana=basename($file); my $s; if(-w $dir) { $s="cd $dir ; ln -s ../available/$bana $bana"; } else { my $admin_user=$r->{'e'}->{'conf'}->{'adminUser'}; if($admin_user) { $s="cd $dir ; sudo -u $admin_user ln -s ../available/$bana $bana"; } else { return ''; } } system($s); if(-l $enabled_link) { return 1; } return ''; } ## <-- just by removing the enabled link sub disable { my $r=shift; my $repcode=shift // confess 'I need a repcode here.'; my $do_strict=shift // '1'; $r->init(); my $enabled_link=$r->enabled_link($repcode); if(not -l $enabled_link) { ## nothing to do return 0; } unlink $enabled_link; if(not -l $enabled_link) { return 1; } ## try via sudo my $admin_user=$r->{'e'}->{'conf'}->{'adminUser'}; if(not $admin_user) { $r->fail_unlink($enabled_link); return; } my $s="/usr/bin/sudo -u $admin_user unlink $enabled_link"; system($s); if(not -l $enabled_link) { return 1; } $r->fail_unlink($enabled_link); ## nothing done return ''; } sub fail_unlink { my $r=shift; my $target=shift // confess 'I need a target here.'; my $lsl=`ls -l $target`; chomp $lsl; confess "I could not delete $lsl"; } ## <-- load a report, returns a doc on success, error string on failure sub load { my $r=shift; my $repcode=shift // $main::repcode // confess "I need a repcode here."; ## we also load a non-enabled report if this is set my $params=shift // {}; my $ref_params=ref($params); if(not $ref_params eq 'HASH') { confess "My second argument needs to be a hashref, not a '$ref_params'."; } my $needs_to_be_enabled=$params->{'enabled'} // 1; $r->init(); my $e=$r->{'e'}; my $amf_ext=$e->{'const'}->{'amf_ext'}; my $amf_ns=$e->{'const'}->{'amf_ns'}; my $link=$r->enabled_link($repcode); my $xpc=$e->{'xpc'} // confess "I need my xpc here."; my $enabled_dir=$r->{'dir'}->{'enabled'}; if(not -d $r->{'dir'}->{'enabled'}) { confess "I don't see your enabled dir $enabled_dir"; } my $file=$r->is_it_available($repcode); if(not $r->is_it_available($repcode)) { return 'no_such_report_available'; } my $allport_repcode=$e->{'conf'}->{'allport_repcode'}; ## check if the report is enabled unless it is the allport if(not ($e->{'conf'}->{'allport_repcode'} and $repcode eq $allport_repcode)) { if(not $r->is_it_enabled($repcode)) { if($needs_to_be_enabled) { return 'exists_but_not_enabled'; } } } if(not $r->{'dir'}) { $r->init(); } my $doc; eval { $doc = XML::LibXML->load_xml(location => $file); }; if(not $doc) { return 'colldoc_misformed'; } my $root_ele=$doc->documentElement; my $coll_ele; if ($root_ele->nodeName eq 'amf') { $coll_ele=$root_ele->getElementsByTagNameNS($amf_ns,'collection')->[0]; } else { $coll_ele=$root_ele; } my $configured_repcode=$e->find_repcode_from_collection($coll_ele); if($configured_repcode ne $repcode) { return 'colldoc_misformed'; } my $start=$e->{'x'}->find_start_from_collection($coll_ele); ## store report code in an array ## if this is defined, it is the full list. Appending to it defines it. #if(not $e->{'report'}->{$repcode}) { # push(@{$e->{'repcodes'}},$repcode); #} ## add the AMF back ## wrap in amf. All stylesheets still assume that wrapping my $rep_amfdoc=$e->{'amfdoc'}->cloneNode(1); $rep_amfdoc->documentElement->appendChild($doc->documentElement); $rep_amfdoc->documentElement->appendText("\n"); ## a local abbreviatan my $rerc=$e->{'report'}->{$repcode}; $rerc->{'repcode'}=$repcode; if ($start) { $rerc->{'start'}=$start; } $rerc->{'colldoc'}=$coll_ele; $rerc->{'repdoc'}=$rep_amfdoc; #print "repcode is $repcode\n"; ## store collection $rerc->{'id'}=$coll_ele->getAttribute('id'); $rerc->{'xml'}->{'collection'}=$coll_ele; ## these may be undefined for defunct reports. # $rerc->{'xml'}->{'editor'}=Ernad::Common::find_editor_element_from_collection($coll_ele); if(not $e->{'x'}) { confess ; } $rerc->{'xml'}->{'editor'}=$e->{'x'}->find_editor_element_from_collection($coll_ele); $rerc->{'xml'}->{'password'}= &Ernad::Common::find_password_element_from_collection($coll_ele); $rerc->{'earliest_train_date'}= &Ernad::Common::find_earliest_train_date_from_collection($coll_ele); ## probably not being used any more # $rerc->{'issue_to_email'}=$repcode.'@'.$e->{'conf'}->{'list_domain'}; ## truncation if(defined($e->{'conf'}->{'truncate'})) { $rerc->{'truncate'}=$e->{'conf'}->{'truncate'}; ## report-specific truncation my $own_truncate=$xpc->findvalue('./e:truncate/text()',$coll_ele) // ''; if ($own_truncate) { $rerc->{'truncate'}=$own_truncate; } } my $editor_xml=$rerc->{'xml'}->{'editor'}; ## there may be no password ... if (defined($rerc->{'xml'}->{'password'})) { $rerc->{'password'}=$rerc->{'xml'}->{'password'}->textContent; } ## look for the status if ($xpc->findnodes('./e:testing',$coll_ele) or $xpc->findvalue('./e:testing/text()',$coll_ele)) { $rerc->{'testing'}='testing'; } ## do we publish? if ($xpc->findnodes('./e:no_publish',$coll_ele) or $xpc->findvalue('./e:no_publish/text()',$coll_ele)) { $rerc->{'no_publish'}='no_publish'; $rerc->{'no_mail'}='no_publish'; } ## do we mail out? elsif ($xpc->findnodes('./e:no_mail',$coll_ele) or $xpc->findvalue('./e:no_mail/text()',$coll_ele)) { $rerc->{'no_mail'}='no_mail'; } ## look for the mayr_presort if ($xpc->findnodes('./e:mayr_presort',$coll_ele)) { $rerc->{'mayr_presort'}='mayr_presort'; } my $start_date=$xpc->findvalue('./e:active/@start',$coll_ele) // ''; if ($start_date) { $rerc->{'start'}=$start_date; } my $end_date=$xpc->findvalue('./e:active/@end',$coll_ele) // ''; if ($end_date) { $rerc->{'end'}=$end_date; } ## set the report directories $rerc->{'path'}=$e->{'dir'}->{'reports'}.'/'.$repcode; foreach my $stage (@{$e->{'const'}->{'stages'}}) { #print "stage is $stage\n"; my $dir=$rerc->{'path'}.'/'.$stage; $rerc->{'dir'}->{$stage}=$dir; if(not -d $dir and -w (dirname($dir))) { mkpath $dir; } $rerc->{'dir'}->{'mail'}=$e->{'const'}->{'mail_dir'}; ## if seedable, ps and sd if($stage eq 'source') { if($e->{'conf'}->{'is_seedable'}) { foreach my $ussd ($e->{'const'}->{'presorted_dir'}, $e->{'const'}->{'seeded_dir'}) { my $ussd_dir=$dir.'/'.$ussd; if (not -d $ussd_dir) { mkdir $ussd_dir; } } } ## if not seedable, us and ps else { foreach my $usps ($e->{'const'}->{'unsorted_dir'}, $e->{'const'}->{'presorted_dir'}) { my $usps_dir=$dir.'/'.$usps; if (not -d $usps_dir) { mkdir $usps_dir; } } } } $rerc->{'dir'}->{'notify'}=$rerc->{'path'}.'/'.$e->{'const'}->{'notify_dir'}; } ## add source dirs my $dir=$rerc->{'dir'}; $dir->{'unsorted'}=$dir->{'source'}.'/'.$e->{'const'}->{'unsorted_dir'}; $dir->{'adrep'}=$e->{'dir'}->{'adrep'}.'/'.$repcode; $dir->{'presorted'}=$dir->{'source'}.'/'.$e->{'const'}->{'presorted_dir'}; $dir->{'issues'}=$e->{'dir'}->{'web'}.'/'.$e->{'const'}->{'issues'}.'/'.$repcode; # OLD $dir->{'blatt'}=$rerc->{'path'}.'/'.$e->{'const'}->{'blatt'}.'/'.$repcode; $dir->{'blatt'}=$e->{'dir'}->{'blatt'}.'/reports/'.$repcode; $dir->{'seeded'}=$dir->{'source'}.'/'.$e->{'const'}->{'seeded_dir'}; $dir->{'cache'}=$rerc->{'path'}.'/'.$e->{'const'}->{'cache_dir'}; #$rerc->{'xml'}->{'editor'}; #print $rerc->{'xml'}->{'editor'}->toString; if ($rerc->{'xml'}->{'editor'}) { my $email=$xpc->findvalue('./amf:person/amf:email',$rerc->{'xml'}->{'editor'}); #print "$email\n"; $rerc->{'editor_email'}=$email; } ## this must stay here, otherwise rerc is lost $rerc->{'doc'}=$doc->cloneNode(1); $e->{'report'}->{$repcode}=$rerc; $e->{'load_time'}->{$repcode}=time(); $e->{'repdoc'}->{$repcode}=$rep_amfdoc; return $rep_amfdoc; } ## splits the load into two sub new_load { my $r=shift; my $repcode=shift // $main::repcode // confess "I need a repcode here."; ## we also load a non-enabled report if this is set my $params=shift // {}; my $ref_params=ref($params); if(not $ref_params eq 'HASH') { confess "My second argument needs to be a hashref, not a '$ref_params'."; } my $needs_to_be_enabled=$params->{'enabled'} // 1; $r->config($repcode,$params); return $r->deep_load($repcode,$params); } ## <-- load a report, returns a doc on success, error string on failure sub config { my $r=shift; my $repcode=shift // $main::repcode // confess "I need a repcode here."; ## we also load a non-enabled report if this is set my $params=shift // {}; my $ref_params=ref($params); if(not $ref_params eq 'HASH') { confess "My second argument needs to be a hashref, not a '$ref_params'."; } my $needs_to_be_enabled=$params->{'enabled'} // 1; $r->init(); my $e=$r->{'e'}; my $link=$r->enabled_link($repcode); my $enabled_dir=$r->{'dir'}->{'enabled'}; if(not -d $r->{'dir'}->{'enabled'}) { confess "I don't see your enabled dir $enabled_dir"; } my $file=$r->is_it_available($repcode); if(not $r->is_it_available($repcode)) { return 'no_such_report_available'; } my $allport_repcode=$e->{'conf'}->{'allport_repcode'}; ## check if the report is enabled unless it is the allport if(not ($e->{'conf'}->{'allport_repcode'} and $repcode eq $allport_repcode)) { if(not $r->is_it_enabled($repcode)) { if($needs_to_be_enabled) { return 'exists_but_not_enabled'; } } } if(not $r->{'dir'}) { $r->init(); } ## a local abbreviatan my $rerc=$e->{'report'}->{$repcode}; $rerc->{'repcode'}=$repcode; ## set the report directories $rerc->{'path'}=$e->{'dir'}->{'reports'}.'/'.$repcode; foreach my $stage (@{$e->{'const'}->{'stages'}}) { #print "stage is $stage\n"; my $dir=$rerc->{'path'}.'/'.$stage; $rerc->{'dir'}->{$stage}=$dir; if(not -d $dir and -w (dirname($dir))) { mkpath $dir; } $rerc->{'dir'}->{'mail'}=$e->{'const'}->{'mail_dir'}; ## if seedable, ps and sd if($stage eq 'source') { if($e->{'conf'}->{'is_seedable'}) { foreach my $ussd ($e->{'const'}->{'presorted_dir'}, $e->{'const'}->{'seeded_dir'}) { my $ussd_dir=$dir.'/'.$ussd; if (not -d $ussd_dir) { mkdir $ussd_dir; } } } ## if not seedable, us and ps else { foreach my $usps ($e->{'const'}->{'unsorted_dir'}, $e->{'const'}->{'presorted_dir'}) { my $usps_dir=$dir.'/'.$usps; if (not -d $usps_dir) { mkdir $usps_dir; } } } } $rerc->{'dir'}->{'notify'}=$rerc->{'path'}.'/'.$e->{'const'}->{'notify_dir'}; } ## add source dirs my $dir=$rerc->{'dir'}; $dir->{'unsorted'}=$dir->{'source'}.'/'.$e->{'const'}->{'unsorted_dir'}; $dir->{'adrep'}=$e->{'dir'}->{'adrep'}.'/'.$repcode; $dir->{'presorted'}=$dir->{'source'}.'/'.$e->{'const'}->{'presorted_dir'}; $dir->{'issues'}=$e->{'dir'}->{'web'}.'/'.$e->{'const'}->{'issues'}.'/'.$repcode; # OLD $dir->{'blatt'}=$rerc->{'path'}.'/'.$e->{'const'}->{'blatt'}.'/'.$repcode; $dir->{'blatt'}=$e->{'dir'}->{'blatt'}.'/reports/'.$repcode; $dir->{'seeded'}=$dir->{'source'}.'/'.$e->{'const'}->{'seeded_dir'}; $dir->{'cache'}=$rerc->{'path'}.'/'.$e->{'const'}->{'cache_dir'}; ## final set $e->{'report'}->{$repcode}=$rerc; return ''; } sub deep_load { my $r=shift; my $repcode=shift // $main::repcode // confess "I need a repcode here."; ## we also load a non-enabled report if this is set my $params=shift // {}; my $ref_params=ref($params); if(not $ref_params eq 'HASH') { confess "My second argument needs to be a hashref, not a '$ref_params'."; } # my $xpc=$e->{'xpc'} // confess "I need my xpc here."; my $e=$r->{'e'}; ## repeated ... my $file=$r->is_it_available($repcode); my $amf_ext=$e->{'const'}->{'amf_ext'}; my $amf_ns=$e->{'const'}->{'amf_ns'}; my $xpc=$e->{'xpc'} // confess "I need my xpc here."; my $doc; eval { $doc = XML::LibXML->load_xml(location => $file); }; if(not $doc) { return 'colldoc_misformed'; } my $root_ele=$doc->documentElement; my $coll_ele; if ($root_ele->nodeName eq 'amf') { $coll_ele=$root_ele->getElementsByTagNameNS($amf_ns,'collection')->[0]; } else { $coll_ele=$root_ele; } my $configured_repcode=$e->find_repcode_from_collection($coll_ele); if($configured_repcode ne $repcode) { return 'colldoc_misformed'; } my $start=$e->{'x'}->find_start_from_collection($coll_ele); ## store report code in an array ## if this is defined, it is the full list. Appending to it defines it. #if(not $e->{'report'}->{$repcode}) { # push(@{$e->{'repcodes'}},$repcode); #} ## add the AMF back ## wrap in amf. All stylesheets still assume that wrapping my $rep_amfdoc=$e->{'amfdoc'}->cloneNode(1); $rep_amfdoc->documentElement->appendChild($doc->documentElement); $rep_amfdoc->documentElement->appendText("\n"); ## a local abbreviatan my $rerc=$e->{'report'}->{$repcode}; $rerc->{'repcode'}=$repcode; if ($start) { $rerc->{'start'}=$start; } $rerc->{'colldoc'}=$coll_ele; $rerc->{'repdoc'}=$rep_amfdoc; #print "repcode is $repcode\n"; ## store collection $rerc->{'id'}=$coll_ele->getAttribute('id'); $rerc->{'xml'}->{'collection'}=$coll_ele; ## these may be undefined for defunct reports. # $rerc->{'xml'}->{'editor'}=Ernad::Common::find_editor_element_from_collection($coll_ele); if(not $e->{'x'}) { confess ; } $rerc->{'xml'}->{'editor'}=$e->{'x'}->find_editor_element_from_collection($coll_ele); $rerc->{'xml'}->{'password'}= &Ernad::Common::find_password_element_from_collection($coll_ele); $rerc->{'earliest_train_date'}= &Ernad::Common::find_earliest_train_date_from_collection($coll_ele); ## probably not being used any more # $rerc->{'issue_to_email'}=$repcode.'@'.$e->{'conf'}->{'list_domain'}; ## truncation if(defined($e->{'conf'}->{'truncate'})) { $rerc->{'truncate'}=$e->{'conf'}->{'truncate'}; ## report-specific truncation my $own_truncate=$xpc->findvalue('./e:truncate/text()',$coll_ele) // ''; if ($own_truncate) { $rerc->{'truncate'}=$own_truncate; } } my $editor_xml=$rerc->{'xml'}->{'editor'}; ## there may be no password ... if (defined($rerc->{'xml'}->{'password'})) { $rerc->{'password'}=$rerc->{'xml'}->{'password'}->textContent; } ## look for the status if ($xpc->findnodes('./e:testing',$coll_ele) or $xpc->findvalue('./e:testing/text()',$coll_ele)) { $rerc->{'testing'}='testing'; } ## do we publish? if ($xpc->findnodes('./e:no_publish',$coll_ele) or $xpc->findvalue('./e:no_publish/text()',$coll_ele)) { $rerc->{'no_publish'}='no_publish'; $rerc->{'no_mail'}='no_publish'; } ## do we mail out? elsif ($xpc->findnodes('./e:no_mail',$coll_ele) or $xpc->findvalue('./e:no_mail/text()',$coll_ele)) { $rerc->{'no_mail'}='no_mail'; } ## look for the mayr_presort if ($xpc->findnodes('./e:mayr_presort',$coll_ele)) { $rerc->{'mayr_presort'}='mayr_presort'; } my $start_date=$xpc->findvalue('./e:active/@start',$coll_ele) // ''; if ($start_date) { $rerc->{'start'}=$start_date; } my $end_date=$xpc->findvalue('./e:active/@end',$coll_ele) // ''; if ($end_date) { $rerc->{'end'}=$end_date; } #$rerc->{'xml'}->{'editor'}; #print $rerc->{'xml'}->{'editor'}->toString; if ($rerc->{'xml'}->{'editor'}) { my $email=$xpc->findvalue('./amf:person/amf:email',$rerc->{'xml'}->{'editor'}); #print "$email\n"; $rerc->{'editor_email'}=$email; } ## this must stay here, otherwise rerc is lost $rerc->{'doc'}=$doc->cloneNode(1); $e->{'report'}->{$repcode}=$rerc; $e->{'load_time'}->{$repcode}=time(); $e->{'repdoc'}->{$repcode}=$rep_amfdoc; return $rep_amfdoc; } ## <-- reload will check whether a conf files is never than the reload time sub reload { my $r=shift; my $repcode=shift // $main::repcode // confess "I need a repcode here."; ## optional parameters ... I just pass them on here my $params=shift; $r->init(); my $e=$r->{'e'} // $main::e // confess "I have no erimp"; if (not $r->{'dir'}) { $r->init(); } my $load_time=$e->{'load_time'}->{$repcode} // 0; my $file=$r->available_file($repcode); ## if this is not there, still call load to get to its error codes if(not -f $file) { $r->load($repcode, $params); } my $mtime=&Ernad::Dates::mtime($file); if(not $mtime) { confess "I don't see the mtime on $file"; } if($mtime < $load_time) { return ''; } return $r->load($repcode, $params); } ## <-- lists the repcodes sub list { my $r=shift; my $how=shift // 'array'; if (($how ne 'array') and ($how ne 'hash')) { confess "I don't know how, '$how'?"; } if (($how ne 'array') and ($how ne 'hash')) { confess "I don't know how, '$how'?"; } my $e=$r->{'e'} // $main::e // confess "I have no erimp"; $r->init(); my $array; my $hash; my $count=0; foreach my $file (glob($r->{'glob'})) { ## check if the linked file exists my $real_file=$r->real_file($file) or next; if (not -f $real_file) { next; } $file=$real_file; my $bana=basename($file); my $repcode=substr($bana,0,length($bana)-8); if ($e->{'conf'}->{'allport_repcode'} and $repcode eq $e->{'conf'}->{'allport_repcode'}) { next; } push(@{$r->{'reports'}},$repcode); ## push something so we have something listed $r->{'report'}->{$repcode}->{'file'}=$file; ## to return $hash->{$repcode}=$file; $array->[$count++]=$repcode; } $e->{'repcodes'}=$array; if($how eq 'hash') { return $hash; } return $array; } ## <-- archive configurations sub archive { my $r=shift; my $e=$r->{'e'} // $main::e // confess "I have no erimp"; ## used externally $r->init(); ## get the user id my $user=`/usr/bin/whoami`; chomp $user; my $uid=$<; my $archive_dir=''; my $admin_user=$e->{'conf'}->{'adminUser'} // ''; if($admin_user) { if($user ne $admin_user) { print "This must be run as the admin user.\n"; exit; } $archive_dir=$ENV{'HOME'}.'/archive'; } else { print "This must be run as the admin user.\n"; exit; } my $amf_ext=$e->{'const'}->{'amf_ext'} // confess 'I need this here.'; my $amf_ext_length=length($amf_ext); my $glob=$r->{'dir'}->{'available'}.'/*'.$amf_ext; foreach my $fufi (glob($glob)) { my $date=&Ernad::Dates::mdate($fufi); $e->echo(__LINE__,"I see the file $fufi"); my $bana=basename($fufi); ## ok does not take a my $repcode=substr($bana,0,length($bana)-$amf_ext_length); $e->echo(__LINE__,"It's repcode is '$repcode'."); my $archive_glob="$archive_dir/$repcode*"; my @archive_files=glob($archive_glob); my $target="$archive_dir/$repcode"."_$date$amf_ext"; if(not scalar(@archive_files)) { system("cp -a $fufi $target"); next; } my $last=$archive_files[$#archive_files]; $e->echo(__LINE__,"My last version is $last."); my $diff=`diff -w $fufi $last`; chomp $diff; if(not $diff) { $e->echo(__LINE__,"I see nothing new for $fufi."); next; } system("cp -a $fufi $target"); } } sub hashref { my $r=shift; my $e=$r->{'e'} // $main::e // confess "I have no erimp"; ## not used externally yet #$r->init(); my $hash; my $count=0; foreach my $file (glob($r->{'glob'})) { ## check if the linked file exists my $real_file=$r->real_file($file) or next; if (not -f $real_file) { next; } $file=$real_file; my $bana=basename($file); ## takes the .amf.xml out my $repcode=substr($bana,0,length($bana)-8); if($e->{'conf'}->{'allport_repcode'} and $repcode eq $e->{'conf'}->{'allport_repcode'}) { next; } $hash->{$repcode}=$file; } return $hash; } ## <-- gets the repdoc sub doc { my $r=shift; my $repcode=shift // $main::repcode; $r->init(); ## this prepares the file names my $files=$r->hashref(); my $file=$files->{$repcode}; if(not $file) { confess "I don't know about your repcode '$repcode'"; } my $doc=&Ernad::Common::load_and_return_xml($file); return $doc; } ## <-- used in the piles, probably useless but adding in hest 2018-12-11 sub allport_collection { my $r=shift; my $e=$r->{'e'} // $main::e // confess "I have no erimp"; my $allport_repcode=$e->{'conf'}->{'allport_repcode'} // confess 'I need this.'; my $file=$r->available_file($allport_repcode); if(not -f $file) { confess 'I need a file $file here.'; } my $doc=&Ernad::Common::load_and_return_xml($file); #my $amf_ns=$e->{'const'}->{'amf_ns'}; #my $col_ele=$doc->getElementsByTagNameNS($amf_ns,'collection')->[0]->cloneNode(1); #my $doc=&XML::LibXML::Document->new('1.0','UTF-8'); #$doc->setDocumentElement($col_ele); return $doc->documentElement(); } ## <-- returns something like the previous reports.amf.xml sub assemble { my $r=shift; $r->init(); my $e=$r->{'e'} // $main::e // confess "I have no erimp"; my $doc=$e->read_impdoc(); ## this has the files for the reports my $files=$r->hashref(); my $amf_ns=$e->{'const'}->{'amf_ns'}; my $col_ele=$doc->getElementsByTagNameNS($amf_ns,'collection')->[0]; ## sort because this is what the NEP homepage usually has foreach my $repcode (sort keys %$files) { my $file=$files->{$repcode}; my $report_doc=&Ernad::Common::load_and_return_xml($file); my $repcol_ele=$report_doc->documentElement(); ## does not seem to work $repcol_ele->removeAttribute('xmlns:ernad'); $repcol_ele->removeAttribute('xmlns:amf'); my $haspart_ele=$doc->createElementNS($amf_ns,'haspart'); $haspart_ele->appendText("\n"); $haspart_ele->appendChild($repcol_ele); $haspart_ele->appendText("\n"); $col_ele->appendChild($haspart_ele); $col_ele->appendText("\n"); } return $doc->cloneNode(1); } 1;