IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 26, 2009, 1:59:32 PM (17 years ago)
Author:
beaumont
Message:

merged with trunk

Location:
branches/cnb_branches/cnb_branch_20090301
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/cnb_branches/cnb_branch_20090301

  • branches/cnb_branches/cnb_branch_20090301/ippScripts/scripts/dist_advancerun.pl

    r23352 r24244  
    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 );
     
    2828
    2929# Parse the command-line arguments
    30 my ($dist_id, $stage, $stage_id, $clean, $outroot);
     30my ($dist_id, $stage, $stage_id, $outdir, $clean);
    3131my ($dbname, $save_temps, $verbose, $no_update, $no_op, $logfile);
    3232
     
    3535           'stage=s'        => \$stage,      # raw, chip, warp, or diff
    3636           'stage_id=s'     => \$stage_id,   # exp_id, chip_id, warp_id, or diff_id
    37            'outroot=s'      => \$outroot,    # "directory" for outputs
     37           'clean'          => \$clean,      # exporting a clean run
     38           'outdir=s'       => \$outdir,     # "directory" for outputs
    3839           'save-temps'     => \$save_temps, # Save temporary files?
    3940           'dbname=s'       => \$dbname,     # Database name
     
    4546
    4647pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    47 pod2usage( -msg => "Required options: --dist_id --stage --stage_id --outroot",
     48pod2usage( -msg => "Required options: --dist_id --stage --stage_id --outdir",
    4849           -exitval => 3) unless
    4950    defined $dist_id and
    5051    defined $stage and
    5152    defined $stage_id and
    52     defined $outroot;
     53    defined $outdir;
    5354
    5455$ipprc->redirect_output($logfile) if $logfile;
     
    7071my $mdcParser = PS::IPP::Metadata::Config->new;
    7172
    72 my $tool;
     73my $tool_cmd;
     74my $list_mode;
     75my $component_key;
    7376if ($stage eq "raw") {
    74     $tool = "regtool";
     77    $tool_cmd = "$regtool -exp_id";
     78    $list_mode = "-processedimfile";
     79    $component_key = "class_id";
    7580} elsif ($stage eq "chip") {
    76     $tool = "chiptool";
     81    $tool_cmd = "$chiptool -chip_id";
     82    $list_mode = "-processedimfile";
     83    $component_key = "class_id";
    7784} elsif ($stage eq "camera") {
    78     $tool = "camtool";
     85    $tool_cmd = "$camtool -cam_id";
     86    $list_mode = "-processedexp";
     87    $component_key = "";
    7988} elsif ($stage eq "fake") {
    80     $tool = "faketool";
     89    $tool_cmd = "$faketool -fake_id";
     90    $list_mode = "-processedimfile";
     91    $component_key = "class_id";
    8192} elsif ($stage eq "warp") {
    82     $tool = "warptool";
     93    $tool_cmd = "$warptool -warp_id";
     94    $list_mode = "-warped";
     95    $component_key = "skycell_id";
    8396} elsif ($stage eq "stack") {
    84     $tool = "stacktool";
     97    $tool_cmd = "$stacktool -stack_id";
     98    $list_mode = "-sumskyfile";
     99    $component_key = "skycell_id";
    85100} elsif ($stage eq "diff") {
    86     $tool = "difftool";
     101    $tool_cmd = "$difftool -diff_id";
     102    $list_mode = "-diffskyfile";
     103    $component_key = "skycell_id";
    87104} else {
    88105    &my_die("Unexpected stage: $stage", $dist_id, $PS_EXIT_CONFIG_ERROR);
    89106}
    90107
    91 # XXX Should we create a file rule for this
    92 my $outfile = "$outroot/dbinfo.$stage.$stage_id.mdc";
    93 
    94 {
    95     my $id_arg = "-$stage" . "_id";
    96     my $command = "$tool -exportrun $id_arg $stage_id -outfile $outfile";
     108$tool_cmd .= " $stage_id";
     109
     110# XXX should we create a file rule for this?
     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;
    97116    $command .= " -dbname $dbname" if defined $dbname;
    98117
     
    104123    }
    105124}
    106 
    107 # set distRun.stage = 'full'
    108 {
    109     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";
    110128    $command .= " -dbname $dbname" if defined $dbname;
    111129
     
    116134        &my_die("Unable to perform $command: $error_code", $dist_id, $error_code);
    117135    }
     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    }
    118191}
    119192
     
    123196### Pau.
    124197
     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}
    125260
    126261sub my_die
     
    134269    my $command = "$disttool -updaterun";
    135270    $command   .= " -dist_id $dist_id";
    136     $command   .= " -code $exit_code";
     271    $command   .= " -fault $exit_code";
    137272    $command   .= " -dbname $dbname" if defined $dbname;
    138273
Note: See TracChangeset for help on using the changeset viewer.