IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 7, 2009, 4:08:25 PM (17 years ago)
Author:
Paul Price
Message:

Merging trunk (r25026) to get up-to-date on old branch.

Location:
branches/pap
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/ippScripts/scripts/receive_fileset.pl

    r23894 r25027  
    2121use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    2222use Pod::Usage qw( pod2usage );
     23use File::Temp qw( tempfile );
     24use Carp;
    2325
    2426# Look for programs we need
     
    3234
    3335# Parse the command-line arguments
    34 my ( $fileset_id, $source, $product, $fileset, $dbname, $verbose, $no_update );
     36my ( $fileset_id, $source, $product, $fileset, $dbname, $verbose, $no_update, $save_temps );
    3537
    3638GetOptions(
     
    4244           'verbose'           => \$verbose,   # Print to stdout
    4345           'no-update'         => \$no_update, # Don't update the database?
     46           'save-temps'        => \$save_temps, # keep temp files
    4447    ) or pod2usage( 2 );
    4548
     
    5255    defined $fileset;
    5356
    54 # Get list of files
    55 my @files = ();                 # Files to add
     57# Get list of files, sanity check and then write it to a temporary file
     58my $numFiles = 0;
     59my ($listFile, $listName) = tempfile("/tmp/$product.$fileset.list.XXXX", UNLINK => !$save_temps);
    5660{
    5761    my $uri = "$source/$product/$fileset"; # URI for datastore fileset
     
    6165    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    6266        run(command => $command, verbose => $verbose);
    63     die "Unable to get fileset listing from $uri\n" unless $success;
     67    &my_die( "Unable to get fileset listing from $uri\n", $fileset_id, $error_code) unless $success;
    6468
    6569    # Get files
     
    6973        next unless $line =~ /\S+/;
    7074        my @fields = split(/\s+/, $line); # Fields in line
    71         my $file = $fields[1];      # Name of file
    72         push @files, $file if defined $file;
     75        &my_die( "too few columns in fileset list entry: $line\n", $fileset_id, $PS_EXIT_DATA_ERROR) unless scalar @fields >= 6;
     76
     77        print $listFile "FILE$numFiles\tMETADATA\n";
     78
     79        print $listFile "\turi\t\tSTR\t" . $fields[0] .  "\n";
     80        print $listFile "\tfile\t\tSTR\t" . $fields[1] .  "\n";
     81        print $listFile "\tbytes\t\tS64\t" . $fields[2] .  "\n";
     82        print $listFile "\tmd5sum\t\tSTR\t" . $fields[3] .  "\n";
     83        print $listFile "\tfile_type\tSTR\t" . $fields[4] .  "\n";
     84        print $listFile "\tcomponent\tSTR\t" . $fields[5] .  "\n";
     85
     86        print $listFile "END\n";
     87        $numFiles++;
    7388    }
     89    close $listFile;
    7490}
    7591
    7692# Add files
    77 if (scalar @files > 0) {
     93my $new_state;
     94if ($numFiles > 0) {
     95    $new_state = "listed";
    7896    my $command = "receivetool -addfile"; # Command to execute
    7997    $command .= " -fileset_id $fileset_id";
    80     $command .= " -file " . join(' -file ', @files);
     98    $command .= " -file_list $listName";
    8199    $command .= " -dbname $dbname" if defined $dbname;
    82100
     
    84102        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    85103            run(command => $command, verbose => $verbose);
    86         die "Unable to add file for fileset $fileset\n" unless $success;
     104        &my_die( "Unable to add file list for fileset $fileset\n", $fileset_id, $error_code) unless $success;
     105    }
     106} else {
     107    print STDERR "fileset $fileset has no files\n" if $verbose;
     108    $new_state = "full";
     109}
     110
     111{
     112    my $command = "receivetool -updatefileset"; # Command to execute
     113    $command .= " -fileset_id $fileset_id";
     114    $command .= " -set_state $new_state";
     115    $command .= " -dbname $dbname" if defined $dbname;
     116
     117    unless (defined $no_update) {
     118        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     119            run(command => $command, verbose => $verbose);
     120        &my_die( "Unable to set state to $new_state for fileset $fileset\n", $fileset_id, $error_code) unless $success;
    87121    }
    88122}
    89123
     124sub my_die {
     125    my $msg = shift;            # Exit message
     126    my $fileset_id = shift;     # File identifier
     127    my $fault = shift;          # Fault code
     128
     129    $fault = $PS_EXIT_PROG_ERROR unless defined $fault;
     130
     131    carp($msg);
     132    if (not $no_update) {
     133        my $command = "$receivetool -updatefileset";
     134        $command .= " -fileset_id $fileset_id";
     135        $command .= " -fault $fault";
     136        $command .= " -dbname $dbname" if defined $dbname;
     137
     138        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     139            run(command => $command, verbose => $verbose);
     140        die "Unable to set fault to $fault for fileset $fileset\n" unless $success;
     141    }
     142    exit $fault;
     143}
    90144__END__
Note: See TracChangeset for help on using the changeset viewer.