[librecat-dev] Error when processing the same file twice

Mayr-Duffner, Georg georg.mayr-duffner at wu.ac.at
Mon Dec 3 21:10:34 CET 2018


Hi Patrick,

thanks for your help. I finally could fix the issue. I‘ve always looked in the wrong place, changing whatever possible in the marc fixing part because of the error message.

I loaded the fix files via relative paths like 'fixFolder/fixfile.fix' (assuming that relative paths are always calculated from the appdir path). This worked well if I commented out one or the other fixing part. With both of them uncommented I got it to work by defining the paths absolutely.

Now it works but I don‘t understand why it hasn‘† before.

Best regards
Georg

Am 03.12.18, 16:51 schrieb "Patrick Hochstenbach" <Patrick.Hochstenbach at UGent.be>:

    Hi Georg
    
    I also tested the code in Dancer2 and still I get the correct answer. Here is my code, can you try that?
    
    
    # test.pl
    use Dancer2;
    
    get '/' => sub {
        use Catmandu;
    
        my $importer1 = Catmandu->importer('MARC', file => 'camel.mrc');
        my $fixer1    = Catmandu::Fix->new(fixes => ['add_field(foo,bar)']);
    
        my $exporter1  = Catmandu->exporter('JSON', file => 'test.json');
    
        $exporter1->add_many($fixer1->fix($importer1));
        $exporter1->commit;
    
        my $importer2 = Catmandu->importer('MARC', file => 'camel.mrc');
        my $fixer2    = Catmandu::Fix->new(fixes => ['add_field(foo,bar)']);
    
        my $exporter2  = Catmandu->exporter('MARC', file => 'test.mrc');
    
        $exporter2->add_many($fixer2->fix($importer2));
        $exporter2->commit;
    
        "Done!";
    };
    dance;
    
    
    $ perl test.pl
    
    and visit http://localhost:3000
    
    Br
    Patrick
    
    > On 28 Nov 2018, at 11:11, Mayr-Duffner, Georg <georg.mayr-duffner at wu.ac.at> wrote:
    > 
    > Hello Patrick,
    > 
    > thank you for your quick response. Yes, that works for me. Also, a more complex version does. But as soon as called from the Dancer2 subroutine, it breaks.
    > 
    > Best regards
    > Georg
    > 
    > Am 28.11.18, 10:32 schrieb "Patrick Hochstenbach" <Patrick.Hochstenbach at UGent.be>:
    > 
    > 
    > 
    >    Hello Georg
    > 
    >    I can’t repeat the error on my machine with a simplified version of your script. I use Catmandu 1.09 and Catmandu::MARC 1.231.
    > 
    >    Can you run the ‘test.pl’ script in the attachement and see if you sill get the errors you report?
    > 
    >    Patrick
    > 
    >> On 27 Nov 2018, at 21:39, Mayr-Duffner, Georg <georg.mayr-duffner at wu.ac.at> wrote:
    >> 
    >> Hello,
    >> 
    >> I‘m trying to set up a web service (with dancer2) that does some Catmandu transformations and I‘m hopelessly stuck. I try to first do a MARC to JSON conversion to get some data out of a MARC input file (which in the end will go into a MongoDB) and then the same input file should be processed again in order to output an enriched MARC file. I can run one or the other but when I try to process both I get an error 
    >> 
    >> Can't locate object method "new" via package "Catmandu::Exporter::MARC" at /Users/gduffner/perl5/perlbrew/perls/perl-5.26.2/lib/site_perl/5.26.2/Catmandu/Env.pm line 219, <GEN2> line 12.
    >> 
    >> Could you please help me track that down?
    >> 
    >> Here’s the code of the subroutine:
    >> 
    >> post '/cleanupMarc' => sub {
    >>   my $sigel = param('paketSigel');
    >>   my $type  = param('inputFileType');
    >>   my $packagemonth = param('packageMonth');
    >> 
    >>   my $input = request->upload('inputFile');
    >>   my $uploaddir   = path(config->{appdir}, 'uploads');
    >>   mkdir $uploaddir if not -e $uploaddir;
    >>   my $inputpath  = path($uploaddir, $input->basename);
    >>   $input->copy_to($inputpath);
    >> 
    >>   my $dldir = path(config->{public_dir}, 'downloads');
    >>   mkdir $dldir if not -e $dldir;
    >> 
    >>   # marc2json
    >>   my $jsonOutput = "$dldir/output1.json";
    >> 
    >>   my $jsonImporter = Catmandu->importer('MARC', file => $inputpath);#, type => $type);
    >> 
    >>   my $jsonFixer = Catmandu::Fix->new(
    >>       variables => { sigel => $sigel, },
    >>       fixes => ['fixfiles/IDs2json.fix'],
    >>   );
    >>   my $jsonExporter = Catmandu->exporter('JSON', file => $jsonOutput);
    >>   my $fixed_jsonImporter = $jsonFixer->fix($jsonImporter);
    >>   $jsonExporter->add_many($fixed_jsonImporter->benchmark);
    >>   $jsonExporter->commit;
    >>   undef($jsonExporter);
    >> 
    >>   # marc2marc
    >>   my $marcOutput = "$dldir/output.mrc";
    >>   my $marcImporter  = Catmandu->importer('MARC', file => $inputpath);#, type => $type);
    >>   my $marcFixer = Catmandu::Fix->new(
    >>       variables => { sigel => $sigel,
    >>                      MARC2ISO => 'fixfiles/marc2iso3166H.csv',
    >>                      ISO2MARC => 'fixfiles/iso3166H2marc.csv',
    >>                      today => '20181122',},
    >>       fixes => ['fixfiles/ebook.fix'],
    >>   );
    >>   my $marcExporter = Catmandu->exporter('MARC', file => $marcOutput);
    >>   my $fixed_marcImporter = $marcFixer->fix($marcImporter);
    >>   $marcExporter->add_many($fixed_marcImporter->benchmark);
    >>   $marcExporter->commit;
    >>   undef($marcExporter);
    >> 
    >>   redirect('/');
    >> };
    >> 
    >> Thank you very much!
    >> 
    >> Best regards
    >> Georg
    >> 
    >> 
    >> 
    >> _______________________________________________
    >> librecat-dev mailing list
    >> - send list mails to librecat-dev at lists.uni-bielefeld.de
    >> - to unsubscribe or change options, visit https://lists.uni-bielefeld.de/mailman2/cgi/unibi/listinfo/librecat-dev
    >> - project website: http://librecat.org/
    > 
    > 
    > 
    
    




More information about the librecat-dev mailing list