| 1 | #!/usr/bin/perl | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use File::Temp qw(tempdir); | ||
| 5 | use oEdtk::Config qw(config_read); | ||
| 6 | use Archive::Zip qw(:ERROR_CODES); | ||
| 7 | |||
| 8 | if ( @ARGV != 2 or $ARGV[0] =~ /-h/i ) { | ||
| 9 | die | ||
| 10 | "Usage: $0 NOM_APP DATA_FILE\n\n For GED data recovery (runs the composition and GED preparation)\n"; | ||
| 11 | } | ||
| 12 | |||
| 13 | my @files; | ||
| 14 | my $app = $ARGV[0]; | ||
| 15 | my $file = $ARGV[1]; | ||
| 16 | warn "INFO: processing $app requested for $file\n"; | ||
| 17 | my $cfg = config_read('COMPO'); | ||
| 18 | my $workdir = tempdir( 'edtkXXXXXXX', DIR => $cfg->{'EDTK_DIR_APPTMP'} ); | ||
| 19 | chmod( 0777, $workdir ); | ||
| 20 | chdir($workdir); | ||
| 21 | warn "INFO: workdir = $workdir\n"; | ||
| 22 | |||
| 23 | # IS THE DATA FILE COMPRESSED ? | ||
| 24 | if ( $file =~ /\.zip$/i ) { | ||
| 25 | my $zip = Archive::Zip->new($file); | ||
| 26 | @files = $zip->members(); | ||
| 27 | $zip->extractTree(); | ||
| 28 | |||
| 29 | } | ||
| 30 | elsif ( $file =~ /\.gz$/i || $file =~ /\.z$/i ) { | ||
| 31 | $files[0] = $file; | ||
| 32 | $files[0] =~ s/(\.z)$//i; | ||
| 33 | $files[0] =~ s/(\.gz)$//i; | ||
| 34 | my $uncompress = system("gunzip -c $file > $files[0]"); | ||
| 35 | die "ERROR: Could not extract data ($uncompress)\n" if $uncompress != 0; | ||
| 36 | |||
| 37 | } | ||
| 38 | else { | ||
| 39 | $files[0] = $file; | ||
| 40 | } | ||
| 41 | |||
| 42 | # PREPARATION OF THE PAGE LAYOUT PROCESSING | ||
| 43 | # CONFIGURATION (CGI GED TO BE REWORKED TO SIMPLIFY AND MAKE MORE EXPLICIT) | ||
| 44 | my $perl = $cfg->{'EDTK_BIN_PERL'} . '/perl'; | ||
| 45 | my $script = $cfg->{'EDTK_DIR_APP'} . "/$app.pl"; | ||
| 46 | my @options = (); | ||
| 47 | |||
| 48 | # my @options = ('cgi'); | ||
| 49 | # push (@options, 'cgiged'); | ||
| 50 | |||
| 51 | # WARNING: the document must also be configured in the parameter database | ||
| 52 | $ENV{'EDTK_OPTIONS'} = join( ',', @options ); | ||
| 53 | |||
| 54 | foreach my $filename (@files) { | ||
| 55 | |||
| 56 | # START THE PAGE LAYOUT PROCESSING WITH SENDING TO THE GED | ||
| 57 | warn "INFO: processing $filename\n"; | ||
| 58 | my $rv = system("$perl $script $filename $filename --edms > $app.perl.log 2>&1"); | ||
| 59 | die "ERROR: Could not extract data ($rv)\n" if $rv != 0; | ||
| 60 | unlink($filename); | ||
| 61 | } | ||
| 62 | warn "INFO: done, docs prepared for GED\n"; | ||
| 63 | |||
| 64 | # DELETE THE INTERMEDIATE PDFs FROM THE WORKING DIRECTORY | ||
| 65 | # unlink glob "*.pdf"; |