IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 13, 2008, 10:45:06 AM (18 years ago)
Author:
jhoblitt
Message:

add --timeout option
misc code cleanups

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/summit_copy.pl

    r16641 r17652  
    11#!/usr/bin/env perl
    22
    3 use Carp;
    43use warnings;
    54use strict;
    6 
    7 ## report the program and machine
    8 use Sys::Hostname;
    9 my $host = hostname();
    10 print "\n\n";
    11 print "Starting script $0 on $host\n\n";
    125
    136use vars qw( $VERSION );
     
    158
    169use IPC::Cmd 0.36 qw( can_run run );
     10use PS::IPP::Config 1.01 qw( :standard );
    1711use PS::IPP::Metadata::Config;
    1812use PS::IPP::Metadata::Stats;
    19 
    20 use PS::IPP::Config qw($PS_EXIT_SUCCESS
    21                        $PS_EXIT_UNKNOWN_ERROR
    22                        $PS_EXIT_SYS_ERROR
    23                        $PS_EXIT_CONFIG_ERROR
    24                        $PS_EXIT_PROG_ERROR
    25                        $PS_EXIT_DATA_ERROR
    26                        $PS_EXIT_TIMEOUT_ERROR
    27                        caturi
    28                        );
    29 my $ipprc = PS::IPP::Config->new(); # IPP configuration
     13use Sys::Hostname;
    3014
    3115use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    3216use Pod::Usage qw( pod2usage );
    3317
     18## report the program and machine
     19my $host = hostname();
     20print "\n\n";
     21print "Starting script $0 on $host\n\n";
     22
    3423# Parse the command-line arguments
    3524my ( $uri, $filename, $compress, $bytes, $md5, $nebulous, $exp_name, $inst, $telescope, $class, $class_id, $end_stage, $workdir,
    36      $dbname, $verbose, $no_update, $no_op );
     25     $dbname, $verbose, $no_update, $no_op, $timeout );
    3726GetOptions(
    38            'uri=s'         => \$uri,       # source location of file on data store
    39            'filename=s'    => \$filename,  # target location of file on local system
    40            'compress'      => \$compress,  # request file in compressed format
    41            'bytes=s'       => \$bytes,     # reported file size in bytes
    42            'md5=s'         => \$md5,       # reported md5 checksum
    43            'nebulous'      => \$nebulous,  # use nebulous for the target file
    44            'exp_name=s'    => \$exp_name,  # Exposure name
    45            'inst=s'        => \$inst,      # Instrument
    46            'telescope=s'   => \$telescope, # Telescope
    47            'class=s'       => \$class,     # Class level
    48            'class_id=s'    => \$class_id,  # Class identifier
    49            'end_stage=s'   => \$end_stage, # end of processing
    50            'workdir=s'     => \$workdir,   # workdir
    51            'dbname=s'      => \$dbname,    # Database name
    52            'verbose'       => \$verbose,   # Print to stdout
    53            'no-update'     => \$no_update, # Don't update the database?
    54            'no-op'         => \$no_op,     # Don't do any operations?
    55            ) or pod2usage( 2 );
     27       'uri=s'          => \$uri,       # source location of file on data store
     28       'filename=s'     => \$filename, # target location of file on local system
     29       'compress'       => \$compress,  # request file in compressed format
     30       'bytes=s'        => \$bytes,     # reported file size in bytes
     31       'md5=s'          => \$md5,       # reported md5 checksum
     32       'nebulous'       => \$nebulous,  # use nebulous for the target file
     33       'exp_name=s'     => \$exp_name,  # Exposure name
     34       'inst=s'         => \$inst,      # Instrument
     35       'telescope=s'    => \$telescope, # Telescope
     36       'class=s'        => \$class,     # Class level
     37       'class_id=s'     => \$class_id,  # Class identifier
     38       'end_stage=s'    => \$end_stage, # end of processing
     39       'workdir=s'      => \$workdir,   # workdir
     40       'dbname=s'       => \$dbname,    # Database name
     41       'verbose'        => \$verbose,   # Print to stdout
     42       'no-update'      => \$no_update, # Don't update the database?
     43       'no-op'          => \$no_op,     # Don't do any operations?
     44       'timeout|t'      => \$timeout,   # passed through to dsget
     45) or pod2usage( 2 );
    5646
    5747pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    5848pod2usage( -msg => "Required options: --uri --filename --exp_name --inst --telescope --class --class_id --workdir",
    59            -exitval => 3) unless
    60     defined $uri and
    61     defined $filename and
    62     defined $exp_name and
    63     defined $inst and
    64     defined $telescope and
    65     defined $class and
    66     defined $class_id and
    67     defined $workdir;
     49       -exitval => 3)
     50    unless defined $uri
     51    and defined $filename
     52    and defined $exp_name
     53    and defined $inst
     54    and defined $telescope
     55    and defined $class
     56    and defined $class_id
     57    and defined $workdir;
    6858
    6959# Look for programs we need
    7060my $missing_tools;
    71 my $dsget = can_run('dsget') or (warn "Can't find dsget" and $missing_tools = 1);
    72 my $pztool = can_run('pztool') or (warn "Can't find pztool" and $missing_tools = 1);
     61my $dsget = can_run('dsget')
     62    or (warn "Can't find dsget" and $missing_tools = 1);
     63my $pztool = can_run('pztool')
     64    or (warn "Can't find pztool" and $missing_tools = 1);
    7365if ($missing_tools) {
    7466    warn("Can't find required tools.");
     
    7668}
    7769
     70# dsget command
    7871my $command;
    79 
    80 # dsget command
    8172$command  = "$dsget --uri $uri --filename $filename";
    82 $command .= " --compress"     if defined $compress;
    83 $command .= " --bytes $bytes" if defined $bytes;
    84 $command .= " --nebulous"     if defined $nebulous;
    85 $command .= " --md5 $md5"     if defined $md5;
     73$command .= " --compress"           if defined $compress;
     74$command .= " --bytes $bytes"       if defined $bytes;
     75$command .= " --nebulous"           if defined $nebulous;
     76$command .= " --md5 $md5"           if defined $md5;
     77$command .= " --timeout $timeout"   if defined $timeout;
    8678
    8779# run command
    8880unless ($no_op) {
    89     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     81    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf )
     82        = run(command => $command, verbose => $verbose);
    9083    unless ($success) {
    91         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    92         &my_die("Unable to perform dsget: $error_code", $exp_name, $inst, $telescope, $class, $class_id, $uri, $error_code);
     84        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     85        my_die("Unable to perform dsget: $error_code",
     86            $exp_name,
     87            $inst,
     88            $telescope,
     89            $class,
     90            $class_id,
     91            $uri,
     92            $error_code
     93        );
    9394    }
    9495} else {
     
    110111# update the database
    111112unless ($no_update) {
    112     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     113    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf )
     114        = run(command => $command, verbose => $verbose);
    113115    unless ($success) {
    114         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    115         warn("Unable to perform $command: $error_code\n");
    116         exit($error_code);
     116        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     117        warn("Unable to perform $command: $error_code\n");
     118        exit($error_code);
    117119    }
    118120} else {
     
    131133    my $exit_code = shift; # Exit code to add
    132134
    133     carp($msg);
     135    warn $msg;
    134136    unless ($no_update) {
    135         # command to update database
    136         my $command;
    137         $command  = "$pztool -copydone";
    138         $command .= " -exp_name $exp_name";
    139         $command .= " -inst $inst";
    140         $command .= " -telescope $telescope";
    141         $command .= " -class $class";
    142         $command .= " -class_id $class_id";
    143         $command .= " -uri $uri";
    144         $command .= " -code $exit_code";
    145         $command .= " -dbname $dbname" if defined $dbname;
     137        # command to update database
     138        my $command;
     139        $command  = "$pztool -copydone";
     140        $command .= " -exp_name $exp_name";
     141        $command .= " -inst $inst";
     142        $command .= " -telescope $telescope";
     143        $command .= " -class $class";
     144        $command .= " -class_id $class_id";
     145        $command .= " -uri $uri";
     146        $command .= " -code $exit_code";
     147        $command .= " -dbname $dbname" if defined $dbname;
    146148
    147149        system ($command);
    148150    }
     151
    149152    exit $exit_code;
    150153}
    151154
    152 END {
    153     my $status = $?;
    154     system("sync") == 0
    155         or die "failed to execute sync: $!" ;
    156     $? = $status;
    157 }
     155# XXX: I don't think that we need this - JH
     156#END {
     157#    my $status = $?;
     158#    system("sync") == 0
     159#        or die "failed to execute sync: $!" ;
     160#    $? = $status;
     161#}
    158162
    159163__END__
Note: See TracChangeset for help on using the changeset viewer.