IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15184


Ignore:
Timestamp:
Oct 3, 2007, 12:15:02 PM (19 years ago)
Author:
Paul Price
Message:

Allow redirect to a file with FILERULES.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/PS-IPP-Config/lib/PS/IPP/Config.pm

    r14794 r15184  
    11# Copyright (c) 2006  Paul Price, Joshua Hoblitt
    22#
    3 # $Id: Config.pm,v 1.69 2007-09-07 21:39:58 price Exp $
     3# $Id: Config.pm,v 1.70 2007-10-03 22:15:02 price Exp $
    44
    55package PS::IPP::Config;
     
    8787        path => $path,          # Path
    8888        camera => undef,        # Camera configuration
     89        filerules => undef,     # File rules from the camera configuration
    8990        rejection => undef,     # Rejection data
    9091        _ipprc => $mdc          # The parsed configuration
     
    654655    }
    655656
    656     my $camera = $self->{camera}; # Camera configuration
    657     unless (defined $camera) {
    658         carp "Camera has not yet been defined.\n";
    659         return undef;
    660     }
    661 
    662     my $filerules = metadataLookupMD($camera, 'FILERULES');     # File rules
    663     unless (defined $filerules) {
    664         carp "Can't find FILERULES list in camera configuration.\n";
    665         return undef;
     657    my $filerules;              # File rules
     658    if (defined $self->{filerules}) {
     659        $filerules = $self->{filerules};
     660    } else {
     661        # Get the file rules from the camera configuration
     662
     663        my $camera = $self->{camera}; # Camera configuration
     664        unless (defined $camera) {
     665            carp "Camera has not yet been defined.\n";
     666            return undef;
     667        }
     668       
     669        $filerules = metadataLookup($camera, 'FILERULES');      # File rules
     670        unless (defined $filerules) {
     671            carp "Can't find FILERULES list in camera configuration.\n";
     672            return undef;
     673        }
     674       
     675        if ($filerules->{class} eq "scalar" and $filerules->{type} eq "STR") {
     676            # Allow indirection to a file
     677            my $filename = $self->_find_config($filerules->{value}); # Resolved filename
     678            # Read the file
     679            my $file;           # File handle
     680            unless (open $file, $filename) {
     681                carp "Unable to open filerules file $filename: $!";
     682                exit($PS_EXIT_CONFIG_ERROR);
     683            }
     684            my @contents = <$file>;
     685            close $file;
     686            $filerules = $parser->parse( join '', @contents);
     687        } elsif ($filerules->{class} eq "metadata") {
     688            $filerules = $filerules->{value};
     689        } else {
     690            carp "Can't interpret FILERULES in camera configuration.\n";
     691            return undef;
     692        }
     693        $self->{filerules} = $filerules;
    666694    }
    667695
     
    845873}
    846874
    847 # Lookup the metadata, checking the type is STR
    848 sub metadataLookupStr
     875sub metadataLookup
    849876{
    850877    my $mdc = shift;            # Metadata config to look up
     
    859886    foreach my $item (@$mdc) {
    860887        if ($item->{name} eq $name) {
    861             carp "$name within metadata is not of type STR.\n" unless $item->{type} eq "STR";
    862             return $item->{value};
     888            return $item;
    863889        }
    864890    }
     
    867893    return undef;
    868894}
     895   
     896
     897# Lookup the metadata, checking the type is STR
     898sub metadataLookupStr
     899{
     900    my $item = metadataLookup(@_);
     901    return undef if not defined $item;
     902    my $name = shift;           # Name of item
     903    carp "$name within metadata is not of type STR.\n" unless $item->{type} eq "STR";
     904    return $item->{value};
     905}
    869906
    870907# Lookup the metadata, checking the type is MD
    871908sub metadataLookupMD
    872909{
    873     my $mdc = shift;            # Metadata config to look up
    874     my $name = shift;           # Name of item to look ip
    875 
    876     unless (defined $mdc and defined $name) {
    877         carp "Programming error";
    878         exit($PS_EXIT_PROG_ERROR);
    879     }
    880 
    881     # Iterate through the array of hashes
    882     foreach my $item (@$mdc) {
    883         if ($item->{name} eq $name) {
    884             carp "$name within metadata is not of type METADATA.\n" unless $item->{class} eq "metadata";
    885             return $item->{value};
    886         }
    887     }
    888 
    889     carp "Unable to find $name within metadata.\n";
    890     return undef;
     910    my $item = metadataLookup(@_);
     911    return undef if not defined $item;
     912    my $name = shift;           # Name of item
     913    carp "$name within metadata is not of type METADATA.\n" unless $item->{class} eq "metadata";
     914    return $item->{value};
    891915}
    892916
     
    894918sub metadataLookupBool
    895919{
    896     my $mdc = shift;            # Metadata config to look up
    897     my $name = shift;           # Name of item to look ip
    898 
    899     unless (defined $mdc and defined $name) {
    900         carp "Programming error";
    901         exit($PS_EXIT_PROG_ERROR);
    902     }
    903 
    904     # Iterate through the array of hashes
    905     foreach my $item (@$mdc) {
    906         if ($item->{name} eq $name) {
    907             carp "$name within metadata is not of type BOOL.\n" unless $item->{type} eq "BOOL";
    908             return $item->{value};
    909         }
    910     }
    911 
    912     carp "Unable to find $name within metadata.\n";
    913     return undef;
     920    my $item = metadataLookup(@_);
     921    return undef if not defined $item;
     922    my $name = shift;           # Name of item
     923    carp "$name within metadata is not of type BOOL.\n" unless $item->{type} eq "BOOL";
     924    return $item->{value};
    914925}
    915926
Note: See TracChangeset for help on using the changeset viewer.