IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 15, 2009, 1:53:33 PM (17 years ago)
Author:
bills
Message:

implementation for "get_image" jobs

File:
1 edited

Legend:

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

    r20220 r26151  
    1616use File::Basename;
    1717use Digest::MD5::File qw( file_md5_hex );
     18use IPC::Cmd 0.36 qw( can_run run );
    1819
    19 use PS::IPP::Config qw($PS_EXIT_SUCCESS
    20                        $PS_EXIT_UNKNOWN_ERROR
    21                        $PS_EXIT_SYS_ERROR
    22                        $PS_EXIT_CONFIG_ERROR
    23                        $PS_EXIT_PROG_ERROR
    24                        $PS_EXIT_DATA_ERROR
    25                        $PS_EXIT_TIMEOUT_ERROR
    26                        metadataLookupStr
    27                        metadataLookupBool
    28                        caturi
    29                        );
     20
     21use PS::IPP::Config qw( :standard );
     22
    3023my $product;
    3124my $fileset;
    3225
    33 my $uri;
    34 my $out_dir;
     26my $output_base;
    3527
    36 my $verbose = 1;
     28my $verbose;
    3729my $ipprc;
    3830my $dbname;
     31my $dbserver;
    3932my $job_id;
    4033my $rownum;
     
    4740        'job_id=s'        =>      \$job_id,
    4841        'rownum=s'        =>      \$rownum,
    49         'uri=s'           =>      \$uri,
    50         'out_dir=s'       =>      \$out_dir,
     42        'output_base=s'   =>      \$output_base,
    5143        'dbname=s'        =>      \$dbname,
     44        'dbserver=s'      =>      \$dbserver,
     45        'verbose'         =>      \$verbose,
    5246) or pod2usage(2);
    5347
     
    5549$err .= "--job_id is required\n" if (!$job_id);
    5650$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);
     51$err .= "--output_base is required to specify the output fileset\n" if (!$output_base);
    5952
    6053die $err if $err;
    6154
    62 # collapse any multiple slashes in output_dir
    63 $out_dir = File::Spec->canonpath($out_dir);
     55my $params_file = $output_base . ".params";
     56if (! open(INPUT, "<$params_file") ) {
     57    die("failed to open params file: $params_file");
     58}
    6459
    65 my @path = split(/\//, $out_dir);
     60my $params = join "", (<INPUT>);
    6661
    67 my $nelem = @path;
    68 if ($nelem < 2) {
    69     die("$out_dir is not a valid output fileset directory");
     62print STDERR "\nparams is $params\n";
     63
     64my ($stage, $stage_id, $component, $path_base, $camera) = split " ", $params;
     65if (!$camera or !$path_base or !$component or !$stage_id or !$stage) {
     66   die "failed to parse params: $params";
    7067}
    71 $fileset = $path[$nelem-1];
    72 $product = $path[$nelem-2];
    7368
    74 $_ = $out_dir;
    75 my ($ds_dir) = m%(.*)/$product/$fileset%;
     69print STDERR "\nCAMERA is $camera\n";
    7670
    77 if ($verbose) {
    78     print STDERR "DS root:  $ds_dir\n";
    79     print STDERR "Product:  $product\n";
    80     print STDERR "Fileset:  $fileset\n";
    81     print STDERR "Filelist: $uri\n";
     71my $out_dir = dirname($output_base);
     72my $prefix = basename($output_base);
     73my $results_file = $output_base . ".bundle_results";
     74
     75# Look for programs we need
     76my $missing_tools;
     77my $dist_bundle   = can_run('dist_bundle.pl') or (warn "Can't find dist_bundle.pl" and $missing_tools = 1);
     78if ($missing_tools) {
     79    warn("Can't find required tools.");
     80    exit($PS_EXIT_CONFIG_ERROR);
    8281}
    8382
    8483
    85 if (!stat("$ds_dir/index.txt")) {
    86     $err .= "Data Store not found at '$ds_dir'.\n"
     84{
     85    my $command = "$dist_bundle --camera $camera --stage $stage --stage_id $stage_id --component $component";
     86    $command .= " --path_base $path_base --outdir $out_dir --results_file $results_file";
     87    $command .= " --prefix $prefix";
     88    # ignore magic for now
     89    $command .= " --no_magic";
     90
     91    $command .= " --dbname $dbname" if $dbname;
     92    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     93        run(command => $command, verbose => $verbose);
     94    unless ($success) {
     95        die("Unable to perform $command: $error_code");
     96    }
    8797}
    8898
    89 show_usage("Invalid product '$product'.")
    90     unless defined stat("$ds_dir/$product/index.txt");
    91 
    92 if (! open(INPUT, "<$uri") ) {
    93     die("failed to open file list: $uri");
     99if (! open(RESULTS, "<$results_file")) {
     100    die("failed to open bundle results file: $results_file");
    94101}
    95102
    96 my $reglist = "$out_dir/reglist";
    97 if (! open(REGLIST, ">$reglist$job_id") ) {
     103my $file_name;
     104my $bytes;
     105my $md5sum;
     106foreach my $line (<RESULTS>) {
     107    chomp $line;
     108    next if !$line;
     109    next if $line =~ /bundleResults/;
     110    last if $line =~ /END/;
     111
     112    my ($tag, $type, $val) = split " ", $line;
     113    if ($tag eq "name") {
     114        $file_name = $val;
     115    } elsif ($tag eq "bytes") {
     116        $bytes = $val;
     117    } elsif ($tag eq "md5sum") {
     118        $md5sum = $val;
     119    } else {
     120        die("unexpected tag: $tag  found in results file: $results_file");
     121    }
     122}
     123
     124my $reglist = "$out_dir/reglist$job_id";
     125if (! open(REGLIST, ">$reglist") ) {
    98126    die("failed to open registration list: $reglist");
    99127}
    100128
    101 my @files;
    102 my $num = 0;
    103 while (<INPUT>) {
    104     chomp;
    105     my @fields = split /\|/;
    106     my $pathname = shift @fields;
    107     my $filetype = shift @fields;
    108     my $class_id = shift @fields;
    109 
    110     ($pathname , my $filename) = resolvepath($pathname);
    111 
    112     if ($verbose) {
    113         print STDERR "$pathname @fields\n";
    114     }
    115 
    116     $num++;
    117     $filename = "${rownum}_${num}_$filename";
    118     my $dest_path = "$out_dir/$filename";
    119     if (! copy $pathname, "$dest_path" ) {
    120         die("failed trying to copy $pathname to $out_dir");
    121     }
    122 
    123     # XXX is pstamp always the right file type, if not where can we get the right one?
    124     print REGLIST file_registration_line($filename, $dest_path, $filetype, $class_id);
    125 
    126     foreach my $f (@fields) {
    127         print REGLIST "$f|";
    128     }
    129     print REGLIST "\n";
    130 }
     129print REGLIST "$file_name|$bytes|$md5sum|tgz|\n";
    131130
    132131close(REGLIST);
    133132
    134133exit 0;
    135 
    136 sub resolvepath {
    137     my $pathname = $_[0];
    138 
    139     # use the basename of the unresolved file as the name of the file
    140     # in order to avoid nebulous name mangled paths in the datastore
    141     my $file = basename($pathname);
    142 
    143     my $slash = index($pathname, "/");
    144     if ($slash != 0) {
    145         if (!$ipprc) {
    146             $ipprc = PS::IPP::Config->new();
    147         }
    148         $pathname = $ipprc->file_resolve($pathname);
    149     }
    150 
    151 
    152     return ($pathname, $file);
    153 }
    154 
    155 # XXX move this to a module so the code can be shared
    156 sub file_registration_line {
    157     my $filename = shift;
    158     my $path     = shift;
    159     my $filetype = shift;
    160     my $chipname = shift;
    161     $chipname = $chipname ? "$chipname|" : "";
    162 
    163     if (-e $path) {
    164         my @finfo = stat($path);
    165         die "failed to stat $path" unless (@finfo);    # XXX clean up
    166         my $bytes = $finfo[7];
    167         my $md5sum = file_md5_hex($path);
    168 
    169         return "$filename|$bytes|$md5sum|$filetype|$chipname";
    170     } else {
    171         die "$filename not found at $path";
    172     }
    173 }
Note: See TracChangeset for help on using the changeset viewer.