IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 7, 2009, 11:21:24 AM (17 years ago)
Author:
bills
Message:

post errors in db pass list of files in fileset to receivetool in a mdc file

File:
1 edited

Legend:

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

    r23894 r24103  
    2121use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    2222use Pod::Usage qw( pod2usage );
     23use File::Temp qw( tempfile );
    2324
    2425# Look for programs we need
     
    3233
    3334# Parse the command-line arguments
    34 my ( $fileset_id, $source, $product, $fileset, $dbname, $verbose, $no_update );
     35my ( $fileset_id, $source, $product, $fileset, $dbname, $verbose, $no_update, $save_temps );
    3536
    3637GetOptions(
     
    4243           'verbose'           => \$verbose,   # Print to stdout
    4344           'no-update'         => \$no_update, # Don't update the database?
     45           'save-temps'        => \$save_temps, # keep temp files
    4446    ) or pod2usage( 2 );
    4547
     
    5254    defined $fileset;
    5355
    54 # Get list of files
    55 my @files = ();                 # Files to add
     56# Get list of files, sanity check and then write it to a temporary file
     57my $numFiles = 0;
     58my ($listFile, $listName) = tempfile("/tmp/$product.$fileset.list.XXXX", UNLINK => !$save_temps);
    5659{
    5760    my $uri = "$source/$product/$fileset"; # URI for datastore fileset
     
    6164    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    6265        run(command => $command, verbose => $verbose);
    63     die "Unable to get fileset listing from $uri\n" unless $success;
     66    &my_die( "Unable to get fileset listing from $uri\n", $fileset_id, $error_code) unless $success;
    6467
    6568    # Get files
     
    6972        next unless $line =~ /\S+/;
    7073        my @fields = split(/\s+/, $line); # Fields in line
    71         my $file = $fields[1];      # Name of file
    72         push @files, $file if defined $file;
     74        &my_die( "too few columns in fileset list entry: $line\n", $fileset_id, $PS_EXIT_DATA_ERROR) unless scalar @fields >= 6;
     75
     76        print $listFile "FILE$numFiles\tMETADATA\n";
     77
     78        print $listFile "\turi\t\tSTR\t" . $fields[0] .  "\n";
     79        print $listFile "\tfile\t\tSTR\t" . $fields[1] .  "\n";
     80        print $listFile "\tbytes\t\tS64\t" . $fields[2] .  "\n";
     81        print $listFile "\tmd5sum\t\tSTR\t" . $fields[3] .  "\n";
     82        print $listFile "\tfile_type\tSTR\t" . $fields[4] .  "\n";
     83        print $listFile "\tcomponent\tSTR\t" . $fields[5] .  "\n";
     84
     85        print $listFile "END\n";
     86        $numFiles++;
    7387    }
     88    close $listFile;
    7489}
    7590
    7691# Add files
    77 if (scalar @files > 0) {
     92my $new_state;
     93if ($numFiles > 0) {
     94    $new_state = "new";
    7895    my $command = "receivetool -addfile"; # Command to execute
    7996    $command .= " -fileset_id $fileset_id";
    80     $command .= " -file " . join(' -file ', @files);
     97    $command .= " -file_list $listName";
    8198    $command .= " -dbname $dbname" if defined $dbname;
    8299
     
    84101        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    85102            run(command => $command, verbose => $verbose);
    86         die "Unable to add file for fileset $fileset\n" unless $success;
     103        &my_die( "Unable to add file list for fileset $fileset\n", $fileset_id, $error_code) unless $success;
     104    }
     105} else {
     106    print STDERR "fileset $fileset has no files\n" if $verbose;
     107    $new_state = "full";
     108}
     109
     110{
     111    my $command = "receivetool -updatefileset"; # Command to execute
     112    $command .= " -fileset_id $fileset_id";
     113    $command .= " -set_state $new_state";
     114    $command .= " -dbname $dbname" if defined $dbname;
     115
     116    unless (defined $no_update) {
     117        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     118            run(command => $command, verbose => $verbose);
     119        &my_die( "Unable to set state to $new_state for fileset $fileset\n", $fileset_id, $error_code) unless $success;
    87120    }
    88121}
    89122
     123sub my_die {
     124    my $msg = shift;            # Exit message
     125    my $fileset_id = shift;     # File identifier
     126    my $fault = shift;          # Fault code
     127
     128    $fault = $PS_EXIT_PROG_ERROR unless defined $fault;
     129
     130    carp($msg);
     131    if (not $no_update) {
     132        my $command = "$receivetool -updatefileset";
     133        $command .= " -fileset_id $fileset_id";
     134        $command .= " -fault $fault";
     135        $command .= " -dbname $dbname" if defined $dbname;
     136
     137        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     138            run(command => $command, verbose => $verbose);
     139        die "Unable to set fault to $fault for fileset $fileset\n" unless $success;
     140    }
     141    exit $fault;
     142}
    90143__END__
Note: See TracChangeset for help on using the changeset viewer.