IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13631


Ignore:
Timestamp:
Jun 4, 2007, 5:19:57 PM (19 years ago)
Author:
Paul Price
Message:

New format for rejections: they live in their own file, which is
parsed and cached as required. Added function to search for a
configuration file (e.g., camera configuration file, rejection file).

File:
1 edited

Legend:

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

    r13629 r13631  
    11# Copyright (c) 2006  Paul Price, Joshua Hoblitt
    22#
    3 # $Id: Config.pm,v 1.53 2007-06-05 02:49:03 price Exp $
     3# $Id: Config.pm,v 1.54 2007-06-05 03:19:57 price Exp $
    44
    55package PS::IPP::Config;
     
    8686        path => $path,          # Path
    8787        camera => undef,        # Camera configuration
     88        rejection => undef,     # Rejection data
    8889        _ipprc => $mdc          # The parsed configuration
    8990        };
     
    9596}
    9697
    97 # Define a camera to use
    98 sub define_camera
    99 {
    100     my $self = shift;           # Configuration object
    101     my $name = shift;           # Camera name
    102 
    103     unless (defined $self and defined $name) {
    104         carp "Programming error";
    105         exit($PS_EXIT_PROG_ERROR);
    106     }
    107 
    108     my $camera_list = metadataLookupMD($self->{_ipprc}, 'CAMERAS'); # List of cameras
    109     my $filename = metadataLookupStr($camera_list, $name); # Filename of camera configuration
    110     unless (defined $filename) {
    111         carp "Unable to find configuration file for camera $name\n";
    112         exit($PS_EXIT_CONFIG_ERROR);
    113     }
     98# Find a configuration file, which might be anywhere in the PATH
     99sub _find_config
     100{
     101    my $self = shift;           # Configuration object
     102    my $filename = shift;       # File name to find
    114103
    115104    my @path = split /:/, $self->{path}; # List of paths to try
     
    127116            if (-f $realfile) {
    128117                $found = 1;
    129                 last;
     118                return $realfile;
    130119            }
    131120        }
     
    143132        }
    144133    }
     134
     135    carp "Unable to find configuration file: $filename";
     136    exit($PS_EXIT_CONFIG_ERROR);
     137}
     138
     139# Define a camera to use
     140sub define_camera
     141{
     142    my $self = shift;           # Configuration object
     143    my $name = shift;           # Camera name
     144
     145    unless (defined $self and defined $name) {
     146        carp "Programming error";
     147        exit($PS_EXIT_PROG_ERROR);
     148    }
     149
     150    my $camera_list = metadataLookupMD($self->{_ipprc}, 'CAMERAS'); # List of cameras
     151    my $filename = metadataLookupStr($camera_list, $name); # Filename of camera configuration
     152    unless (defined $filename) {
     153        carp "Unable to find configuration file for camera $name\n";
     154        exit($PS_EXIT_CONFIG_ERROR);
     155    }
     156
     157    my $realfile = $self->_find_config($filename); # Resolved filename, after hunting the PATH
    145158
    146159    # Read the file
     
    534547    }
    535548
    536     my $camera = $self->{camera}; # Camera configuration
    537     unless (defined $camera) {
    538         carp "Camera has not yet been defined.\n";
    539         return undef;
    540     }
    541 
    542     my $rejection = metadataLookupMD($camera, 'REJECTION');     # Rejection list
    543     unless (defined $rejection) {
    544         carp "Can't find REJECTION list in camera configuration.\n";
    545         return undef;
    546     }
    547 
     549    unless (defined $self->{rejection}) {
     550        my $camera = $self->{camera}; # Camera configuration
     551        unless (defined $camera) {
     552            carp "Camera has not yet been defined.\n";
     553            return undef;
     554        }
     555       
     556        my $rejName = metadataLookupStr($camera, 'REJECTION'); # Name of rejection file
     557        unless (defined $rejName) {
     558            carp "Can't find REJECTION list in camera configuration.\n";
     559            return undef;
     560        }
     561       
     562        my $rejRealName = $self->_find_config($rejName); # Resolved filename, after hunting the PATH
     563
     564        my $rejFile;            # Rejection file handle
     565        unless (open $rejFile, $rejRealName) {
     566            carp "Unable to open rejection file $rejRealName: $!";
     567            exit($PS_EXIT_CONFIG_ERROR);
     568        }
     569        my @rejContents = <$rejFile>; # Contents of the rejection file
     570        close $rejFile;
     571       
     572        my $self->{rejection} = $parser->parse( join '', @rejContents); # The rejection metadata
     573        unless (defined $self->{rejection}) {
     574            carp "Unable to parse rejection file $rejRealName.";
     575            exit($PS_EXIT_CONFIG_ERROR);
     576        }
     577    }
     578
     579    my $rejection = $self->{rejection};
     580
     581    # Find the appropriate entry
    548582  TYPES: foreach my $item (@$rejection) {
    549583      if (lc($item->{name}) eq $type) {
Note: See TracChangeset for help on using the changeset viewer.