Changeset 4232


Ignore:
Timestamp:
2003-05-07T15:49:26+12:00 (21 years ago)
Author:
jrm21
Message:

now return codes when an error occurs, so that the receptionist can tell!

Location:
trunk/gsdl/bin/script
Files:
2 edited

Legend:

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

    r4125 r4232  
    3232
    3333BEGIN {
    34     die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
     34    if (!defined($ENV{'GSDLHOME'})) {
     35    print STDERR "GSDLHOME not set\n";
     36    return 1;
     37    }
    3538    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
    3639}
     
    4447{
    4548    my $gsdldir = "$ENV{'GSDLHOME'}";
    46 
    4749    # Read the languages available from etc/main.cfg
    4850    my $maincfg_fname = util::filename_cat($gsdldir, "etc", "main.cfg");
    49     open(MCFILE, "<$maincfg_fname") or die "Error: Could not open $maincfg_fname: $!\n";
     51    if (!open(MCFILE, "<$maincfg_fname")) {
     52    print STDERR "Error: Could not open $maincfg_fname: $!\n";
     53    return 2;
     54    }
    5055
    5156    my @languages;
     
    6368
    6469    # Write the HTML content of the page to tmp/lang/picklanguage.lang
    65     my $picklang_fname = util::filename_cat($gsdldir, "tmp", "lang", "picklanguage.lang");
     70    my $dir = util::filename_cat($gsdldir, "tmp", "lang");
     71    # creates directory if it doesn't already exist
     72    my $currentmask = umask;
     73    umask(0000);
     74    if (!-e $dir) {
     75    if (! mkdir($dir, 0777)) {
     76        print STDERR "Couldn't create directory $dir\n";
     77        return 3;
     78    }
     79    }
     80    my $picklang_fname = util::filename_cat($dir, "picklanguage.lang");
    6681
    6782    # Make the file world writeable
    68     my $currentmask = umask;
    69     umask(0000);
    7083    if (! open(HTMLFILE,">$picklang_fname")) {
    7184    umask($currentmask);
    72     die "Error: Could not create $picklang_fname: $!\n";
     85    print STDERR "Error: Could not create $picklang_fname: $!\n";
     86    return 4;
    7387    }
    7488    umask($currentmask);
     
    99113            "<center><img src=\"_httpimg_/divb.gif\"></center><p>");
    100114    close HTMLFILE;
     115    return 0;
    101116}
    102117
    103118
    104 &main();
     119exit &main();
  • trunk/gsdl/bin/script/translator.pl

    r4179 r4232  
    2929
    3030BEGIN {
    31     die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
     31    if (!defined $ENV{'GSDLHOME'}) {
     32    print STDERR "GSDLHOME not set\n";
     33    return 1;
     34    }
    3235    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
    3336}
     
    5558    # Check that both arguments were supplied
    5659    if (!$sourcelang) {
    57     die "Error: You didn't supply the name of the source language!\n";
     60    print STDERR "Error: You didn't supply the name of the source language!\n";
     61    return 2;
    5862    }
    5963    if (!$targetlang) {
    60     die "Error: You didn't supply the name of the target language!\n";
     64    print STDERR "Error: You didn't supply the name of the target language!\n";
     65    return 2;
    6166    }
    6267
     
    7378    if (! -e $translationdir) {
    7479    print STDERR "Error: Translation has not been initialised (exiting).\n";
    75     return;
     80    return 3;
    7681    }
    7782
     
    8489    # Make sure some macros exist to be translated
    8590    if (!$sourcehash1 && !$sourcehash2) {
    86     die "Error: No source macro information exists.\n";
     91    print STDERR "Error: No source macro information exists.\n";
     92    return 4;
    8793    }
    8894
     
    372378    # Write the number of pages to a file for use by the receptionist
    373379    my $numpagesfile = util::filename_cat($translationdir, "numpages.log");
    374     open NUMPAGESLOG, ">$numpagesfile" or die "Error: Could not write $numpagesfile.\n";
     380    if (!open NUMPAGESLOG, ">$numpagesfile") {
     381    print STDERR "Error: Could not write $numpagesfile.\n";
     382    return 5;
     383    }
    375384    print NUMPAGESLOG ($pageno - 1);
    376385    close NUMPAGESLOG;
     
    378387    # Write thankyou page for language translator once translation is complete
    379388    my $thankyoufile = util::filename_cat($translationdir, "thankyou.lang");
    380     open THANKYOU, ">$thankyoufile" or die "Error: Could not write $thankyoufile.\n";
     389    if (!open THANKYOU, ">$thankyoufile") {
     390    print STDERR "Error: Could not write $thankyoufile.\n";
     391    return 6;
     392    }
    381393    print THANKYOU ("<center> _textthanks_ $targetlang _texttrans_ ",
    382394            "<br> _textviewtranslation_ ",
     
    614626}
    615627
    616 
    617 &main(@ARGV);
     628exit &main(@ARGV);
Note: See TracChangeset for help on using the changeset viewer.