Changeset 13631
- Timestamp:
- Jun 4, 2007, 5:19:57 PM (19 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
r13629 r13631 1 1 # Copyright (c) 2006 Paul Price, Joshua Hoblitt 2 2 # 3 # $Id: Config.pm,v 1.5 3 2007-06-05 02:49:03price Exp $3 # $Id: Config.pm,v 1.54 2007-06-05 03:19:57 price Exp $ 4 4 5 5 package PS::IPP::Config; … … 86 86 path => $path, # Path 87 87 camera => undef, # Camera configuration 88 rejection => undef, # Rejection data 88 89 _ipprc => $mdc # The parsed configuration 89 90 }; … … 95 96 } 96 97 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 99 sub _find_config 100 { 101 my $self = shift; # Configuration object 102 my $filename = shift; # File name to find 114 103 115 104 my @path = split /:/, $self->{path}; # List of paths to try … … 127 116 if (-f $realfile) { 128 117 $found = 1; 129 last;118 return $realfile; 130 119 } 131 120 } … … 143 132 } 144 133 } 134 135 carp "Unable to find configuration file: $filename"; 136 exit($PS_EXIT_CONFIG_ERROR); 137 } 138 139 # Define a camera to use 140 sub 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 145 158 146 159 # Read the file … … 534 547 } 535 548 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 548 582 TYPES: foreach my $item (@$rejection) { 549 583 if (lc($item->{name}) eq $type) {
Note:
See TracChangeset
for help on using the changeset viewer.
