IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18543


Ignore:
Timestamp:
Jul 15, 2008, 10:09:05 AM (18 years ago)
Author:
bills
Message:

Each get_image job now builds the data needed by dsreg to register the
job's output files in the output fileset

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/scripts/pstamp_get_image_job.pl

    r16959 r18543  
    1515use File::Copy;
    1616use File::Basename;
     17use Digest::MD5::File qw( file_md5_hex );
    1718
    1819use PS::IPP::Config qw($PS_EXIT_SUCCESS
     
    3536my $verbose = 1;
    3637my $ipprc;
     38my $dbname;
     39my $job_id;
     40my $rownum;
    3741
    3842#
     
    4145
    4246GetOptions(
     47        'job_id=s'        =>      \$job_id,
     48        'rownum=s'        =>      \$rownum,
    4349        'uri=s'           =>      \$uri,
    4450        'out_dir=s'       =>      \$out_dir,
     51        'dbname=s'        =>      \$dbname,
    4552) or pod2usage(2);
    4653
    4754my $err = "";
     55$err .= "--job_id is required\n" if (!$job_id);
     56$err .= "--rownum is required\n" if (!$rownum);
     57$err .= "--uri is required to specify the file list\n" if (!$uri);
     58$err .= "--out_dir is required to specify the output fileset\n" if (!$out_dir);
    4859
    49 if (!$uri) {
    50     die("--uri is required to specify the file list");
    51 }
    52 if (!$out_dir) {
    53     die("--out_dir is required to specify the output fileset");
    54 }
     60die $err if $err;
    5561
    5662# collapse any multiple slashes in output_dir
     
    8995
    9096my $reglist = "$out_dir/reglist";
    91 if (! open(REGLIST, ">$reglist") ) {
     97if (! open(REGLIST, ">$reglist$job_id") ) {
    9298    die("failed to open registration list: $reglist");
    9399}
    94100
    95101my @files;
     102my $num = 0;
    96103while (<INPUT>) {
    97104    chomp;
    98105    my @fields = split /\|/;
    99106    my $pathname = shift @fields;
    100 
    101     #my ($volume, $directories, $filename) = File::Spec->splitpath($pathname);
     107    my $filetype = shift @fields;
    102108
    103109    ($pathname , my $filename) = resolvepath($pathname);
     
    107113    }
    108114
    109     if (! symlink $pathname, "$out_dir/$filename" ) {
    110         die("failed trying to create symlink to $pathname in $out_dir");
     115    $num++;
     116    $filename = "${rownum}_${num}_$filename";
     117    my $dest_path = "$out_dir/$filename";
     118    if (! copy $pathname, "$dest_path" ) {
     119        die("failed trying to copy $pathname to $out_dir");
    111120    }
    112121
    113     print REGLIST "$filename|";
     122    # XXX is pstamp always the right file type, if not where can we get the right one?
     123    print REGLIST file_registration_line($filename, $dest_path, $filetype);
     124
    114125    foreach my $f (@fields) {
    115126        print REGLIST "$f|";
     
    120131close(REGLIST);
    121132
    122 #only thing left to do is register the fileset
    123 exec "dsreg < $reglist --add --product $product --fileset $fileset --type PSRESULTS";
    124 
     133exit 0;
    125134
    126135sub resolvepath {
     
    139148    return ($pathname, $file);
    140149}
     150
     151# XXX move this to a module so the code can be shared
     152sub file_registration_line {
     153    my $filename = shift;
     154    my $path     = shift;
     155    my $filetype = shift;
     156    if (-e $path) {
     157        my @finfo = stat($path);
     158        die "failed to stat $path" unless (@finfo);    # XXX clean up
     159        my $bytes = $finfo[7];
     160        my $md5sum = file_md5_hex($path);
     161
     162        return "$filename|$bytes|$md5sum|$filetype|";
     163    } else {
     164        die "$filename not found at $path";
     165    }
     166}
Note: See TracChangeset for help on using the changeset viewer.