Ignore:
Timestamp:
2000-08-27T23:04:47+12:00 (24 years ago)
Author:
stefan
Message:

Lots of changes to perl building code for collectoraction

File:
1 edited

Legend:

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

    r1452 r1454  
    44# windows (build.bat is in bin\windows)
    55
     6package build;
     7
    68use FileHandle;
     9use File::Copy;
    710
    811BEGIN {
     
    2023use parsargv;
    2124use util;
    22 
    23 if (!parsargv::parse(\@ARGV,
    24              'append', \$append,
    25              'remove_archives', \$remove_archives,
    26              'remove_import', \$remove_import,
    27              'buildtype/^(build|import)$/import', \$buildtype,
    28              'maxdocs/^\-?\d+/-1', \$maxdocs,
    29              'download/.+', \@download,
    30              'out/.*/STDERR', \$out)) {
    31    
    32     &print_usage();
    33     die "\n";
    34 }
     25use cfgread;
     26
     27&parse_args (\@ARGV);
    3528
    3629my ($collection) = @ARGV;
     
    4235}
    4336
     37if ($optionfile =~ /\w/) {
     38    open (OPTIONS, $optionfile) || die "Couldn't open $optionfile\n";
     39    my $line = [];
     40    my $options = [];
     41    while (defined ($line = &cfgread::read_cfg_line ('build::OPTIONS'))) {
     42    push (@$options, @$line);
     43    }
     44    close OPTIONS;
     45    &parse_args ($options);
     46}
     47
    4448if ($maxdocs == -1) {
    4549    $maxdocs = "";
     
    4852}
    4953
    50 my $collectdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection);
    51 my $importdir = &util::filename_cat ($collectdir, "import");
    52 my $archivedir = &util::filename_cat ($collectdir, "archives");
    53 my $buildingdir = &util::filename_cat ($collectdir, "building");
    54 my $indexdir = &util::filename_cat ($collectdir, "index");
     54my $cdir = $collectdir;
     55$cdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect") unless $collectdir =~ /\w/;
     56my $importdir = &util::filename_cat ($cdir, $collection, "import");
     57my $archivedir = &util::filename_cat ($cdir, $collection, "archives");
     58my $buildingdir = &util::filename_cat ($cdir, $collection, "building");
     59my $indexdir = &util::filename_cat ($cdir, $collection, "index");
    5560my $bindir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin");
    5661
     
    6873$out->autoflush(1);
    6974
     75# delete any .kill file left laying around from a previously aborted build
     76if (-e &util::filename_cat ($cdir, $collection, ".kill")) {
     77    &util::rm (&util::filename_cat ($cdir, $collection, ".kill"));
     78}
     79
    7080&main();
    7181
     
    7585    print STDERR "\n  usage: $0 [options] collection-name\n\n";
    7686    print STDERR "  options:\n";
     87    print STDERR "   -optionfile file        Get options from file, useful on systems where\n";
     88    print STDERR "                           long command lines may cause problems\n";
    7789    print STDERR "   -append                 Add new files to existing collection\n";
    7890    print STDERR "   -remove_archives        Remove archives directory after successfully\n";
     
    90102    print STDERR "                           deleted to make way for the downloaded data if\n";
    91103    print STDERR "                           a -download option is supplied\n";
     104    print STDERR "   -collectdir directory   Collection directory (defaults to " .
     105    &util::filename_cat ($ENV{'GSDLHOME'}, "collect") . ")\n";
     106    print STDERR "   -dontinstall            Only applicable if -collectdir is set to something\n";
     107    print STDERR "                           other than the default. -dontinstall will suppress the\n";
     108    print STDERR "                           default behaviour which is to install the collection to\n";
     109    print STDERR "                           the gsdl/collect directory once it has been built.\n";
     110    print STDERR "   -save_archives          Create a copy of the existing archives directory called\n";
     111    print STDERR "                           archives.org\n";
    92112    print STDERR "   -out                    Filename or handle to print output status to.\n";
    93113    print STDERR "                           The default is STDERR\n\n";
     
    95115
    96116sub main {
    97    
     117
     118    if ($save_archives && -d $archivedir) {
     119    print $out "caching original archives to ${archivedir}.org\n";
     120    &util::cp_r ($archivedir, "${archivedir}.org");
     121    }
     122
    98123    # do the download thing if we have any -download options
    99124    if (scalar (@download)) {
     
    103128        &util::rm_r ($importdir);
    104129    }
    105 
     130   
    106131    foreach $download_dir (@download) {
    107132       
     
    120145            # copy download_dir and all it contains to the import directory
    121146            my $download_cmd = "perl " . &util::filename_cat ($bindir, "script", "filecopy.pl");
     147            $download_cmd .= " -collectdir \"$collectdir\"" if $collectdir =~ /\w/;
    122148            $download_cmd .= " -out \"$outfile.download\"" if $use_out;
    123149            $download_cmd .= " \"" . $download_dir . "\" " . $collection;
     
    165191    }
    166192    }
     193
     194    if ($collectdir ne "" && !$dontinstall) {
     195    my $install_collectdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect");
     196    if (!&util::filenames_equal ($collectdir, $install_collectdir)) {
     197       
     198        # install collection to gsdl/collect
     199        print $out "installing the $collection collection\n";
     200        my $newdir = &util::filename_cat ($install_collectdir, $collection);
     201        my $olddir = &util::filename_cat ($collectdir, $collection);
     202        if (-d $newdir) {
     203        print $out "build: Could not install collection as $newdir\n";
     204        print $out "       already exists. Collection will remain at\n";
     205        print $out "       $olddir\n";
     206        &final_out (4) if $use_out;
     207        die "\n";
     208        }
     209        if (!&File::Copy::move ($olddir, $newdir)) {
     210        print $out "build: Failed to install collection to $newdir\n";
     211        print $out "       Collection will remain at $olddir\n";
     212        &final_out (5) if $use_out;
     213        die "\n";
     214        }
     215    }
     216    }
     217
    167218    &final_out (0) if $use_out;
    168219}
     
    175226    $import_cmd .= " -out \"$outfile.import\"" if $use_out;
    176227    $import_cmd .= " -removeold" unless $append;
     228    $import_cmd .= " -collectdir \"$collectdir\"" if $collectdir =~ /\w/;
    177229    $import_cmd .= " $maxdocs $collection";
    178230    system ($import_cmd);
     
    188240    } else {
    189241    &final_out (2) if $use_out;
    190     die "\nimport.pl failed\n";
     242    print $out "\nimport.pl failed\n";
     243    die "\n";
    191244    }
    192245}
     
    198251    my $build_cmd = "perl " . &util::filename_cat ($bindir, "script", "buildcol.pl");
    199252    $build_cmd .= " -out \"$outfile.build\"" if $use_out;
     253    $build_cmd .= " -collectdir \"$collectdir\"" if $collectdir =~ /\w/;
    200254    $build_cmd .= " $maxdocs $collection";
    201255    system ($build_cmd);
     
    211265    }
    212266    } else {
    213     &final_out (2) if $use_out;
    214     die "\nbuildcol.pl failed\n";
     267    &final_out (3) if $use_out;
     268    print $out "\nbuildcol.pl failed\n";
     269    die "\n";
    215270    }
    216271
     
    221276    }
    222277    rmdir ($indexdir) if -d $indexdir;
    223     rename ($buildingdir, $indexdir);
     278    &File::Copy::move ($buildingdir, $indexdir);
     279
     280    # remove the cached arhives
     281    if ($save_archives) -d "${archivedir}.org") {
     282    &util::rm_r ("${archivedir}.org");
     283    }
    224284}
    225285
     
    263323    }
    264324}
     325
     326sub parse_args {
     327    my ($argref) = @_;
     328
     329    if (!parsargv::parse($argref,
     330             'optionfile/.*/', \$optionfile,
     331             'append', \$append,
     332             'remove_archives', \$remove_archives,
     333             'remove_import', \$remove_import,
     334             'buildtype/^(build|import)$/import', \$buildtype,
     335             'maxdocs/^\-?\d+/-1', \$maxdocs,
     336             'download/.+', \@download,
     337             'collectdir/.*/', \$collectdir,
     338             'dontinstall', \$dontinstall,
     339             'save_archives', \$save_archives,
     340             'out/.*/STDERR', \$out)) {
     341   
     342    &print_usage();
     343    die "\n";
     344    }
     345}
Note: See TracChangeset for help on using the changeset viewer.