IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 15, 2009, 4:02:42 PM (17 years ago)
Author:
eugene
Message:

updates from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20090715/pstamp/scripts/pstamp_parser_run.pl

    r25022 r25406  
    1414use File::Basename qw( basename dirname);
    1515use POSIX qw( strftime );
     16use Carp;
     17use IPC::Cmd 0.36 qw( can_run run );
     18
     19use PS::IPP::Metadata::Config;
     20use PS::IPP::Metadata::Stats;
     21use PS::IPP::Metadata::List qw( parse_md_list );
     22
     23use PS::IPP::Config qw( :standard );
    1624
    1725my $req_id;
     
    3947}
    4048
    41 die "--req_id --uri --product are required"
     49my $missing_tools;
     50
     51my $pstamptool  = can_run('pstamptool')  or (warn "Can't find pstamptool"  and $missing_tools = 1);
     52my $pstampparse = can_run('pstampparse.pl') or (warn "Can't find pstampparse.pl" and $missing_tools = 1);
     53my $dqueryparse = can_run('dqueryparse.pl') or (warn "Can't find dqueryparse.pl" and $missing_tools = 1);
     54my $dsget = can_run('dsget') or (warn "Can't find dsget" and $missing_tools = 1);
     55
     56if ($missing_tools) {
     57    warn("Can't find required tools.");
     58    exit ($PS_EXIT_CONFIG_ERROR);
     59}
     60
     61
     62my_die("--req_id --uri --product are required", $req_id, $PS_EXIT_CONFIG_ERROR)
    4263    if !defined($req_id) or
    4364       !defined($uri) or
    4465       !defined($product);
    45 
    46 use IPC::Cmd 0.36 qw( can_run run );
    47 
    48 use PS::IPP::Metadata::Config;
    49 use PS::IPP::Metadata::Stats;
    50 use PS::IPP::Metadata::List qw( parse_md_list );
    51 
    52 use PS::IPP::Config qw($PS_EXIT_SUCCESS
    53                        $PS_EXIT_UNKNOWN_ERROR
    54                        $PS_EXIT_SYS_ERROR
    55                        $PS_EXIT_CONFIG_ERROR
    56                        $PS_EXIT_PROG_ERROR
    57                        $PS_EXIT_DATA_ERROR
    58                        $PS_EXIT_TIMEOUT_ERROR
    59                        metadataLookupStr
    60                        metadataLookupBool
    61                        caturi
    62                        );
    6366
    6467my $ipprc = PS::IPP::Config->new(); # IPP Configuration
     
    8083my $datedir = "$pstamp_workdir/$datestr";
    8184if (! -e $datedir ) {
    82     mkdir $datedir or die "failed to create working directory $datedir for request id $req_id";
     85    mkdir $datedir or my_die( "failed to create working directory $datedir for request id $req_id", $req_id,
     86        $PS_EXIT_CONFIG_ERROR);
    8387}
    8488
    8589my $workdir = "$datedir/$req_id";
    8690if (! -e $workdir ) {
    87     mkdir $workdir or die "failed to create working directory $workdir for request id $req_id";
     91    mkdir $workdir or my_die("failed to create working directory $workdir for request id $req_id", $req_id,
     92        $PS_EXIT_CONFIG_ERROR);
    8893}
    8994
     
    96101exit ($PS_EXIT_CONFIG_ERROR) unless defined $defaultDSProduct;
    97102   
    98 my $missing_tools;
    99 
    100 my $pstamptool  = can_run('pstamptool')  or (warn "Can't find pstamptool"  and $missing_tools = 1);
    101 my $pstampparse = can_run('pstampparse.pl') or (warn "Can't find pstampparse.pl" and $missing_tools = 1);
    102 my $dqueryparse = can_run('dqueryparse.pl') or (warn "Can't find dqueryparse.pl" and $missing_tools = 1);
    103 my $dsget = can_run('dsget') or (warn "Can't find dsget" and $missing_tools = 1);
    104 
    105 if ($missing_tools) {
    106     warn("Can't find required tools.");
    107     exit ($PS_EXIT_CONFIG_ERROR);
    108 }
    109 
    110103my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    111104
     
    119112        run(command => $command, verbose => $verbose);
    120113    unless ($success) {
    121         die("Unable to perform $command error code: $error_code");
     114        my_die("Unable to perform $command error code: $error_code", $req_id, $error_code >> 8);
    122115    }
    123116} elsif ($uri ne $new_uri) {
    124117    # put a link to the file into the workdir
    125118    if (-e $new_uri) {
    126         unlink $new_uri or die "failed to unlink $new_uri";
     119        unlink $new_uri or my_die("failed to unlink $new_uri", $req_id, $PS_EXIT_UNKNOWN_ERROR);
    127120    }
    128121    if (! symlink $uri, $new_uri) {
    129         die ("failed to link request file $uri to workdir $workdir");
     122        my_die ("failed to link request file $uri to workdir $workdir", $req_id, $PS_EXIT_UNKNOWN_ERROR);
    130123    }
    131124}
    132125$uri = $new_uri;
    133126
    134 die "request file $uri not found" if ! -e $uri;
     127my_die("request file $uri not found", $req_id, $PS_EXIT_UNKNOWN_ERROR) if ! -e $uri;
    135128
    136129#  if product was not defined (in database), use the default
     
    200193    unlink $error_file_name if (-e $error_file_name);
    201194
     195    # Run the parser
     196
    202197    my $command = "$parse_cmd";
    203198    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    261256    }
    262257}
     258
     259sub my_die {
     260    my $msg = shift;
     261    my $req_id = shift;
     262    my $fault = shift;
     263
     264    carp($msg);
     265
     266    my $command = "$pstamptool -updatereq -req_id $req_id  -fault $fault";
     267    $command   .= " -dbname $dbname" if $dbname;
     268    $command   .= " -dbserver $dbserver" if $dbserver;
     269    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     270        run(command => $command, verbose => $verbose);
     271    unless ($success) {
     272        die("Unable to perform $command error code: $error_code");
     273    }
     274    exit $fault;
     275}
Note: See TracChangeset for help on using the changeset viewer.