IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 9, 2009, 2:19:48 PM (17 years ago)
Author:
bills
Message:

Pass information about the paths from the distribution server to the client.
Use these to edit the database dump

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/dist_advancerun.pl

    r23874 r24125  
    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";
     111my $dbinfo_file = "$outdir/dbinfo.$stage.$stage_id.mdc";
     112
     113{
     114    my $command = "$tool_cmd -exportrun -outfile $dbinfo_file";
    97115    $command .= " -clean" if defined $clean;
    98116    $command .= " -dbname $dbname" if defined $dbname;
     
    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        if (!$destdir) {
     150            my $workdir = $c->{workdir};
     151            if ($workdir) {
     152                $destdir = stripvolume($workdir, $stage);
     153            } elsif ($stage eq 'raw') {
     154                $destdir = 'none';
     155            } else {
     156                &my_die("workdir not found for open dirinfo file $dirinfo",  $dist_id, $PS_EXIT_UNKNOWN_ERROR);
     157            }
     158            print MANIFEST "destdir METADATA\n";
     159            print MANIFEST "\t" , "destdir", "\tSTR\t", $destdir, "\n";
     160            print MANIFEST "END\n\n";
     161            print MANIFEST "components METADATA\n";
     162        }
     163        my $component = $c->{$component_key} ? $c->{$component_key} : "exposure";
     164        my $path;
     165        if ($stage eq 'raw') {
     166            $path = $c->{uri};
     167        } else {
     168            $path = $c->{path_base};
     169        }
     170        &my_die("unable to find path",  $dist_id, $PS_EXIT_UNKNOWN_ERROR) if !$path;
     171        my $component_dir = find_componentdir($destdir, $path);
     172#        print MANIFEST "$component METADATA\n";
     173        print MANIFEST "\t" , "$component", "\tSTR\t", $component_dir, "\n";
     174    }
     175    print MANIFEST "END\n\n";
     176    close MANIFEST or
     177        &my_die("Unable to close dirinfo file $dirinfo",  $dist_id, $PS_EXIT_UNKNOWN_ERROR);
     178}
     179
     180{
     181    my $command = "$disttool -updaterun -dist_id $dist_id -set_state full";
     182    $command .= " -dbname $dbname" if defined $dbname;
     183
     184    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     185        run(command => $command, verbose => $verbose);
     186    unless ($success) {
     187        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     188        &my_die("Unable to perform $command: $error_code", $dist_id, $error_code);
     189    }
    119190}
    120191
     
    124195### Pau.
    125196
     197sub stripvolume
     198{
     199    my $path = shift;
     200    my $stage = shift;
     201    my @segments;
     202
     203    # workdir isn't what we want for raw stage
     204    return "none" if ($stage and ($stage eq 'raw'));
     205
     206    my $scheme = file_scheme($path);
     207    my $tail;
     208    if ($scheme) {
     209        # strip off scheme://
     210        $tail = substr($path, length($scheme) + 3);
     211    } elsif (substr($path, 0, 1) eq '/') {
     212        $tail = substr($path, 1);
     213        $scheme = "";
     214    }
     215    # remove any leading / that are left
     216    while ((substr($tail, 0, 1) eq '/')) {
     217        $tail = substr($tail, 1);
     218    }
     219
     220    if (($scheme eq 'neb') or ($scheme eq 'path')) {
     221        my $volume;
     222        ($volume, @segments) = split '/', $tail;
     223
     224    } elsif (!$scheme or ($scheme eq 'file')) {
     225
     226        # XXX Here we're assuming the /data/ipp??? structure. This won't be true when data is forwarded
     227        # by remote sites. We need a way to configure this
     228        my $volume;
     229
     230        # data/ippxxx/dirs
     231        (undef, $volume, @segments) = split '/', $tail;
     232    } else {
     233        die( "unexpected workdir value: $path\n");
     234    }
     235
     236    return caturi(@segments);
     237}
     238
     239sub find_componentdir
     240{
     241    my $destdir = shift;
     242    my $path = shift;
     243
     244    my $result;
     245    if ($destdir eq 'none') {
     246        $result = stripvolume($path);
     247    } else {
     248        # find location of destdir in the path
     249        my $i = index($path, $destdir);
     250
     251        $result = substr($path, $i + length($destdir) + 1);
     252
     253        while (substr($result, 0, 1) eq '/') {
     254            $result = substr($result, 1);
     255        }
     256    }
     257    return dirname($result);
     258}
    126259
    127260sub my_die
Note: See TracChangeset for help on using the changeset viewer.