IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36592


Ignore:
Timestamp:
Mar 18, 2014, 12:04:49 PM (12 years ago)
Author:
bills
Message:

make pstamp_insert_request.pl more robust at reporting errors from
illegal files by using replacing use of fields with fhead and parsing
the output. Print error messages to stdout so that the web form can
get them.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tags/ipp-20130712/pstamp/scripts/pstamp_insert_request.pl

    r35487 r36592  
    4545my $pstamptool = can_run('pstamptool')  or (warn "Can't find pstamptool"  and $missing_tools = 1);
    4646my $fields = can_run('fields')  or (warn "Can't find fields"  and $missing_tools = 1);
     47my $fhead = can_run('fhead')  or (warn "Can't find fhead"  and $missing_tools = 1);
    4748
    4849if ($missing_tools) {
     
    5657    # Note that if it's a pstamp request then REQ_NAME should be defined.
    5758    # if it's a detectability query it will not have a REQ_NAME but will have a QUERY_ID
    58     my $command = "echo $tmp_req_file | $fields -x 0 EXTNAME EXTVER REQ_NAME QUERY_ID";
     59    # my $command = "echo $tmp_req_file | $fields -x 0 EXTNAME EXTVER REQ_NAME QUERY_ID";
     60    my $command = "$fhead -x 0 $tmp_req_file";
    5961    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    6062        run(command => $command, verbose => $verbose);
    61 if (0) {
    62     # stoopid fields doesn't set exit status to zero when it works
    6363    unless ($success) {
    6464        print STDERR @$stderr_buf;
    6565        exit $error_code >> 8;
    6666    }
    67 }
    6867    my $output = join "", @$stdout_buf;
    69     (undef, $extname, $extver, $req_name) = split " ", $output;
     68
     69
     70    my $makehash = 0;
     71    my %hash;
     72    foreach my $line (split "\n", $output) {
     73        chomp $line;
     74        # split lines inte left and right using equals sign. left is the keyword
     75        my ($key, $right) = split "=", $line;
     76            # skip if there was no '='
     77        next if !$right;
     78
     79        $key =~ s/ //g;
     80
     81        # separate value from comment
     82        my ($value, $comment) = split "/", $right;
     83        # remove ' and space characters from key and value
     84        $value =~ s/'//g;
     85        $value =~ s/ //g;
     86
     87        #    print "$key $value\n";
     88
     89        # extract the values that we are looking for
     90        $extname  = $value if ($key eq "EXTNAME");
     91        $extver   = $value if ($key eq "EXTVER");
     92        $req_name = $value if ($key eq "REQ_NAME");
     93        $req_name = $value if ($key eq "QUERY_ID");
     94
     95        # optionally build hash. Duplicate keys get the last value seen
     96        if ($makehash) {
     97            $hash{$key} = $value;
     98        }
     99    }
     100
     101    # (undef, $extname, $extver, $req_name) = split " ", $output;
     102
    70103    if (!$extname or ! (($extname eq "PS1_PS_REQUEST") or ($extname eq "MOPS_DETECTABILITY_QUERY"))) {
    71104        print STDERR "invalid request file\n";
     105        print "invalid request file\n";
    72106        exit $PS_EXIT_DATA_ERROR;
    73107    }
     108
    74109    if (!defined $req_name) {
    75110        print STDERR "invalid request file no REQ_NAME or QUERY_ID\n";
     111        print "invalid request file no REQ_NAME or QUERY_ID\n";
     112        exit $PS_EXIT_DATA_ERROR;
     113    }
     114    if (!defined $extver) {
     115        print STDERR "invalid request file no EXTVER found\n";
     116        print "invalid request file no EXTVER found\n";
    76117        exit $PS_EXIT_DATA_ERROR;
    77118    }
     
    119160
    120161exit 0;
     162
    121163# Ask the database for the next web request number
    122164sub get_webreq_num
Note: See TracChangeset for help on using the changeset viewer.