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/dist_advancerun.pl

    r23874 r25027  
    1616use IPC::Cmd 0.36 qw( can_run run );
    1717use File::Temp qw( tempfile );
    18 use File::Basename qw( basename );
     18use File::Basename qw( dirname);
    1919use PS::IPP::Metadata::Config;
    2020use PS::IPP::Metadata::List qw( parse_md_list );
     
    7272
    7373my $tool_cmd;
     74my $list_mode;
     75my $component_key;
    7476if ($stage eq "raw") {
    7577    $tool_cmd = "$regtool -exp_id";
     78    $list_mode = "-processedimfile";
     79    $component_key = "class_id";
    7680} elsif ($stage eq "chip") {
    7781    $tool_cmd = "$chiptool -chip_id";
     82    $list_mode = "-processedimfile";
     83    $component_key = "class_id";
    7884} elsif ($stage eq "camera") {
    7985    $tool_cmd = "$camtool -cam_id";
     86    $list_mode = "-processedexp";
     87    $component_key = "";
    8088} elsif ($stage eq "fake") {
    8189    $tool_cmd = "$faketool -fake_id";
     90    $list_mode = "-processedimfile";
     91    $component_key = "class_id";
    8292} elsif ($stage eq "warp") {
    8393    $tool_cmd = "$warptool -warp_id";
     94    $list_mode = "-warped";
     95    $component_key = "skycell_id";
    8496} elsif ($stage eq "stack") {
    8597    $tool_cmd = "$stacktool -stack_id";
     98    $list_mode = "-sumskyfile";
     99    $component_key = "skycell_id";
    86100} elsif ($stage eq "diff") {
    87101    $tool_cmd = "$difftool -diff_id";
     102    $list_mode = "-diffskyfile";
     103    $component_key = "skycell_id";
    88104} else {
    89105    &my_die("Unexpected stage: $stage", $dist_id, $PS_EXIT_CONFIG_ERROR);
    90106}
    91107
     108$tool_cmd .= " $stage_id";
     109
    92110# XXX should we create a file rule for this?
    93 my $outfile = "$outdir/dbinfo.$stage.$stage_id.mdc";
    94 
    95 {
    96     my $command = "$tool_cmd $stage_id -exportrun -outfile $outfile";
    97     $command .= " -clean" if defined $clean;
     111my $dbinfo_file = "$outdir/dbinfo.$stage.$stage_id.mdc";
     112
     113{
     114    my $command = "$tool_cmd -exportrun -outfile $dbinfo_file";
     115    $command .= " -clean" if ((defined $clean) and ($stage ne "raw"));
    98116    $command .= " -dbname $dbname" if defined $dbname;
    99117
     
    105123    }
    106124}
    107 
    108 # set distRun.stage = 'full'
    109 {
    110     my $command = "$disttool -updaterun -dist_id $dist_id -set_state full";
     125my $dirinfo = "$outdir/dirinfo.$stage.$stage_id.mdc";
     126{
     127    my $command = "$tool_cmd $list_mode";
    111128    $command .= " -dbname $dbname" if defined $dbname;
    112129
     
    117134        &my_die("Unable to perform $command: $error_code", $dist_id, $error_code);
    118135    }
     136    if (@$stdout_buf == 0) {
     137        &my_die("Unable to perform $command: $error_code", $dist_id, $error_code);
     138    }
     139    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     140        &my_die("Unable to parse metadata config doc", $dist_id, $PS_EXIT_UNKNOWN_ERROR);
     141    my $components = parse_md_list($metadata) or
     142        &my_die("Unable to parse metadata list", $dist_id, $PS_EXIT_UNKNOWN_ERROR);
     143
     144    open MANIFEST, ">$dirinfo" or
     145        &my_die("Unable to open dirinfo file $dirinfo",  $dist_id, $PS_EXIT_UNKNOWN_ERROR);
     146
     147    my $destdir;
     148    foreach my $c (@$components) {
     149        # take the workdir from the first component
     150        if (!$destdir) {
     151            my $workdir = $c->{workdir};
     152            if ($workdir) {
     153                $destdir = stripvolume($workdir, $stage);
     154            } elsif ($stage eq 'raw') {
     155                $destdir = 'none';
     156            } else {
     157                &my_die("workdir not found for open dirinfo file $dirinfo",  $dist_id, $PS_EXIT_UNKNOWN_ERROR);
     158            }
     159            print MANIFEST "destdir METADATA\n";
     160            print MANIFEST "\t" , "destdir", "\tSTR\t", $destdir, "\n";
     161            print MANIFEST "END\n\n";
     162            print MANIFEST "components METADATA\n";
     163        }
     164        my $component = $c->{$component_key} ? $c->{$component_key} : "exposure";
     165        my $path;
     166        if ($stage eq 'raw') {
     167            $path = $c->{uri};
     168        } else {
     169            $path = $c->{path_base};
     170        }
     171        &my_die("unable to find path",  $dist_id, $PS_EXIT_UNKNOWN_ERROR) if !$path;
     172        my $component_dir = find_componentdir($destdir, $path);
     173#        print MANIFEST "$component METADATA\n";
     174        print MANIFEST "\t" , "$component", "\tSTR\t", $component_dir, "\n";
     175    }
     176    print MANIFEST "END\n\n";
     177    close MANIFEST or
     178        &my_die("Unable to close dirinfo file $dirinfo",  $dist_id, $PS_EXIT_UNKNOWN_ERROR);
     179}
     180
     181{
     182    my $command = "$disttool -updaterun -dist_id $dist_id -set_state full";
     183    $command .= " -dbname $dbname" if defined $dbname;
     184
     185    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     186        run(command => $command, verbose => $verbose);
     187    unless ($success) {
     188        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     189        &my_die("Unable to perform $command: $error_code", $dist_id, $error_code);
     190    }
    119191}
    120192
     
    124196### Pau.
    125197
     198sub stripvolume
     199{
     200    my $path = shift;
     201    my $stage = shift;
     202    my @segments;
     203
     204    # workdir isn't what we want for raw stage
     205    return "none" if ($stage and ($stage eq 'raw'));
     206
     207    my $scheme = file_scheme($path);
     208    my $tail;
     209    if ($scheme) {
     210        # strip off scheme://
     211        $tail = substr($path, length($scheme) + 3);
     212    } elsif (substr($path, 0, 1) eq '/') {
     213        $tail = substr($path, 1);
     214        $scheme = "";
     215    }
     216    # remove any leading / that are left
     217    while ((substr($tail, 0, 1) eq '/')) {
     218        $tail = substr($tail, 1);
     219    }
     220
     221    if (($scheme eq 'neb') or ($scheme eq 'path')) {
     222        my $volume;
     223        ($volume, @segments) = split '/', $tail;
     224
     225    } elsif (!$scheme or ($scheme eq 'file')) {
     226
     227        # XXX Here we're assuming the /data/ipp??? structure. This won't be true when data is forwarded
     228        # by remote sites. We need a way to configure this
     229        my $volume;
     230
     231        # data/ippxxx/dirs
     232        (undef, $volume, @segments) = split '/', $tail;
     233    } else {
     234        die( "unexpected workdir value: $path\n");
     235    }
     236
     237    return caturi(@segments);
     238}
     239
     240sub find_componentdir
     241{
     242    my $destdir = shift;
     243    my $path = shift;
     244
     245    my $result;
     246    if ($destdir eq 'none') {
     247        $result = stripvolume($path);
     248    } else {
     249        # find location of destdir in the path
     250        my $i = index($path, $destdir);
     251
     252        $result = substr($path, $i + length($destdir) + 1);
     253
     254        while (substr($result, 0, 1) eq '/') {
     255            $result = substr($result, 1);
     256        }
     257    }
     258    return dirname($result);
     259}
    126260
    127261sub my_die
Note: See TracChangeset for help on using the changeset viewer.