Changeset 5920


Ignore:
Timestamp:
2003-11-20T13:52:30+13:00 (20 years ago)
Author:
kjdon
Message:

modified this so you can export mulitple collections, and supply a name from teh resulting cd

File:
1 edited

Legend:

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

    r5849 r5920  
    3838    print STDERR "exportcol.pl: Exports a collection for writing to CD-ROM.\n\n";
    3939    print STDERR "  usage: $0 [options] collection-name\n\n";
    40     print STDERR "   -out   Filename or handle to print debug info to.\n";
    41     print STDERR "          The default is STDERR\n\n";
     40    print STDERR "   -out    Filename or handle to print debug info to.\n";
     41    print STDERR "           The default is STDERR\n";
     42    print STDERR "   -cdname The name of the cd - this is what will appear in the start menu once the cd is installed.\n";
     43    print STDERR "           The default is 'Greenstone Collections'.\n\n";
    4244}
    4345
     
    4547
    4648sub main {
    47     my ($out, $collection);
    48     if (!parsargv::parse(\@ARGV, 'out/.*/STDERR', \$out)) {
     49    my ($out, $cdname);
     50    if (!parsargv::parse(\@ARGV,
     51             'out/.*/STDERR', \$out,
     52             'cdname/.*/', \$cdname)) {
     53   
    4954    &print_usage();
    5055    die "\n";
    5156    }
    52 
    53     # get and check the collection name
    54     if (($collection = &util::use_collection(@ARGV)) eq "") {
     57    my $dirname="";
     58    if ($cdname eq "") {
     59    $cdname = "Greenstone Collections";
     60    $dirname = "exported_collections";
     61    } else {
     62    $dirname = $cdname;
     63    $dirname =~ s/\s//g;
     64    $dirname = "exported_".$dirname;
     65    }
     66
     67    my @coll_list = @ARGV;
     68
     69    if (not @coll_list) { # empty list
    5570    &print_usage();
    56     exit (1);
    57     }
    58 
     71    exit(1);
     72    }
     73   
    5974    my $close_out = 0;
    6075    if ($out !~ /^(STDERR|STDOUT)$/i) {
     
    6479    }
    6580
    66     # make sure the collection is built (or at least contains all the
    67     # directories we expect it to) - we expect that it should contain an
    68     # index and an etc directory and will also copy across an images
    69     # directory if it exists
    70     my $colindexdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection, "index");
    71     my $colimagesdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection, "images");
    72     my $coletcdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection, "etc");
    73     if ((!-d $colindexdir) || (!-d $coletcdir)) {
    74     print $out "exportcol.pl failed: One or more of the following necessary\n";
    75     print $out "directories does not exist\n\n";
    76     print $out "  $colindexdir\n";
    77     print $out "  $coletcdir\n";
     81    # check each collection
     82    my @valid_coll_list = ();
     83    foreach $c (@coll_list) {
     84    my $colldir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $c);
     85    if (! -d $colldir) {
     86        print $out "Invalid collection $c, collection not found at $colldir, ignoring\n";
     87        next;
     88    }
     89    my $colindexdir = &util::filename_cat ($colldir, "index");
     90    my $coletcdir = &util::filename_cat ($colldir, "etc");
     91    if ((!-d $colindexdir) || (!-d $coletcdir)) {
     92        print $out "Invalid collection $c, one of the following directories does not exist\n\n";
     93        print $out "  $colindexdir\n";
     94        print $out "  $coletcdir\n";
     95        next;
     96    }
     97    # the collection seems ok, we add it to the valid coll list
     98    push @valid_coll_list, $c;
     99   
     100    }
     101
     102    if (not @valid_coll_list) {
     103    # no valid colls left
     104    print $out "exportcol.pl failed: no valid collections specified to export\n";
    78105    die "\n";
    79106    }
    80107
    81108    # create exported directory
    82     my $topdir = &util::filename_cat ($ENV{'GSDLHOME'}, "tmp", "exported_$collection");
     109    my $topdir = &util::filename_cat ($ENV{'GSDLHOME'}, "tmp", $dirname);
    83110    &util::mk_all_dir ($topdir);
    84111    if (!-d $topdir) {
     
    105132    }
    106133    print INSTALLCFG "CompanyName:New Zealand Digital Library\n";
    107     print INSTALLCFG "CollectionName:$collection\n";
    108     print INSTALLCFG "CollectionDirName:$collection\n";
     134    print INSTALLCFG "CollectionName:$cdname\n";
     135    print INSTALLCFG "CollectionDirName:$cdname\n";
    109136    print INSTALLCFG "CollectionVersion:1.0\n";
    110137    print INSTALLCFG "CollectionVolume:1\n";
     
    123150    print MANIFESTCFG "  net32 net16 server.exe\n\n";
    124151    print MANIFESTCFG "database:\n";
    125     print MANIFESTCFG '  etc collect\$(COLDIRNAME)\index\text\$(COLDIRNAME).ldb' . "\n\n";
     152    print MANIFESTCFG '  etc ';
     153    foreach $c (@valid_coll_list) {
     154    print MANIFESTCFG "collect\\$c\\index\\text\\$c.ldb ";
     155    }
     156    print MANIFESTCFG "\n\n";
    126157    print MANIFESTCFG "collection:\n";
    127158    print MANIFESTCFG "  collect etc images macros mappings bin\n";
     
    195226    }
    196227
    197     # copy the collection itself
    198     my $thiscoldir = &util::filename_cat ($collectdir, $collection);
    199     &util::mk_all_dir ($thiscoldir);
    200     &util::cp_r ($colindexdir, $thiscoldir);
    201     &util::cp_r ($coletcdir, $thiscoldir);
    202     &util::cp_r ($colimagesdir, $thiscoldir) if (-e $colimagesdir);
    203 
    204     # now we need to check the collect.cfg file to make sure its public
    205     my $collectcfg = &util::filename_cat ($thiscoldir, "etc", "collect.cfg");
    206     open INFILE, "<$collectcfg";
    207     open OUTFILE, ">$collectcfg.tmp";
    208     while ($line = <INFILE>) {
    209     if ($line =~ /^\s*public\s+false/) {
    210         print OUTFILE "public\ttrue\n";
    211         last; # stop matching once we have found the line
    212     } else {
     228    # copy the collections over
     229    foreach $c (@valid_coll_list) {
     230    #old directories
     231    my $colldir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $c);
     232    my $colindexdir = &util::filename_cat ($colldir, "index");
     233    my $coletcdir = &util::filename_cat ($colldir, "etc");
     234    my $colimagesdir = &util::filename_cat ($colldir, "images");
     235    # new coll directory
     236    my $newcoldir = &util::filename_cat ($collectdir, $c);
     237
     238    &util::mk_all_dir ($newcoldir);
     239    &util::cp_r ($colindexdir, $newcoldir);
     240    &util::cp_r ($coletcdir, $newcoldir);
     241    &util::cp_r ($colimagesdir, $newcoldir) if (-e $colimagesdir);
     242
     243    # now we need to check the collect.cfg file to make sure its public
     244    my $collectcfg = &util::filename_cat ($newcoldir, "etc", "collect.cfg");
     245    open INFILE, "<$collectcfg";
     246    open OUTFILE, ">$collectcfg.tmp";
     247    while ($line = <INFILE>) {
     248        if ($line =~ /^\s*public\s+false/) {
     249        print OUTFILE "public\ttrue\n";
     250        last; # stop matching once we have found the line
     251        } else {
     252        print OUTFILE "$line";
     253        }
     254    }
     255    # continue with no checking
     256    while ($line = <INFILE>) {
    213257        print OUTFILE "$line";
    214258    }
    215     }
    216     # continue with no checking
    217     while ($line = <INFILE>) {
    218     print OUTFILE "$line";
    219     }
    220     close INFILE;
    221     close OUTFILE;
    222     &util::mv("$collectcfg.tmp", $collectcfg);
    223 
    224     print $out "exportcol.pl succeeded: The exported collection is in $topdir\n";
     259    close INFILE;
     260    close OUTFILE;
     261    &util::mv("$collectcfg.tmp", $collectcfg);
     262    }
     263    print $out "exportcol.pl succeeded: The exported collections are in $topdir\n";
    225264    close OUT if $close_out;
    226265}
Note: See TracChangeset for help on using the changeset viewer.