IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 6, 2023, 6:00:06 PM (3 years ago)
Author:
eugene
Message:

big re-work to allow repeat, iterated fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/eam/rawfix.20230221/src/get_md5s_instances.pl

    r42441 r42444  
    1111use Getopt::Long qw( GetOptions :config auto_help auto_version );
    1212
    13 # USAGE: get_md5s_instances.pl --hostname (hostname) --input (file) --stage (v0,v1,etc)
     13# USAGE: get_md5s_instances.pl --hostname (hostname) --input (file) --stage (0,1,etc)
    1414
    1515my ($myhost, $input, $stage) = &parse_cmdopts;
     
    2626
    2727if ($output eq $input) { die "output file ($output) matches input file ($input)\n"; }
     28
     29# read in both instance
     30my $out_hash_r;
    2831if (-e $output) {
    29     # check that all instances are in the output file?
    30     print "$output exists, skipping\n";
    31     exit 0;
     32    $out_hash_r = &load_output_list ($output);
    3233}
    3334
    34 open (OUTFILE, ">$output");
     35open (OUTFILE, ">>$output");
    3536
    3637# foreach my $instance (@$ins_list_r) {
     
    4142    my $md5sum_tru = $md5_list_r->[$i];
    4243
     44    # if the instance is already in the output file, skip it
     45    if (defined $out_hash_r) {
     46        my $name = $out_hash_r->{$instance};
     47        if (defined $name) {
     48            print STDERR "skipping $instance (already in output)\n";
     49            next;
     50        }
     51    }
     52
    4353    my $filename = $instance;
    4454    $filename =~ s|file://||;
    45    
     55
    4656    # check for the existence of the file first:
    4757    unless (-e $filename) {
     
    6373exit 0;
    6474
    65 # read the list of chip_ids:
     75# read the instance info
    6676sub load_instance_list {
    6777    my $infile = $_[0];
     
    8898}
    8999
     100# read the instance list in the output file
     101sub load_output_list {
     102    my $infile = $_[0];
     103
     104    my (%out_hash);
     105
     106    open(FILE,$infile) or die "cannot open file $infile\n";
     107
     108    my @lines = <FILE>;
     109
     110    foreach my $line (@lines) {
     111        chomp $line;
     112        if ($line =~ /^\s*#/) { next; } # skip lines with leading #
     113        my @words = split (/\s+/,$line);
     114
     115        if (@words != 4) { die "error in input $infile : $line\n"; }
     116        $out_hash{$words[0]} = 1;
     117    }
     118    close (FILE);
     119
     120    return (\%out_hash);
     121}
     122
    90123sub parse_cmdopts {
    91124
     
    95128    pod2usage( -msg => "Provide the input list with --input", -exitval => 2) unless defined $input;
    96129    pod2usage( -msg => "Define the host machine with --hostname", -exitval => 2) unless defined $myhost;
    97     pod2usage( -msg => "Define the stage (v0, v1, etc) with --stage", -exitval => 2) unless defined $stage;
     130    pod2usage( -msg => "Define the stage (0, 1, etc) with --stage", -exitval => 2) unless defined $stage;
     131   
     132    # check that stage is an integer
     133    unless (is_integer ($stage)) { die "stage must be a non-negative integer\n"; }
     134    unless ($stage >= 0) { die "stage must be a non-negative integer\n"; }
    98135   
    99136    return ($myhost, $input, $stage);
     
    106143    return $status;
    107144}
     145
     146sub is_integer {
     147   defined $_[0] && $_[0] =~ /^[+-]?\d+$/;
     148}
     149   
Note: See TracChangeset for help on using the changeset viewer.