Changeset 6054


Ignore:
Timestamp:
2003-12-01T11:40:59+13:00 (20 years ago)
Author:
kjdon
Message:

put all the output strings into the dictionary

File:
1 edited

Legend:

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

    r5920 r6054  
    3333use util;
    3434use parsargv;
    35 
    36 sub print_usage {
    37     print STDERR "\n";
    38     print STDERR "exportcol.pl: Exports a collection for writing to CD-ROM.\n\n";
    39     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";
    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";
    44 }
     35use printusage;
     36
     37my $arguments =
     38    [ { 'name' => "out",
     39    'desc' => "{exportcol.out}",
     40    'type' => "string",
     41    'deft' => "STDERR",
     42    'reqd' => "no" },
     43      { 'name' => "cdname",
     44    'desc' => "{exportcol.cdname}",
     45    'type' => "string",
     46    'deft' => "Greenstone Collections",
     47    'reqd' => "no" }, ];
     48
     49my $options = { 'name' => "exportcol.pl",
     50        'desc' => "{exportcol.desc}",
     51        'args' => $arguments };
     52
     53sub print_xml_usage
     54{
     55    local $language = shift(@_);
     56
     57    &PrintUsage::print_xml_header();
     58
     59    print STDERR "<Info>\n";
     60    print STDERR "  <Name>$options->{'name'}</Name>\n";
     61    print STDERR "  <Desc>" . &lookup_string($options->{'desc'}) . "</Desc>\n";
     62    print STDERR "  <Arguments>\n";
     63    if (defined($options->{'args'})) {
     64    &PrintUsage::print_options_xml($language, $options->{'args'});
     65    }
     66    print STDERR "  </Arguments>\n";
     67    print STDERR "</Info>\n";
     68}
     69
     70sub print_txt_usage
     71{
     72    local $language = shift(@_);
     73
     74    local $programname = $options->{'name'};
     75    local $programargs = $options->{'args'};
     76
     77    # Find the length of the longest option string
     78    local $descoffset = 0;
     79    if (defined($programargs)) {
     80    $descoffset = &PrintUsage::find_longest_option_string($programargs);
     81    }
     82
     83    # Produce the usage information using the data structure above
     84    print STDERR " " . &lookup_string("{common.usage}") . ": $programname";
     85    print STDERR " " . &lookup_string("{exportcol.params}") . "\n\n";
     86
     87    # Display the program options, if there are some
     88    if (defined($programargs)) {
     89    # Calculate the column offset of the option descriptions
     90    local $optiondescoffset = $descoffset + 2;  # 2 spaces between options & descriptions
     91
     92    print STDERR " " . &lookup_string("{common.options}") . ":\n";
     93
     94    # Display the program options
     95    &PrintUsage::print_options_txt($language, $programargs, $optiondescoffset);
     96    }
     97}
     98
     99
     100sub lookup_string
     101{
     102    return &gsprintf::lookup_string($language, shift(@_));
     103}
     104
     105sub gsprintf
     106{
     107    return &gsprintf::gsprintf(@_);
     108}
     109
     110#sub print_usage {
     111#    print STDERR "\n";
     112#    print STDERR "exportcol.pl: Exports  collection for writing to CD-ROM.\n\n";
     113#    print STDERR "  usage: $0 [options] collection-name\n\n";
     114#    print STDERR "   -out    Filename or handle to print debug info to.\n";
     115#    print STDERR "           The default is STDERR\n";
     116#    print STDERR "   -cdname The name of the cd - this is what will appear in the start menu once the cd is installed.\n";
     117#    print STDERR "           The default is 'Greenstone Collections'.\n\n";
     118#}
    45119
    46120&main();
     
    48122sub main {
    49123    my ($out, $cdname);
     124
     125    my $xml = 0;
     126   
    50127    if (!parsargv::parse(\@ARGV,
    51128             'out/.*/STDERR', \$out,
    52              'cdname/.*/', \$cdname)) {
     129             'cdname/.*/', \$cdname,
     130             q^xml^, \$xml)) {
    53131   
    54     &print_usage();
    55     die "\n";
    56     }
     132    &print_txt_usage();
     133    die "\n";
     134    }
     135
     136    if ($xml) {
     137        &print_xml_usage($language);
     138    die "\n";
     139    }
     140   
    57141    my $dirname="";
    58142    if ($cdname eq "") {
     
    68152
    69153    if (not @coll_list) { # empty list
    70     &print_usage();
     154    &print_txt_usage();
    71155    exit(1);
    72156    }
     
    74158    my $close_out = 0;
    75159    if ($out !~ /^(STDERR|STDOUT)$/i) {
    76     open (OUT, ">$out") || die "Couldn't open output file $out\n";
     160    open (OUT, ">$out") ||
     161        die &lookup_string("{common.cannot_open_output_file}") . " $out\n";
    77162    $out = OUT;
    78163    $close_out = 1;
     
    84169    my $colldir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $c);
    85170    if (! -d $colldir) {
    86         print $out "Invalid collection $c, collection not found at $colldir, ignoring\n";
     171        &gsprintf($out, "{exportcol.coll_not_found}\n", $c, $colldir);
    87172        next;
    88173    }
     
    90175    my $coletcdir = &util::filename_cat ($colldir, "etc");
    91176    if ((!-d $colindexdir) || (!-d $coletcdir)) {
    92         print $out "Invalid collection $c, one of the following directories does not exist\n\n";
     177        &gsprintf($out, "{exportcol.coll_dirs_not_found}\n", $c);
    93178        print $out "  $colindexdir\n";
    94179        print $out "  $coletcdir\n";
     
    102187    if (not @valid_coll_list) {
    103188    # no valid colls left
    104     print $out "exportcol.pl failed: no valid collections specified to export\n";
     189    &gsprintf($out, "{exportcol.fail}");
     190    &gsprintf($out, "{exportcol.no_valid_colls}\n");
    105191    die "\n";
    106192    }
     
    110196    &util::mk_all_dir ($topdir);
    111197    if (!-d $topdir) {
    112     print $out "exportcol.pl failed: couldn't create directory $topdir\n";
     198    &gsprintf($out, "{exportcol.fail}");
     199    &gsprintf($out, "{exportcol.couldnt_create_dir}\n", $topdir);
    113200    die "\n";
    114201    }
     
    128215    my $installcfg = &util::filename_cat ($topdir, "install.cfg");
    129216    if (!open (INSTALLCFG, ">$installcfg")) {
    130     print $out "exportcol.pl failed: Could not create $installcfg\n";
     217    &gsprintf($out, "{exportcol.fail}");
     218    &gsprintf($out, "{exportcol.couldnt_create_file}\n", $installcfg );
    131219    die "\n";
    132220    }
     
    142230    my $manifestcfg = &util::filename_cat ($topdir, "manifest.cfg");
    143231    if (!open (MANIFESTCFG, ">$manifestcfg")) {
    144     print $out "exportcol.pl failed: Could not create $manifestcfg\n";
     232    &gsprintf($out, "{exportcol.fail}");
     233    &gsprintf($out, "{exportcol.couldnt_create_file}\n", $manifestcfg );
    145234    die "\n";
    146235    }
     
    162251    my $autoruninf = &util::filename_cat ($topdir, "Autorun.inf");
    163252    if (!open (AUTORUNINF, ">$autoruninf")) {
    164     print $out "exportcol.pl failed: Could not create $autoruninf\n";
     253    &gsprintf($out, "{exportcol.fail}");
     254    &gsprintf($out, "{exportcol.couldnt_create_file}\n", $autoruninf );
    165255    die "\n";
    166256    }
     
    187277    (!-e $serverexe) || (!-e $gssetupexe) || (!-e $setupexe) || (!-d $net32dir) ||
    188278    (!-d $net16dir) || (!-d $netscapedir) || (!-d $win32sdir) || (!-e $phindjar)) {
    189     print $out "exportcol.pl failed: One or more of the following necessary\n";
    190     print $out "files and directories does not exist\n\n";
     279    &gsprintf($out, "{exportcol.fail}");
     280    &gsprintf($out, "{exportcol.non_exist_files}\n");
    191281    print $out "  $imagesdir\n";
    192282    print $out "  $macrosdir\n";
     
    261351    &util::mv("$collectcfg.tmp", $collectcfg);
    262352    }
    263     print $out "exportcol.pl succeeded: The exported collections are in $topdir\n";
     353    &gsprintf($out, "{exportcol.success}");
     354    &gsprintf($out, "{exportcol.output_dir}\n", $topdir);
    264355    close OUT if $close_out;
    265356}
Note: See TracChangeset for help on using the changeset viewer.