Changeset 9504 for trunk/PS-IPP-Config/lib/PS/IPP/Config.pm
- Timestamp:
- Oct 12, 2006, 10:12:14 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/PS-IPP-Config/lib/PS/IPP/Config.pm (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/PS-IPP-Config/lib/PS/IPP/Config.pm
r9168 r9504 1 1 # Copyright (c) 2006 Paul Price, Joshua Hoblitt 2 2 # 3 # $Id: Config.pm,v 1. 1 2006-10-04 01:45:47price Exp $3 # $Id: Config.pm,v 1.2 2006-10-12 20:12:14 price Exp $ 4 4 5 5 package PS::IPP::Config; … … 11 11 12 12 use Carp qw( carp croak ); 13 use PS::IPP::Metadata::Config; 13 use File::Spec; 14 use PS::IPP::Metadata::Config 0.07; 14 15 use Getopt::Long qw( GetOptions :config gnu_getopt pass_through ); # Set pass_through so we don't kill @ARGV 15 16 16 17 use base qw( Class::Accessor::Fast ); 17 18 __PACKAGE__->mk_accessors( qw( path workdir ) ); 19 20 our $parser = PS::IPP::Metadata::Config->new; # Metadata parser 21 $parser->overwrite(0); # Turn off overwrite 18 22 19 23 #$::RD_TRACE = 1; … … 24 28 sub new { 25 29 my $class = shift; # Class name 30 my $camera = shift; # Camera name 26 31 27 32 # Get location of ipprc file … … 35 40 close $file; 36 41 37 my $parser = PS::IPP::Metadata::Config->new; # Parser for ipprc file38 42 my $mdc = $parser->parse( join '', @contents); # The parsed metadata config 39 43 40 44 my $path = _mdLookupStr($mdc, 'PATH'); # The path 41 45 my $workdir = _mdLookupStr($mdc, 'WORKDIR'); # The working directory 42 43 46 croak "PATH is not set in $name\n" unless defined $path; 44 47 croak "WORKDIR is not set in $name\n" unless defined $workdir; … … 47 50 path => $path, # Path 48 51 workdir => $workdir, # Working directory 52 camera => undef, # Camera configuration 49 53 _ipprc => $mdc # The parsed configuration 50 54 }; 55 bless $self, $class; 51 56 52 bless $self, $class; 57 $self->define_camera($camera) if defined $camera; 58 53 59 return $self; 54 55 60 } 56 61 57 # Lookup the metadata, checking the type 62 # Define a camera to use 63 sub define_camera 64 { 65 my $self = shift; # Configuration object 66 my $name = shift; # Camera name 67 68 my $camera_list = _mdLookupMD($self->{_ipprc}, 'CAMERAS'); # List of cameras 69 my $filename = _mdLookupStr($camera_list, $name); # Filename of camera configuration 70 my @path = split /:/, $self->{path}; # List of paths to try 71 my $found; # Found it? 72 foreach my $path (@path) { 73 my $test = File::Spec->rel2abs( $filename, $path ); 74 if (-f $test) { 75 $found = $test; 76 last; 77 } 78 } 79 croak "Unable to find camera configuration file $filename\n" if not defined $found; 80 81 # Read the file 82 open my $file, $found or croak "Unable to open camera configuration file $found: $!"; 83 my @contents = <$file>; 84 close $file; 85 $self->{camera} = $parser->parse( join '', @contents); # The parsed metadata config 86 87 return defined $self->{camera}; 88 } 89 90 91 # Return a rejection limit from the camera configuration 92 sub rejection 93 { 94 my $self = shift; # Configuration object 95 my $name = shift; # Name of limit 96 my $type = lc(shift); # Type of frame 97 my $filter = shift; # Filter name, for extra qualification; optional 98 99 my $camera = $self->{camera}; # Camera configuration 100 unless (defined $camera) { 101 carp "Camera has not yet been defined.\n"; 102 return undef; 103 } 104 105 my $rejection = _mdLookupMD($camera, 'REJECTION'); # Rejection list 106 unless (defined $rejection) { 107 carp "Can't find REJECTION list in camera configuration.\n"; 108 return undef; 109 } 110 111 TYPES: foreach my $item (@$rejection) { 112 if (lc($item->{name}) eq $type) { 113 croak "$name within REJECTION is not of type METADATA" unless $item->{class} eq "metadata"; 114 my $limits = $item->{value}; # List of rejection limits 115 116 # Check the FILTER first 117 foreach my $limit (@$limits) { 118 if ($limit->{name} eq 'FILTER') { 119 if ($limit->{value} eq '*' or 120 (defined $filter and 121 $limit->{value} eq $filter)) { 122 last; 123 } 124 next TYPES; # Doesn't match --- look at the next one 125 } 126 } 127 128 foreach my $limit (@$limits) { 129 return $limit->{value} if $limit->{name} eq $name; 130 } 131 carp "Unable to find limit $name in REJECTION list for $type.\n"; 132 return undef; 133 } 134 } 135 136 if (not defined $filter) { 137 carp "Unable to find type $type with no FILTER in REJECTION list.\n"; 138 } else { 139 carp "Unable to find type $type with FILTER $filter in REJECTION list.\n"; 140 } 141 return undef; 142 } 143 144 145 # Lookup the metadata, checking the type is STR 58 146 sub _mdLookupStr 59 147 { … … 73 161 } 74 162 163 # Lookup the metadata, checking the type is MD 164 sub _mdLookupMD 165 { 166 my $mdc = shift; # Metadata config to look up 167 my $name = shift; # Name of item to look ip 168 169 # Iterate through the array of hashes 170 foreach my $item (@$mdc) { 171 if ($item->{name} eq $name) { 172 carp "$name within metadata is not of type METADATA.\n" unless $item->{class} eq "metadata"; 173 return $item->{value}; 174 } 175 } 176 177 carp "Unable to find $name within metadata.\n"; 178 return undef; 179 } 180 75 181 76 182 1;
Note:
See TracChangeset
for help on using the changeset viewer.
