Changeset 433


Ignore:
Timestamp:
1999-08-04T17:23:41+12:00 (25 years ago)
Author:
sjboddie
Message:

added gzip option to import.pl

Location:
trunk/gsdl
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/bin/script/import.pl

    r314 r433  
    2727    print STDERR "   -removeold             Will remove the old contents of the archives\n";
    2828    print STDERR "                          directory -- use with care\n";
     29    print STDERR "   -gzip                  Use gzip to compress resulting gml documents\n";
    2930    print STDERR "   -maxdocs number        Maximum number of documents to import\n\n";
    3031}
     
    4041             'keepold', \$keepold,
    4142             'removeold', \$removeold,
     43             'gzip', \$gzip,
    4244             'maxdocs/\d+/', \$maxdocs)) {
    4345    &print_usage();
     
    110112
    111113    # create a docsave object to process the documents
    112     $processor = new docsave ($collection, $archive_info, $verbosity);
     114    $processor = new docsave ($collection, $archive_info, $verbosity, $gzip);
    113115    $processor->setarchivedir ($archivedir);
    114116
  • trunk/gsdl/perllib/docsave.pm

    r170 r433  
    1515
    1616sub new {
    17     my ($class, $collection, $archive_info, $verbosity) = @_;
     17    my ($class, $collection, $archive_info, $verbosity, $gzip) = @_;
    1818    my $self = new docproc ();
    1919
     
    2121    $self->{'archive_info'} = $archive_info;
    2222    $self->{'verbosity'} = $verbosity;
     23    $self->{'gzip'} = $gzip;
    2324
    2425    # set a default for the archive directory
     
    5051    # same one.
    5152    $doc_dir = $doc_info->[0];
    52     $doc_dir =~ s/\/?doc\.gml$//;
     53    $doc_dir =~ s/\/?doc\.gml(\.gz)?$//;
    5354
    5455    } else {
     
    6364        }
    6465    } while ($doc_dir_rest ne "" &&
    65          (-d "$archive_dir/$doc_dir.dir" ||
     66         ((-d &util::filename_cat ($archive_dir, "$doc_dir.dir")) ||
    6667          ($self->{'archive_info'}->size() >= 1024 && $doc_dir_num < 2)));
    6768    $doc_dir .= ".dir";
     
    7576    foreach $assoc_file (@{$doc_obj->get_assoc_files()}) {
    7677    if (-e $assoc_file->[0]) {
    77         &util::cp ($assoc_file->[0], "$archive_dir/$doc_dir/$assoc_file->[1]");
     78        my $afile = &util::filename_cat($archive_dir, $doc_dir, $assoc_file->[1]);
     79        &util::cp ($assoc_file->[0], $afile);
    7880        $doc_obj->add_metadata ($doc_obj->get_top_section(),
    7981                    "gsdlassocfile",
     
    8183    } else {
    8284        print STDERR "docsave::process couldn't copy the associated file " .
    83         "$assoc_file->[0] to $archive_dir/$doc_dir/$assoc_file->[1]\n"
     85        "$assoc_file->[0] to $afile\n";
    8486    }
    8587    }
    8688
    8789    # save this document
    88     if (!open (OUTDOC, ">$archive_dir/$doc_dir/doc.gml")) {
    89     print STDERR "docsave::process could not write to file " .
    90         "$archive_dir/$doc_dir/doc.gml\n";
     90    my $doc_file = &util::filename_cat ($archive_dir, $doc_dir, "doc.gml");
     91    my $short_doc_file = &util::filename_cat ($doc_dir, "doc.gml");
     92
     93    if (!open (OUTDOC, ">$doc_file")) {
     94    print STDERR "docsave::process could not write to file $docfile\n";
    9195    return;
    9296    }
     
    9498    close OUTDOC;
    9599
     100    if ($self->{'gzip'}) {
     101    `gzip $doc_file`;
     102    $doc_file .= ".gz";
     103    $short_doc_file .= ".gz";
     104    if (!-e $doc_file) {
     105        print STDERR "error while gzipping: $doc_file doesn't exist\n";
     106        return;
     107    }
     108    }
     109
    96110    # store reference in the archive_info
    97     $self->{'archive_info'}->add_info($OID,
    98                       "$doc_dir/doc.gml");
     111    $self->{'archive_info'}->add_info($OID, $short_doc_file);
    99112   
    100113}
  • trunk/gsdl/perllib/plugins/GMLPlug.pm

    r317 r433  
    4747
    4848    # see if this is a gml book
    49     return undef unless (-f $fullname && $fullname =~ /\.gml$/i);
     49    return undef unless (-f $fullname && $fullname =~ /\.gml(\.gz)?$/i);
    5050
    51     my ($parent_dir) = $fullname =~ /^(.*)\/[^\/]+.gml$/;
     51    my ($parent_dir, $gz) = $fullname =~ /^(.*)\/[^\/]+.gml(\.gz)?$/i;
     52
     53    if (defined $gz && $gz =~ /\.gz/i) {
     54    $gz = 1;
     55    } else {
     56    $gz = 0;
     57    }
    5258
    5359    # create a new document
     
    6066    my $gml = "";
    6167    my $line = "";
    62     if (!open (INFILE, $fullname)) {
    63     print STDERR "GMLPlug::read - couldn't read $fullname\n";
    64     return undef;
     68
     69    if ($gz) {
     70    if (!open (INFILE, "zcat $fullname |")) {
     71        print STDERR "GMLPlug::read - zcat couldn't read $fullname\n";
     72        return undef;
     73    }
     74    } else {
     75    if (!open (INFILE, $fullname)) {
     76        print STDERR "GMLPlug::read - couldn't read $fullname\n";
     77        return undef;
     78    }
    6579    }
     80
    6681    while (defined ($line = <INFILE>)) {
    6782    $gml .= $line;
Note: See TracChangeset for help on using the changeset viewer.