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/ippScripts/scripts/summit_copy.pl

    r23688 r25406  
    1212use Sys::Hostname;
    1313
     14use Digest::MD5::File qw( file_md5_hex );
    1415use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    1516use Pod::Usage qw( pod2usage );
     
    2122
    2223# Parse the command-line arguments
    23 my ( $uri, $filename, $compress, $bytes, $md5, $nebulous, $exp_name, $inst, $telescope, $class, $class_id, $end_stage, $workdir,
     24my ( $uri, $filename, $compress, $bytes, $md5, $nebulous, $exp_name, $inst, $telescope, $class, $class_id,
    2425     $dbname, $verbose, $no_update, $no_op, $timeout, $copies );
    2526GetOptions(
     
    3536       'class=s'        => \$class,     # Class level
    3637       'class_id=s'     => \$class_id,  # Class identifier
    37        'end_stage=s'    => \$end_stage, # end of processing
    38        'workdir=s'      => \$workdir,   # workdir
    3938       'dbname=s'       => \$dbname,    # Database name
    4039       'verbose'        => \$verbose,   # Print to stdout
     
    6261my $pztool = can_run('pztool')
    6362    or (warn "Can't find pztool" and $missing_tools = 1);
     63my $neblocate = can_run('neb-locate')
     64    or (warn "Can't find neb-locate" and $missing_tools = 1);
    6465if ($missing_tools) {
    6566    warn("Can't find required tools.");
    6667    exit($PS_EXIT_CONFIG_ERROR);
    6768}
     69
     70my $ipprc = PS::IPP::Config->new();
    6871
    6972# dsget command
     
    97100}
    98101
     102#
     103# Find all instances of the new file and make sure they have the
     104# same checksum and size.
     105# if so pass the results to pztool to the results in pzDownloadImfile.
     106# uncomment this to turn on
     107# my ($new_bytes, $new_md5) = check_instances($filename, $nebulous, $compress);
     108
    99109# command to update database
    100110$command  = "$pztool -copydone";
     
    106116$command .= " -class_id $class_id";
    107117$command .= " -uri $filename";
    108 # $command .= " -workdir $workdir";
    109118$command .= " -hostname $host";
    110 # $command .= " -end_stage $end_stage" if defined $end_stage;
    111119$command .= " -dbname $dbname" if defined $dbname;
     120
     121# XXX: TODO: see above. Don't do this until pztool and the DB have
     122# been updated
     123# $command .= " -md5sum $new_md5 -bytes $new_bytes";
    112124
    113125# update the database
     
    122134} else {
    123135    print "skipping command: $command\n";
     136}
     137
     138sub get_file_params
     139{
     140    my $filename = shift;
     141
     142    my $size = -s $filename;
     143    my $md5 = file_md5_hex($filename);
     144
     145    return ($size, $md5);
     146}
     147
     148sub check_instances {
     149    my $filename = shift;
     150    my $nebulous = shift;
     151    my $compress = shift;
     152
     153    my @instances;
     154    if ($nebulous) {
     155        my $command = "$neblocate --path --all $filename";
     156        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf )
     157            = run(command => $command, verbose => $verbose);
     158        unless ($success) {
     159            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     160            my_die("Unable to perform neb-locate: $error_code",
     161                $exp_name,
     162                $inst,
     163                $telescope,
     164                $class,
     165                $class_id,
     166                $uri,
     167                $error_code
     168            );
     169        }
     170        @instances = split "\n", join "", @$stdout_buf;
     171    } else {
     172        if (!defined $ipprc) {
     173            # we don't usually need this so defer instantaiating it
     174            $ipprc = PS::IPP::Config->new();
     175        }
     176        my $resolved = $ipprc->file_resolve($filename);
     177        if ($resolved) {
     178            $instances[0] = $resolved;
     179        }
     180    }
     181    if (! scalar @instances) {
     182        my_die("no instances",
     183                    $exp_name,
     184                    $inst,
     185                    $telescope,
     186                    $class,
     187                    $class_id,
     188                    $uri,
     189                    $PS_EXIT_UNKNOWN_ERROR
     190            );
     191    }
     192
     193    my ($new_bytes, $new_md5) = get_file_params($instances[0]);
     194       
     195    for (my $i = 1; $i < scalar @instances; $i++) {
     196        my ($b, $m) = get_file_params($instances[$i]);
     197        my $error = "";
     198        if ($b ne $new_bytes) {
     199            $error = "size of $instances[$i] does not match $instances[0]";
     200        } elsif ($m != $new_md5) {
     201            $error = "md5sum of $instances[$i] does not match $instances[0]";
     202        }
     203        if ($error) {
     204            my_die($error,
     205                    $exp_name,
     206                    $inst,
     207                    $telescope,
     208                    $class,
     209                    $class_id,
     210                    $uri,
     211                    $PS_EXIT_DATA_ERROR
     212            );
     213        }
     214    }
     215
     216    return ($new_bytes, $new_md5);
     217   
    124218}
    125219
Note: See TracChangeset for help on using the changeset viewer.