Changeset 17652 for trunk/ippScripts/scripts/summit_copy.pl
- Timestamp:
- May 13, 2008, 10:45:06 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/summit_copy.pl (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/summit_copy.pl
r16641 r17652 1 1 #!/usr/bin/env perl 2 2 3 use Carp;4 3 use warnings; 5 4 use strict; 6 7 ## report the program and machine8 use Sys::Hostname;9 my $host = hostname();10 print "\n\n";11 print "Starting script $0 on $host\n\n";12 5 13 6 use vars qw( $VERSION ); … … 15 8 16 9 use IPC::Cmd 0.36 qw( can_run run ); 10 use PS::IPP::Config 1.01 qw( :standard ); 17 11 use PS::IPP::Metadata::Config; 18 12 use 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 13 use Sys::Hostname; 30 14 31 15 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); 32 16 use Pod::Usage qw( pod2usage ); 33 17 18 ## report the program and machine 19 my $host = hostname(); 20 print "\n\n"; 21 print "Starting script $0 on $host\n\n"; 22 34 23 # Parse the command-line arguments 35 24 my ( $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 ); 37 26 GetOptions( 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 ); 56 46 57 47 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 58 48 pod2usage( -msg => "Required options: --uri --filename --exp_name --inst --telescope --class --class_id --workdir", 59 -exitval => 3) unless 60 defined $uri and61 defined $filename and62 defined $exp_name and63 defined $inst and64 defined $telescope and65 defined $class and66 defined $class_id and67 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; 68 58 69 59 # Look for programs we need 70 60 my $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); 61 my $dsget = can_run('dsget') 62 or (warn "Can't find dsget" and $missing_tools = 1); 63 my $pztool = can_run('pztool') 64 or (warn "Can't find pztool" and $missing_tools = 1); 73 65 if ($missing_tools) { 74 66 warn("Can't find required tools."); … … 76 68 } 77 69 70 # dsget command 78 71 my $command; 79 80 # dsget command81 72 $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; 86 78 87 79 # run command 88 80 unless ($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); 90 83 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 ); 93 94 } 94 95 } else { … … 110 111 # update the database 111 112 unless ($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); 113 115 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); 117 119 } 118 120 } else { … … 131 133 my $exit_code = shift; # Exit code to add 132 134 133 carp($msg);135 warn $msg; 134 136 unless ($no_update) { 135 # command to update database136 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; 146 148 147 149 system ($command); 148 150 } 151 149 152 exit $exit_code; 150 153 } 151 154 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 #} 158 162 159 163 __END__
Note:
See TracChangeset
for help on using the changeset viewer.
