Changeset 1693


Ignore:
Timestamp:
2000-11-23T11:51:09+13:00 (23 years ago)
Author:
kjm18
Message:

updated to resemble the updated buildcol.pl

File:
1 edited

Legend:

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

    r1303 r1693  
    2626#
    2727###########################################################################
     28package mgppbuildcol;
    2829
    2930BEGIN {
     
    3233    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
    3334    unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
     35    unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
    3436}
    3537    #$ENV{'PATH'} = "$ENV{'GSDLHOME'}/src/mgpp/text:".$ENV{'PATH'};
     
    3840use parsargv;
    3941use util;
     42use FileHandle;
    4043
    4144&main();
     
    5659    print STDERR "                         building directory\n";
    5760    print STDERR "   -allclassifications   Don't remove empty classifications\n\n";
    58 }
     61    print STDERR "   -create_images        Attempt to create default images for new\n";
     62    print STDERR "                         collection. This relies on the Gimp being\n";
     63    print STDERR "                         installed along with relevant perl modules\n";
     64    print STDERR "                         to allow scripting from perl\n";
     65    print STDERR "   -collectdir directory Collection directory (defaults to " .
     66    &util::filename_cat ($ENV{'GSDLHOME'}, "collect") . ")\n";
     67    print STDERR "   -out                  Filename or handle to print output status to.\n";
     68    print STDERR "                         The default is STDERR\n\n";
     69}
     70
    5971
    6072
     
    6274{
    6375    my ($verbosity, $archivedir, $cachedir, $builddir, $maxdocs,
    64     $debug, $mode, $indexname, $keepold, $allclassifications);
     76    $debug, $mode, $indexname, $keepold, $allclassifications,
     77    $create_images, $collectdir, $out);
    6578    if (!parsargv::parse(\@ARGV,
    6679             'verbosity/\d+/2', \$verbosity,
     
    7386             'index/.*/', \$indexname,
    7487             'keepold', \$keepold,
    75              'allclassifications', \$allclassifications)) {
     88             'allclassifications', \$allclassifications,
     89             'create_images', \$create_images,
     90             'collectdir/.*/', \$collectdir,
     91             'out/.*/STDERR', \$out)) {
    7692    &print_usage();
    7793    die "\n";
    7894    }
     95
     96    my $close_out = 0;
     97    if ($out !~ /^(STDERR|STDOUT)$/i) {
     98    open (OUT, ">$out") || die "Couldn't open output file $out\n";
     99    $out = "buildcol::OUT";
     100    $close_out = 1;
     101    }
     102    $out->autoflush(1);
    79103
    80104    # get and check the collection
    81105    # this sets up GSDLCOLLECTION (eg demo) and GSDLCOLLECTDIR (eg
    82106    # GSDLHOME/collect/demo )
    83     if (($collection = &util::use_collection(@ARGV)) eq "") {
     107    if (($collection = &util::use_collection(@ARGV, $collectdir)) eq "") {
    84108    &print_usage();
    85109    die "\n";
     
    107131    }
    108132   
     133    # create default images if required
     134    if ($create_images) {
     135    my $collection_name = $collection;
     136    $collection_name = $collectcfg->{'collectionmeta'}->{'collectionname'}
     137    if defined $collectcfg->{'collectionmeta'}->{'collectionname'};
     138   
     139    &create_images ($collection_name);
     140    }
     141
    109142    # fill in the default archives and building directories if none
    110143    # were supplied, turn all \ into / and remove trailing /
     
    118151    # update the archive cache if needed
    119152    if ($cachedir) {
    120     print STDERR "Updating archive cache\n" if ($verbosity >= 1);
     153    print $out "Updating archive cache\n" if ($verbosity >= 1);
    121154
    122155    $cachedir =~ s/[\\\/]+$//;
     
    138171    &util::mk_all_dir ($realbuilddir);
    139172
    140 
    141     # if a builder class has been created for this collection, use it
     173   # if a builder class has been created for this collection, use it
    142174    # otherwise, use the mg builder
    143175    if (-e "$ENV{'GSDLCOLLECTDIR'}/perllib/${collection}builder.pm") {
     
    153185    eval("\$builder = new $buildertype(\$collection, " .
    154186     "\$realarchivedir, \$realbuilddir, \$verbosity, " .
    155      "\$maxdocs, \$debug, \$keepold, \$allclassifications)");
     187     "\$maxdocs, \$debug, \$keepold, \$allclassifications, \$out)");
    156188    die "$@" if $@;
    157189
     
    159191
    160192
    161     print STDERR "text index=$textindex, indexname= $indexname\n";
    162193    if ($mode =~ /^all$/i) {
    163194#   $builder->build_collection($textindex, $indexname);
     
    180211   
    181212    if (($realbuilddir ne $builddir) && !$debug) {
    182     print STDERR "Copying back the cached build\n" if ($verbosity >= 1);
     213    print $out "Copying back the cached build\n" if ($verbosity >= 1);
    183214    &util::rm_r ($builddir);
    184215    &util::cp_r ($realbuilddir, $builddir);
    185216    }
    186 }
    187 
    188 
     217
     218    close OUT if $close_out;
     219}
     220
     221
     222sub create_images {
     223    my ($collection_name) = @_;
     224
     225    my $image_script = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "script", "gimp", "title_icon.pl");
     226    if (!-e $image_script) {
     227    print $out "WARNING: Image making script ($image_script) could not be found\n";
     228    print $out "         Default images will not be generated\n\n";
     229    return;
     230    }
     231
     232    my $imagedir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "images");
     233
     234    &util::mk_all_dir ($imagedir);
     235
     236    # create the images
     237    system ("$image_script -size 1.5 -image_dir \"$imagedir\" -filename $collection.gif -text \"$collection_name\"");
     238    system ("$image_script -image_dir \"$imagedir\" -filename ${collection}sm.gif -text \"$collection_name\"");
     239
     240    # update the collect.cfg configuration file (this will need
     241    # to be changed when the config file format changes)
     242    if (!open (CFGFILE, $configfilename)) {
     243    print $out "WARNING: Couldn't open config file ($configfilename)\n";
     244    print $out "         for updating so collection images may not be linked correctly\n";
     245    return;
     246    }
     247
     248    my $line = ""; my $file = "";
     249    my $found = 0; my $foundsm = 0;
     250    while (defined ($line = <CFGFILE>)) {
     251    if ($line =~ /collectionmeta\s+iconcollection\s+/) {
     252        $line = "collectionmeta iconcollection _httpprefix_/collect/$collection/images/$collection.gif\n";
     253        $found = 1;
     254    } elsif ($line =~ /collectionmeta\s+iconcollectionsmall\s+/) {
     255        $line = "collectionmeta iconcollectionsmall _httpprefix_/collect/$collection/images/${collection}sm.gif\n";
     256        $foundsm = 1;
     257    }
     258    $file .= $line;
     259    }
     260    close CFGFILE;
     261
     262    $file .= "collectionmeta iconcollection _httpprefix_/collect/$collection/images/$collection.gif\n" if !$found;
     263    $file .= "collectionmeta iconcollectionsmall _httpprefix_/collect/$collection/images/${collection}sm.gif\n" if !$foundsm;
     264
     265    if (!open (CFGFILE, ">$configfilename")) {
     266    print $out "WARNING: Couldn't open config file ($configfilename)\n";
     267    print $out "         for updating so collection images may not be linked correctly\n";
     268    return;
     269    }
     270    print CFGFILE $file;
     271    close CFGFILE;
     272}
     273
Note: See TracChangeset for help on using the changeset viewer.