Ignore:
Timestamp:
2017-06-29T16:27:37+12:00 (7 years ago)
Author:
ak19
Message:

Moved function generate_item_file that's shared between PowerPointPlugin and the new UnknownConverterPlugin into their shared base class ConvertBinaryFile.pm. 2. In UnknownConverterPlugin, removed unnecessary plugin uption, made the file return 1 as all other Plugin/pm files do, and now some debug stmts are only printed when the verbosity is >2.

Location:
main/trunk/greenstone2/perllib/plugins
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugins/ConvertBinaryFile.pm

    r28381 r31761  
    496496
    497497}
     498
     499# This sub is shared across PowerPointPlugin and UnknownConverterPlugin,
     500# so it's been copied into here from the former.
     501sub generate_item_file {
     502    my $self = shift(@_);
     503    my ($input_filename) = @_;
     504    my $outhandle = $self->{'outhandle'};
     505    my ($tailname, $dirname, $suffix)
     506    = &File::Basename::fileparse($input_filename, "\\.[^\\.]+\$");
     507
     508    my $plugin_name = $self->{'plugin_type'}; # inherited from BaseImporter
     509
     510    # find all the files in the directory
     511    if (!opendir (DIR, $dirname)) {
     512    print $outhandle "$plugin_name: Couldn't read directory $dirname\n";
     513    return $input_filename;
     514    }
     515
     516    my @dir = readdir (DIR);
     517    closedir (DIR);
     518
     519    # start the item file
     520    my $itemfile_name = &util::filename_cat($dirname, "$tailname.item");
     521
     522    # encoding specification????
     523    if (!open (ITEMFILE, ">$itemfile_name")) {
     524    print $outhandle "$plugin_name: Couldn't open $itemfile_name for writing\n";
     525    }
     526    print ITEMFILE "<GeneratedBy>$plugin_name\n";
     527    # print the first page
     528    my @sorted_dir = sort alphanum_sort @dir;
     529    for (my $i = 0; $i < scalar(@sorted_dir); $i++) {
     530    my $file = $sorted_dir[$i];
     531    if ($file =~ /^img(\d+)\.jpg$/) {
     532        my $num = $1;
     533        $self->tidy_up_html(&util::filename_cat($dirname, "text$num.html"));
     534        print ITEMFILE "$num:img$num.jpg:text$num.html:\n";
     535    }
     536    }
     537    close ITEMFILE;
     538    return $itemfile_name;
     539
     540}
     541
    4985421;
    499543
  • main/trunk/greenstone2/perllib/plugins/PowerPointPlugin.pm

    r31742 r31761  
    398398}
    399399
    400 sub generate_item_file
    401 {
    402     my $self = shift(@_);
    403     my ($input_filename) = @_;
    404     my $outhandle = $self->{'outhandle'};
    405     my ($tailname, $dirname, $suffix)
    406     = &File::Basename::fileparse($input_filename, "\\.[^\\.]+\$");
    407 
    408     my $plugin_name = $self->{'plugin_type'};
    409 
    410     # find all the files in the directory
    411     if (!opendir (DIR, $dirname)) {
    412     print $outhandle "$plugin_name: Couldn't read directory $dirname\n";
    413     return $input_filename;
    414     }
    415 
    416     my @dir = readdir (DIR);
    417     closedir (DIR);
    418 
    419     # start the item file
    420     my $itemfile_name = &util::filename_cat($dirname, "$tailname.item");
    421 
    422     # encoding specification????
    423     if (!open (ITEMFILE, ">$itemfile_name")) {
    424     print $outhandle "$plugin_name: Couldn't open $itemfile_name for writing\n";
    425     }
    426     print ITEMFILE "<GeneratedBy>$plugin_name\n";
    427     # print the first page
    428     my @sorted_dir = sort alphanum_sort @dir;
    429     for (my $i = 0; $i < scalar(@sorted_dir); $i++) {
    430     my $file = $sorted_dir[$i];
    431     if ($file =~ /^img(\d+)\.jpg$/) {
    432         my $num = $1;
    433         $self->tidy_up_html(&util::filename_cat($dirname, "text$num.html"));
    434         print ITEMFILE "$num:img$num.jpg:text$num.html:\n";
    435     }
    436     }
    437     close ITEMFILE;
    438     return $itemfile_name;
    439 
    440    
    441 }
    442 
    443400# want to sort img1, img2, ...img10, img11 etc.
    444401sub alphanum_sort {
  • main/trunk/greenstone2/perllib/plugins/UnknownConverterPlugin.pm

    r31760 r31761  
    4545# At present, a file or folder of files is assumed.
    4646# Need to look in there for files with extension process_ext.
    47 # Support html_multi as output? Then a folder of html files is generated per document? OR Flag that indicates whether an html file + associated folder (such as of images) gets generated. And name of assoc folder. Such output gets generated for instance when a doc file is replaced by its html version.
     47# Do we also need a html_multi option to convert_to? Support html_multi as output?
     48# Then a folder of html files is generated per document?
     49# OR Flag that indicates whether an html file + associated folder (such as of images) gets generated. And name of assoc folder. Such output gets generated for instance when a doc file is replaced by its html version.
    4850
    4951sub BEGIN {
     
    7577    'reqd' => "yes",
    7678    'list' => $convert_to_list,
    77     'deft' => "text" },
    78       { 'name' => "output_file_or_dir_name",
    79     'desc' => "{UnknownConverterPlugin.output_file_or_dir_name}",
    80     'type' => "string",
    81     'reqd' => "no",
    82     'deft' => "" } ];
     79    'deft' => "text" } ];
    8380
    8481my $options = { 'name'     => "UnknownConverterPlugin",
     
    292289    } else {
    293290    $cmd =~ s@OUTPUT@\"$output_filename\"@g;
    294     }   
    295 
    296     print STDERR "@@@@ $plugin_name: executing conversion cmd \n|$cmd|\n";
    297     print STDERR "   on infile |$input_filename|\n";
    298     print STDERR "   to produce expected $output_filename\n";
     291    }
     292
     293    # Some debugging
     294    if ($self->{'verbosity'} > 2) {
     295    print STDERR "$plugin_name: executing conversion cmd \n|$cmd|\n";
     296    print STDERR "   on infile |$input_filename|\n";
     297    print STDERR "   to produce expected $output_filename\n";
     298    }
     299
     300    # Run the command at last
    299301    my $status = system($cmd);
    300302
     
    326328    # if multiple images were generated by running the conversion
    327329    if ($self->{'convert_to'} =~ /^pagedimg/) {
    328     my $item_filename = $self->generate_item_file($output_filename); #my $item_filename = $self->generate_item_file($output_file_or_dir);
     330    my $item_filename = $self->generate_item_file($output_filename);
    329331
    330332    if (!-e $item_filename) {
     
    338340    $self->{'output_filename'} = $output_filename;
    339341   
    340     return $output_filename; #$output_file_or_dir;
     342    return $output_filename;
    341343}
    342344
     
    463465}
    464466
    465 # do we also need a html_multi option to convert_to?
    466 # move the following, copied from PPT Plugin, into parent ConvertBinaryPlugin, as it's now shared
    467 sub generate_item_file {
    468     my $self = shift(@_);
    469     my ($input_filename) = @_;
    470     my $outhandle = $self->{'outhandle'};
    471     my ($tailname, $dirname, $suffix)
    472     = &File::Basename::fileparse($input_filename, "\\.[^\\.]+\$");
    473 
    474     my $plugin_name = $self->{'plugin_type'}; # inherited from BaseImporter
    475 
    476     # find all the files in the directory
    477     if (!opendir (DIR, $dirname)) {
    478     print $outhandle "$plugin_name: Couldn't read directory $dirname\n";
    479     return $input_filename;
    480     }
    481 
    482     my @dir = readdir (DIR);
    483     closedir (DIR);
    484 
    485     # start the item file
    486     my $itemfile_name = &util::filename_cat($dirname, "$tailname.item");
    487 
    488     # encoding specification????
    489     if (!open (ITEMFILE, ">$itemfile_name")) {
    490     print $outhandle "$plugin_name: Couldn't open $itemfile_name for writing\n";
    491     }
    492     print ITEMFILE "<GeneratedBy>$plugin_name\n";
    493     # print the first page
    494     my @sorted_dir = sort alphanum_sort @dir;
    495     for (my $i = 0; $i < scalar(@sorted_dir); $i++) {
    496     my $file = $sorted_dir[$i];
    497     if ($file =~ /^img(\d+)\.jpg$/) {
    498         my $num = $1;
    499         $self->tidy_up_html(&util::filename_cat($dirname, "text$num.html"));
    500         print ITEMFILE "$num:img$num.jpg:text$num.html:\n";
    501     }
    502     }
    503     close ITEMFILE;
    504     return $itemfile_name;
    505 
    506 }
     467
     4681;
Note: See TracChangeset for help on using the changeset viewer.