Ignore:
Timestamp:
2000-08-20T20:42:28+12:00 (24 years ago)
Author:
sjboddie
Message:

Made a few minor adjustments to perl building code for use with
collectoraction

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/bin/script/build

    r1424 r1431  
    1818
    1919if (!parsargv::parse(\@ARGV,
     20             'append', \$append,
    2021             'remove_archives', \$remove_archives,
    2122             'remove_import', \$remove_import,
     
    5051my $bindir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin");
    5152
    52 my $close_out = 0;
     53my $use_out = 0;
    5354my $outfile = $out;
    5455if ($out !~ /^(STDERR|STDOUT)$/i) {
    5556    open (OUT, ">$out") || die "Couldn't open output file $out\n";
    5657    $out = "OUT";
    57     $close_out = 1;
     58    $use_out = 1;
    5859}
    5960$out->autoflush(1);
     
    6162&main();
    6263
    63 close OUT if $close_out;
     64close OUT if $use_out;
    6465
    6566sub print_usage {
    6667    print STDERR "\n  usage: $0 [options] collection-name\n\n";
    6768    print STDERR "  options:\n";
     69    print STDERR "   -append                 Add new files to existing collection\n";
    6870    print STDERR "   -remove_archives        Remove archives directory after successfully\n";
    6971    print STDERR "                           building the collection.\n";
     
    8991    if (scalar (@download)) {
    9092    # remove any existing import data
    91     &util::rm_r ($importdir) if -d $importdir;
     93    if (&has_content ($importdir)) {
     94        print $out "build: WARNING: removing contents of $importdir\n";
     95        &util::rm_r ($importdir);
     96    }
    9297
    9398    foreach $download_dir (@download) {
     
    107112            # copy download_dir and all it contains to the import directory
    108113            my $download_cmd = "perl " . &util::filename_cat ($bindir, "script", "filecopy.pl");
    109             $download_cmd .= " -out \"$outfile\" \"" . $download_dir . "\" " . $collection;
     114            $download_cmd .= " -out \"$outfile.download\"" if $use_out;
     115            $download_cmd .= " \"" . $download_dir . "\" " . $collection;
    110116            system ($download_cmd);
     117            # if using output directory append the file download output to it
     118            &append_file ($out, "$outfile.download");
    111119        } else {
    112120            print $out "WARNING: $download_dir does not exist\n";
     
    154162    print $out "importing the $collection collection\n\n";
    155163
    156     my $import = &util::filename_cat ($bindir, "script", "import.pl");
    157     system ("perl $import -removeold $maxdocs -out \"$outfile\" $collection");
     164    my $import_cmd = "perl " . &util::filename_cat ($bindir, "script", "import.pl");
     165    $import_cmd .= " -out \"$outfile.import\"" if $use_out;
     166    $import_cmd .= " -removeold" unless $append;
     167    $import_cmd .= " $maxdocs $collection";
     168    system ($import_cmd);
     169    # if using output directory append the import output to it
     170    &append_file ($out, "$outfile.import");
     171
    158172    if (-e &util::filename_cat ($archivedir, "archives.inf")) {
    159173    print $out "$collection collection imported successfully\n\n";
     
    171185    print $out "building the $collection collection\n\n";
    172186
    173     my $buildcol = &util::filename_cat ($bindir, "script", "buildcol.pl");
    174     system ("perl $buildcol $maxdocs -out \"$outfile\" $collection");
     187    my $build_cmd = "perl " . &util::filename_cat ($bindir, "script", "buildcol.pl");
     188    $build_cmd .= " -out \"$outfile.build\"" if $use_out;
     189    $build_cmd .= " $maxdocs $collection";
     190    system ($build_cmd);
     191    # if using output directory append the buildcol output to it
     192    &append_file ($out, "$outfile.build");
     193
    175194    if (-e &util::filename_cat ($buildingdir, "text", "$collection.ldb") ||
    176195    -e &util::filename_cat ($buildingdir, "text", "$collection.bdb")) {
     
    209228    return 0;
    210229}
     230
     231sub append_file {
     232    my ($handle, $file) = @_;
     233
     234    open (FILE, $file) || return;
     235    undef $/;
     236    print $handle <FILE>;
     237    $/ = "\n";
     238    close FILE;
     239    &util::rm ($file);
     240}
Note: See TracChangeset for help on using the changeset viewer.