IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 11, 2006, 4:41:30 PM (20 years ago)
Author:
jhoblitt
Message:

merge in cache feature

File:
1 edited

Legend:

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

    r9492 r9501  
    77$VERSION = '0.01';
    88
     9use Cache::File;
     10use Storable qw(freeze thaw);
     11use File::Basename qw( basename);
    912use IPC::Cmd qw( can_run run );
    1013use PS::IPP::Metadata::Config;
    1114use PS::IPP::Metadata::Stats;
    12 use Storabe qw( freeze thaw );
    13 use Data::Dumper;
    1415
    1516use PS::IPP::Config;
     
    2021use Pod::Usage qw( pod2usage );
    2122
    22 my ($exp_tag, $class_id, $uri, $no_update);
     23my ($cache, $exp_tag, $class_id, $uri, $no_update);
    2324
    2425GetOptions(
    25     'exp_tag|e=s'    => \$exp_tag,
     26    'caches'        => \$cache,
     27    'exp_tag|e=s'   => \$exp_tag,
    2628    'class_id|i=s'  => \$class_id,
    2729    'uri|u=s'       => \$uri,
     
    7577die "Can't find required tools.\n" if $missing_tools;
    7678
     79# setup cache interface
     80
     81my $c = Cache::File->new(
     82    cache_root => File::Spec->catdir($ENV{'HOME'}, '.pxtools', basename($0)),
     83    default_expires => '7200 sec',
     84);
     85
    7786# Resolve the input URI
    7887$uri = File::Spec->rel2abs( $uri, $ipprc->workdir() );
     
    8392    my $command = "$ppStats $uri -recipe PPSTATS " . RECIPE; # Command to run ppStats
    8493    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    85         run(command => $command, verbose => 1);
    86     die "Unable to perform ppStats on exposure id $exp_tag: $error_code\n" if not $success;
     94        cache_run(command => $command, verbose => 1);
     95    die "Unable to perform ppStats on exposure id $exp_tag: $error_code\n"
     96        if not $success;
    8797   
    8898    # Parse the output
     
    123133}
    124134
     135sub cache_run
     136{
     137    my %p = @_;
     138
     139    my $cmd_output = $c->get($p{command}) if $cache;
     140    if (defined $cmd_output) {
     141        return @{thaw $cmd_output};
     142    } else {
     143        my @output = run(%p);
     144        $c->set($p{command}, freeze \@output) if $cache;
     145        return @output;
     146    }
     147}
     148
    125149# Pau.
    126150
Note: See TracChangeset for help on using the changeset viewer.