Changeset 17667
- Timestamp:
- May 13, 2008, 4:06:02 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/PS-IPP-Config/lib/PS/IPP/Config.pm (modified) (70 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/PS-IPP-Config/lib/PS/IPP/Config.pm
r17664 r17667 1 1 # Copyright (c) 2006 Paul Price, Joshua Hoblitt 2 2 # 3 # $Id: Config.pm,v 1.8 4 2008-05-14 01:52:31 billsExp $3 # $Id: Config.pm,v 1.85 2008-05-14 02:06:02 jhoblitt Exp $ 4 4 5 5 package PS::IPP::Config; … … 21 21 22 22 our @EXPORT_OK = qw( 23 $PS_EXIT_SUCCESS24 $PS_EXIT_UNKNOWN_ERROR25 $PS_EXIT_SYS_ERROR26 $PS_EXIT_CONFIG_ERROR27 $PS_EXIT_PROG_ERROR28 $PS_EXIT_DATA_ERROR29 $PS_EXIT_TIMEOUT_ERROR30 metadataLookupStr31 metadataLookupMD32 metadataLookupBool33 caturi34 file_scheme35 );23 $PS_EXIT_SUCCESS 24 $PS_EXIT_UNKNOWN_ERROR 25 $PS_EXIT_SYS_ERROR 26 $PS_EXIT_CONFIG_ERROR 27 $PS_EXIT_PROG_ERROR 28 $PS_EXIT_DATA_ERROR 29 $PS_EXIT_TIMEOUT_ERROR 30 metadataLookupStr 31 metadataLookupMD 32 metadataLookupBool 33 caturi 34 file_scheme 35 ); 36 36 our %EXPORT_TAGS = (standard => [@EXPORT_OK]); 37 37 … … 45 45 46 46 our $parser = PS::IPP::Metadata::Config->new; # Metadata parser 47 $parser->overwrite(0); # Turn off overwrite47 $parser->overwrite(0); # Turn off overwrite 48 48 49 49 #$::RD_TRACE = 1; … … 53 53 # Given a parsed metadata, parse it into an array of hashes 54 54 sub new { 55 my $class = shift; # Class name56 my $camera = shift; # Camera name55 my $class = shift; # Class name 56 my $camera = shift; # Camera name 57 57 58 58 unless (defined $class) { 59 carp "Programming error";60 exit($PS_EXIT_PROG_ERROR);59 carp "Programming error"; 60 exit($PS_EXIT_PROG_ERROR); 61 61 } 62 62 63 63 # Get location of ipprc file 64 my $name; # Name of ipprc file64 my $name; # Name of ipprc file 65 65 GetOptions( 'site=s' => \$name ); 66 66 $name = $ENV{IPPRC} if not defined $name; 67 67 if (not defined $name and defined $ENV{HOME}) { 68 $name = $ENV{HOME} . '/.ipprc';69 } 70 71 my $file; # File handle68 $name = $ENV{HOME} . '/.ipprc'; 69 } 70 71 my $file; # File handle 72 72 unless (open $file, $name) { 73 carp "Unable to open ipprc file $name: $!";74 exit($PS_EXIT_CONFIG_ERROR);75 } 76 my @contents = <$file>; # Contents of the ipprc file73 carp "Unable to open ipprc file $name: $!"; 74 exit($PS_EXIT_CONFIG_ERROR); 75 } 76 my @contents = <$file>; # Contents of the ipprc file 77 77 close $file; 78 78 … … 81 81 my $path = _interpolate_env(metadataLookupStr($mdc, 'PATH')); # The path 82 82 unless (defined $path) { 83 carp "PATH is not set in $name\n";84 exit($PS_EXIT_CONFIG_ERROR);83 carp "PATH is not set in $name\n"; 84 exit($PS_EXIT_CONFIG_ERROR); 85 85 } 86 86 … … 88 88 89 89 my $self = { 90 path => $path,# Path91 camera => undef,# Camera configuration92 filerules => undef,# File rules from the camera configuration93 rejection => undef,# Rejection data94 reductionClasses => undef, # Reduction class definitions95 _userConfig => $mdc,# The top-level user configuration96 _siteConfig => undef,# The site configuration (from _userConfig)97 _systemConfig => undef# The system configuration (from _userConfig)98 };90 path => $path, # Path 91 camera => undef, # Camera configuration 92 filerules => undef, # File rules from the camera configuration 93 rejection => undef, # Rejection data 94 reductionClasses => undef, # Reduction class definitions 95 _userConfig => $mdc, # The top-level user configuration 96 _siteConfig => undef, # The site configuration (from _userConfig) 97 _systemConfig => undef # The system configuration (from _userConfig) 98 }; 99 99 bless $self, $class; 100 100 … … 110 110 sub _find_config 111 111 { 112 my $self = shift; # Configuration object113 my $filename = shift; # File name to find112 my $self = shift; # Configuration object 113 my $filename = shift; # File name to find 114 114 115 115 my @path = split /:/, $self->{path}; # List of paths to try 116 my $found = 0; # Found it?116 my $found = 0; # Found it? 117 117 my $realfile; 118 118 my $tries = 0; 119 119 while (not $found) { 120 ## try a second time121 foreach my $path (@path) {122 $realfile = File::Spec->rel2abs( $filename, $path );123 if ($tries) {124 print "re-trying ($tries): filename: $filename, path: $path -> ";125 print "test: $realfile\n";126 }127 if (-f $realfile) {128 $found = 1;129 return $realfile;130 }131 }132 if (not $found) {133 $tries ++;134 if ($tries > 4) {135 unless ($found) {136 carp "Unable to find camera configuration file $filename\n";137 exit($PS_EXIT_CONFIG_ERROR);138 }139 }140 ## try again after a moment?141 ## system ("df");142 select(undef, undef, undef, 0.25);143 }120 ## try a second time 121 foreach my $path (@path) { 122 $realfile = File::Spec->rel2abs( $filename, $path ); 123 if ($tries) { 124 print "re-trying ($tries): filename: $filename, path: $path -> "; 125 print "test: $realfile\n"; 126 } 127 if (-f $realfile) { 128 $found = 1; 129 return $realfile; 130 } 131 } 132 if (not $found) { 133 $tries ++; 134 if ($tries > 4) { 135 unless ($found) { 136 carp "Unable to find camera configuration file $filename\n"; 137 exit($PS_EXIT_CONFIG_ERROR); 138 } 139 } 140 ## try again after a moment? 141 ## system ("df"); 142 select(undef, undef, undef, 0.25); 143 } 144 144 } 145 145 … … 151 151 sub load_site 152 152 { 153 my $self = shift; # Configuration object153 my $self = shift; # Configuration object 154 154 155 155 my $i = 0; 156 156 157 157 unless (defined $self) { 158 carp "Programming error";159 exit($PS_EXIT_PROG_ERROR);158 carp "Programming error"; 159 exit($PS_EXIT_PROG_ERROR); 160 160 } 161 161 162 162 my $filename = metadataLookupStr($self->{_userConfig}, 'SITE'); # Site config file 163 163 unless (defined $filename) { 164 carp "Unable to find site configuration file\n";165 exit($PS_EXIT_CONFIG_ERROR);164 carp "Unable to find site configuration file\n"; 165 exit($PS_EXIT_CONFIG_ERROR); 166 166 } 167 167 … … 169 169 170 170 # Read the file 171 my $file; # File handle171 my $file; # File handle 172 172 unless (open $file, $realfile) { 173 carp "Unable to open site configuration file $realfile: $!";174 exit($PS_EXIT_CONFIG_ERROR);173 carp "Unable to open site configuration file $realfile: $!"; 174 exit($PS_EXIT_CONFIG_ERROR); 175 175 } 176 176 … … 180 180 181 181 unless (defined $self->{_siteConfig}) { 182 carp "Failure to parse the site configuration file $realfile";183 exit($PS_EXIT_CONFIG_ERROR);182 carp "Failure to parse the site configuration file $realfile"; 183 exit($PS_EXIT_CONFIG_ERROR); 184 184 } 185 185 … … 190 190 sub load_system 191 191 { 192 my $self = shift; # Configuration object192 my $self = shift; # Configuration object 193 193 194 194 unless (defined $self) { 195 carp "Programming error";196 exit($PS_EXIT_PROG_ERROR);195 carp "Programming error"; 196 exit($PS_EXIT_PROG_ERROR); 197 197 } 198 198 199 199 my $filename = metadataLookupStr($self->{_userConfig}, 'SYSTEM'); # System config file 200 200 unless (defined $filename) { 201 carp "Unable to find system configuration file\n";202 exit($PS_EXIT_CONFIG_ERROR);201 carp "Unable to find system configuration file\n"; 202 exit($PS_EXIT_CONFIG_ERROR); 203 203 } 204 204 … … 206 206 207 207 # Read the file 208 my $file; # File handle208 my $file; # File handle 209 209 unless (open $file, $realfile) { 210 carp "Unable to open system configuration file $realfile: $!";211 exit($PS_EXIT_CONFIG_ERROR);210 carp "Unable to open system configuration file $realfile: $!"; 211 exit($PS_EXIT_CONFIG_ERROR); 212 212 } 213 213 my @contents = <$file>; … … 216 216 217 217 unless (defined $self->{_systemConfig}) { 218 carp "Failure to define system configuration";219 exit($PS_EXIT_CONFIG_ERROR);218 carp "Failure to define system configuration"; 219 exit($PS_EXIT_CONFIG_ERROR); 220 220 } 221 221 … … 227 227 sub define_camera 228 228 { 229 my $self = shift; # Configuration object230 my $name = shift; # Camera name229 my $self = shift; # Configuration object 230 my $name = shift; # Camera name 231 231 232 232 unless (defined $self and defined $name) { 233 carp "Programming error";234 exit($PS_EXIT_PROG_ERROR);233 carp "Programming error"; 234 exit($PS_EXIT_PROG_ERROR); 235 235 } 236 236 … … 238 238 my $filename = metadataLookupStr($camera_list, $name); # Filename of camera configuration 239 239 unless (defined $filename) { 240 carp "Unable to find configuration file for camera $name\n";241 exit($PS_EXIT_CONFIG_ERROR);240 carp "Unable to find configuration file for camera $name\n"; 241 exit($PS_EXIT_CONFIG_ERROR); 242 242 } 243 243 … … 245 245 246 246 # Read the file 247 my $file; # File handle247 my $file; # File handle 248 248 unless (open $file, $realfile) { 249 carp "Unable to open camera configuration file $realfile: $!";250 exit($PS_EXIT_CONFIG_ERROR);249 carp "Unable to open camera configuration file $realfile: $!"; 250 exit($PS_EXIT_CONFIG_ERROR); 251 251 } 252 252 my @contents = <$file>; … … 256 256 257 257 unless (defined $self->{camera}) { 258 carp "Failure to define camera";259 exit($PS_EXIT_CONFIG_ERROR);258 carp "Failure to define camera"; 259 exit($PS_EXIT_CONFIG_ERROR); 260 260 } 261 261 … … 267 267 sub file_scheme 268 268 { 269 my $name = shift; # Filename for which to get the scheme269 my $name = shift; # Filename for which to get the scheme 270 270 my ($scheme) = $name =~ /^(path|neb|file):/; # The scheme, e.g., file://, path:// 271 271 # $scheme may be undef if the input doesn't contain one of the above recognised schemes … … 277 277 sub caturi 278 278 { 279 my $base = shift; # Base name (might be "foo /foo path://SOMETHING" or "neb://SOMETHING")280 my @segments = @_; # Path segments279 my $base = shift; # Base name (might be "foo /foo path://SOMETHING" or "neb://SOMETHING") 280 my @segments = @_; # Path segments 281 281 282 282 carp "base is not inited" if not defined $base; … … 291 291 # Remove leading and trailing slashes 292 292 foreach my $segment ( @segments ) { 293 $segment =~ s|^/*||;294 $segment =~ s|/*$||;293 $segment =~ s|^/*||; 294 $segment =~ s|/*$||; 295 295 } 296 296 … … 298 298 my $joined = join('/', @segments); 299 299 if (defined $scheme) { 300 $joined = lc($scheme) . "://" . $joined;300 $joined = lc($scheme) . "://" . $joined; 301 301 } else { 302 $joined = $root . $joined;302 $joined = $root . $joined; 303 303 } 304 304 … … 309 309 sub datapath 310 310 { 311 my $self = shift; # Configuration object312 my $name = shift; # datapath name311 my $self = shift; # Configuration object 312 my $name = shift; # datapath name 313 313 314 314 unless (defined $self and defined $name) { 315 carp "Programming error";316 exit($PS_EXIT_PROG_ERROR);315 carp "Programming error"; 316 exit($PS_EXIT_PROG_ERROR); 317 317 } 318 318 … … 320 320 my $pathname = metadataLookupStr($path_list, $name); # Path of interest 321 321 unless (defined $pathname) { 322 carp "Unable to find datapath $name\n" ;323 exit($PS_EXIT_CONFIG_ERROR);322 carp "Unable to find datapath $name\n" ; 323 exit($PS_EXIT_CONFIG_ERROR); 324 324 } 325 325 … … 330 330 sub _neb_start 331 331 { 332 my $self = shift; # Configuration object332 my $self = shift; # Configuration object 333 333 334 334 eval { 335 require Nebulous::Client;335 require Nebulous::Client; 336 336 }; 337 337 if ($@) { 338 carp "Can't find Nebulous::Client.";339 exit($PS_EXIT_PROG_ERROR);338 carp "Can't find Nebulous::Client."; 339 exit($PS_EXIT_PROG_ERROR); 340 340 } 341 341 … … 344 344 my $server = metadataLookupStr( $self->{_siteConfig}, 'NEB_SERVER' ); # Nebulous server 345 345 unless (defined $server) { 346 carp "Unable to find NEB_SERVER in camera configuration file.";347 exit($PS_EXIT_CONFIG_ERROR);346 carp "Unable to find NEB_SERVER in camera configuration file."; 347 exit($PS_EXIT_CONFIG_ERROR); 348 348 } 349 349 350 350 my $neb = Nebulous::Client->new( proxy => $server ); 351 351 unless (defined $neb) { 352 carp "Unable to find NEB_SERVER in camera configuration file.";353 exit($PS_EXIT_CONFIG_ERROR);352 carp "Unable to find NEB_SERVER in camera configuration file."; 353 exit($PS_EXIT_CONFIG_ERROR); 354 354 } 355 355 … … 362 362 sub file_resolve 363 363 { 364 my $self = shift; # Configuration object365 my $name = shift; # File name to check366 my $touch = shift; # if $name is in nebulous instantiate it364 my $self = shift; # Configuration object 365 my $name = shift; # File name to check 366 my $touch = shift; # if $name is in nebulous instantiate it 367 367 368 368 my $scheme = file_scheme($name); # The scheme, e.g., file://, path:// … … 372 372 373 373 if ($scheme eq 'neb') { 374 $name =~ s|^neb:/*||;375 $self->_neb_start();376 my $neb = $self->{nebulous}; # Nebulous handle374 $name =~ s|^neb:/*||; 375 $self->_neb_start(); 376 my $neb = $self->{nebulous}; # Nebulous handle 377 377 if ($touch) { 378 378 unless ($neb->stat( $name )) { … … 383 383 } 384 384 } 385 return $neb->find( $name );385 return $neb->find( $name ); 386 386 } 387 387 if ($scheme eq 'path' or $scheme eq 'file') { 388 # guaranteed to have a scheme (path:// or file://)389 return $self->convert_filename_absolute( $name );388 # guaranteed to have a scheme (path:// or file://) 389 return $self->convert_filename_absolute( $name ); 390 390 } 391 391 … … 396 396 sub file_create_open 397 397 { 398 my $self = shift; # Configuration object399 my $name = shift; # File name to check398 my $self = shift; # Configuration object 399 my $name = shift; # File name to check 400 400 401 401 $self->file_prepare( $name ); … … 403 403 my $scheme = file_scheme($name); # The scheme, e.g., file://, path:// 404 404 if (defined $scheme) { 405 $scheme = lc($scheme);406 if ($scheme eq 'neb') {407 $name =~ s|^neb:/*||;408 $self->_neb_start();409 return $self->{nebulous}->open_create( $name );410 }411 if ($scheme eq 'path' or $scheme eq 'file') {412 # guaranteed to have a scheme (path:// or file://)413 $name = $self->convert_filename_absolute( $name );414 }405 $scheme = lc($scheme); 406 if ($scheme eq 'neb') { 407 $name =~ s|^neb:/*||; 408 $self->_neb_start(); 409 return $self->{nebulous}->open_create( $name ); 410 } 411 if ($scheme eq 'path' or $scheme eq 'file') { 412 # guaranteed to have a scheme (path:// or file://) 413 $name = $self->convert_filename_absolute( $name ); 414 } 415 415 } 416 416 417 417 if (-f $name) { 418 carp "Unable to create file $name --- file exists.";419 exit($PS_EXIT_SYS_ERROR);418 carp "Unable to create file $name --- file exists."; 419 exit($PS_EXIT_SYS_ERROR); 420 420 } 421 421 422 422 my $fh; 423 423 unless (open $fh, '>', $name) { 424 carp "Unable to create file $name --- $!";425 exit($PS_EXIT_SYS_ERROR);424 carp "Unable to create file $name --- $!"; 425 exit($PS_EXIT_SYS_ERROR); 426 426 } 427 427 return $fh; … … 431 431 sub file_create_append 432 432 { 433 my $self = shift; # Configuration object434 my $name = shift; # File name to check433 my $self = shift; # Configuration object 434 my $name = shift; # File name to check 435 435 436 436 $self->file_prepare( $name ); … … 438 438 my $scheme = file_scheme($name); # The scheme, e.g., file://, path:// 439 439 if (defined $scheme) { 440 $scheme = lc($scheme);441 if ($scheme eq 'neb') {442 $name =~ s|^neb:/*||;443 $self->_neb_start();444 return $self->{nebulous}->open_create( $name );445 }446 if ($scheme eq 'path' or $scheme eq 'file') {447 # guaranteed to have a scheme (path:// or file://)448 $name = $self->convert_filename_absolute( $name );449 }440 $scheme = lc($scheme); 441 if ($scheme eq 'neb') { 442 $name =~ s|^neb:/*||; 443 $self->_neb_start(); 444 return $self->{nebulous}->open_create( $name ); 445 } 446 if ($scheme eq 'path' or $scheme eq 'file') { 447 # guaranteed to have a scheme (path:// or file://) 448 $name = $self->convert_filename_absolute( $name ); 449 } 450 450 } 451 451 452 452 my $fh; 453 453 unless (open $fh, '>>', $name) { 454 carp "Unable to create file $name --- $!";455 exit($PS_EXIT_SYS_ERROR);454 carp "Unable to create file $name --- $!"; 455 exit($PS_EXIT_SYS_ERROR); 456 456 } 457 457 return $fh; … … 461 461 sub file_create 462 462 { 463 my $self = shift; # Configuration object464 my $name = shift; # File name to check463 my $self = shift; # Configuration object 464 my $name = shift; # File name to check 465 465 466 466 $self->file_prepare( $name ); … … 468 468 my $scheme = file_scheme($name); # The scheme, e.g., file://, path:// 469 469 if (defined $scheme and lc($scheme) eq 'neb') { 470 $name =~ s|^neb:/*||;471 $self->_neb_start();472 $name = $self->{nebulous}->create( $name );470 $name =~ s|^neb:/*||; 471 $self->_neb_start(); 472 $name = $self->{nebulous}->create( $name ); 473 473 } 474 474 … … 479 479 sub file_exists 480 480 { 481 my $self = shift; # Configuration object482 my $name = shift; # File name to check481 my $self = shift; # Configuration object 482 my $name = shift; # File name to check 483 483 484 484 my $scheme = file_scheme($name); # The scheme, e.g., file://, path:// 485 485 if (defined $scheme and lc($scheme) eq 'neb') { 486 $name =~ s|^neb:/*||;487 $self->_neb_start();488 return (defined $self->{nebulous}->find_instances( $name ) ? 1 : 0);486 $name =~ s|^neb:/*||; 487 $self->_neb_start(); 488 return (defined $self->{nebulous}->find_instances( $name ) ? 1 : 0); 489 489 } 490 490 … … 495 495 sub file_copy 496 496 { 497 my $self = shift; # Configuration object498 my $source = shift; # Name of source file499 my $target = shift; # Name of target file497 my $self = shift; # Configuration object 498 my $source = shift; # Name of source file 499 my $target = shift; # Name of target file 500 500 501 501 $self->file_prepare( $target ); … … 503 503 my $scheme = file_scheme($target); # The scheme, e.g., file://, path:// 504 504 if (defined $scheme and lc($scheme) eq 'neb') { 505 $target =~ s|^neb:/*||;506 $self->_neb_start();507 $target = $self->{nebulous}->create( $target );505 $target =~ s|^neb:/*||; 506 $self->_neb_start(); 507 $target = $self->{nebulous}->create( $target ); 508 508 } 509 509 $target = $self->file_resolve( $target ); … … 511 511 512 512 system("cp $source $target") == 0 or (carp "Can't copy file $source to $target." and 513 exit($PS_EXIT_DATA_ERROR));513 exit($PS_EXIT_DATA_ERROR)); 514 514 return 1; 515 515 } … … 518 518 sub _strip_filename 519 519 { 520 my $name = shift; # File name of interest520 my $name = shift; # File name of interest 521 521 $name =~ s|/[\w.-]*?$||; 522 522 return $name; … … 527 527 sub file_prepare 528 528 { 529 my $self = shift; # Configuration object530 my $name = shift; # File name for which to prepare531 my $workdir = shift; # Working directory532 my $template = shift; # Template filename from which to get working directory if529 my $self = shift; # Configuration object 530 my $name = shift; # File name for which to prepare 531 my $workdir = shift; # Working directory 532 my $template = shift; # Template filename from which to get working directory if 533 533 534 534 if (defined $workdir) { 535 $name = caturi( $workdir, $name );535 $name = caturi( $workdir, $name ); 536 536 } elsif (defined $template) { 537 # Take directory from template and apply to name538 my $dir = _strip_filename( $template );539 $name = caturi( $dir, $name );537 # Take directory from template and apply to name 538 my $dir = _strip_filename( $template ); 539 $name = caturi( $dir, $name ); 540 540 } 541 541 … … 549 549 my ( $vol, $dirs, $file ) = File::Spec->splitpath( $resolved ); 550 550 unless (-d $dirs) { 551 system("mkdir -p $dirs") == 0 or (carp "Can't create directory $dirs" and exit($PS_EXIT_DATA_ERROR));551 system("mkdir -p $dirs") == 0 or (carp "Can't create directory $dirs" and exit($PS_EXIT_DATA_ERROR)); 552 552 } 553 553 … … 559 559 sub outroot_prepare 560 560 { 561 my $self = shift; # Configuration object562 my $outroot = shift; # Working directory561 my $self = shift; # Configuration object 562 my $outroot = shift; # Working directory 563 563 564 564 # outroot is a directory + fragement of a filename … … 573 573 my ( $vol, $dirs, $file ) = File::Spec->splitpath( $resolved ); 574 574 unless (-d $dirs) { 575 system("mkdir -p $dirs") == 0 or (carp "Can't create directory $dirs" and exit($PS_EXIT_DATA_ERROR));575 system("mkdir -p $dirs") == 0 or (carp "Can't create directory $dirs" and exit($PS_EXIT_DATA_ERROR)); 576 576 } 577 577 … … 583 583 sub convert_filename_absolute 584 584 { 585 my $self = shift; # Configuration object586 my $name = shift; # raw name585 my $self = shift; # Configuration object 586 my $name = shift; # raw name 587 587 588 588 unless (defined $self and defined $name) { 589 carp "Programming error";590 exit($PS_EXIT_PROG_ERROR);589 carp "Programming error"; 590 exit($PS_EXIT_PROG_ERROR); 591 591 } 592 592 … … 596 596 ## if this is already an absolute path (/PATH/file), just return the path 597 597 unless (defined $scheme) { 598 if ($name =~ m|^/|) { return $name; }599 # without a leading slash, this is an error600 carp "Relative file name provided: relative paths are not permitted.";601 exit($PS_EXIT_SYS_ERROR);598 if ($name =~ m|^/|) { return $name; } 599 # without a leading slash, this is an error 600 carp "Relative file name provided: relative paths are not permitted."; 601 exit($PS_EXIT_SYS_ERROR); 602 602 } 603 603 … … 605 605 606 606 if (lc($scheme) eq 'file') { 607 # the above strips of the leading slash; replace it for file://608 $name = '/' . $name;609 return $name;607 # the above strips of the leading slash; replace it for file:// 608 $name = '/' . $name; 609 return $name; 610 610 } 611 611 612 612 if (lc($scheme) eq 'path') { 613 my @dirs = split('/', $name);614 my $pathName = shift @dirs;615 my $path = $self->datapath( $pathName );616 $path =~ s|/*$||;617 return File::Spec->catfile( $path, @dirs );613 my @dirs = split('/', $name); 614 my $pathName = shift @dirs; 615 my $path = $self->datapath( $pathName ); 616 $path =~ s|/*$||; 617 return File::Spec->catfile( $path, @dirs ); 618 618 } 619 619 … … 629 629 sub convert_filename_relative 630 630 { 631 my $self = shift; # Configuration object632 my $name = shift; # raw name631 my $self = shift; # Configuration object 632 my $name = shift; # raw name 633 633 634 634 unless (defined $self and defined $name) { 635 carp "Programming error";636 exit($PS_EXIT_PROG_ERROR);635 carp "Programming error"; 636 exit($PS_EXIT_PROG_ERROR); 637 637 } 638 638 … … 640 640 my $scheme = file_scheme($name); # The scheme, e.g., file, path 641 641 if (defined $scheme) { 642 $scheme = lc($scheme);643 if ($scheme eq 'path' or $scheme eq 'file') {644 # We may as well search for a 'better' path645 # guaranteed to have a scheme (path:// or file://)646 $name = $self->convert_filename_absolute( $name );647 } elsif ($scheme eq 'neb') {648 # No chance of changing anything --- move along649 return $name;650 }642 $scheme = lc($scheme); 643 if ($scheme eq 'path' or $scheme eq 'file') { 644 # We may as well search for a 'better' path 645 # guaranteed to have a scheme (path:// or file://) 646 $name = $self->convert_filename_absolute( $name ); 647 } elsif ($scheme eq 'neb') { 648 # No chance of changing anything --- move along 649 return $name; 650 } 651 651 } 652 652 … … 667 667 next if scalar @path_dirs > scalar @dirs; 668 668 for (my $i = 0; $i < scalar @path_dirs; $i++) { 669 next CFR_PATH_CHECK if $path_dirs[$i] ne $dirs[$i];669 next CFR_PATH_CHECK if $path_dirs[$i] ne $dirs[$i]; 670 670 } 671 671 # It is suitable; see if it is 'best' (minimizes the number of directories) 672 672 my $score = scalar @path_dirs; 673 673 if (not defined $best_score or $score > $best_score) { 674 $best_path = $path;675 $best_score = $score;676 $best_name = $path_name;674 $best_path = $path; 675 $best_score = $score; 676 $best_name = $path_name; 677 677 } 678 678 } … … 681 681 $name =~ s|/$||; 682 682 if (defined $best_score) { 683 $best_path =~ s|^/||;684 $best_path =~ s|/$||;685 $name =~ s|^$best_path|$best_name|;686 return 'path://' . $name;683 $best_path =~ s|^/||; 684 $best_path =~ s|/$||; 685 $name =~ s|^$best_path|$best_name|; 686 return 'path://' . $name; 687 687 } 688 688 return 'file://' . $name; … … 692 692 sub rejection 693 693 { 694 my $self = shift; # Configuration object695 my $name = shift; # Name of limit696 my $type = lc(shift); # Type of frame697 my $filter = shift; # Filter name, for extra qualification; optional694 my $self = shift; # Configuration object 695 my $name = shift; # Name of limit 696 my $type = lc(shift); # Type of frame 697 my $filter = shift; # Filter name, for extra qualification; optional 698 698 699 699 unless (defined $self and defined $name and defined $type) { 700 carp "Programming error";701 exit($PS_EXIT_PROG_ERROR);700 carp "Programming error"; 701 exit($PS_EXIT_PROG_ERROR); 702 702 } 703 703 704 704 unless (defined $self->{rejection}) { 705 my $camera = $self->{cameraName}; # Camera name706 unless (defined $camera) {707 carp "Camera has not yet been defined.\n";708 return undef;709 }710 711 # rejections are saved as a recipe: REJECTIONS712 my @rejContents = `ppConfigDump -dump-recipe REJECTIONS -camera $camera -`;713 714 # load from resulting psMetadataConfig715 $self->{rejection} = $parser->parse( join '', @rejContents); # The rejection metadata716 unless (defined $self->{rejection}) {717 carp "Unable to parse REJECTION recipe for $camera.";718 exit($PS_EXIT_CONFIG_ERROR);719 }705 my $camera = $self->{cameraName}; # Camera name 706 unless (defined $camera) { 707 carp "Camera has not yet been defined.\n"; 708 return undef; 709 } 710 711 # rejections are saved as a recipe: REJECTIONS 712 my @rejContents = `ppConfigDump -dump-recipe REJECTIONS -camera $camera -`; 713 714 # load from resulting psMetadataConfig 715 $self->{rejection} = $parser->parse( join '', @rejContents); # The rejection metadata 716 unless (defined $self->{rejection}) { 717 carp "Unable to parse REJECTION recipe for $camera."; 718 exit($PS_EXIT_CONFIG_ERROR); 719 } 720 720 } 721 721 … … 725 725 TYPES: foreach my $item (@$rejection) { 726 726 if (lc($item->{name}) eq $type) { 727 unless ($item->{class} eq "metadata") {728 carp "$name within REJECTIONS is not of type METADATA";729 exit($PS_EXIT_PROG_ERROR);730 }731 my $limits = $item->{value}; # List of rejection limits732 733 # Check the FILTER first734 foreach my $limit (@$limits) {735 if ($limit->{name} eq 'FILTER') {736 if ($limit->{value} eq '*' or737 (defined $filter and738 $limit->{value} eq $filter)) {739 last;740 }741 next TYPES; # Doesn't match --- look at the next one742 }743 }744 745 foreach my $limit (@$limits) {746 return $limit->{value} if $limit->{name} eq $name;747 }748 carp "Unable to find limit $name in REJECTIONS list for $type.\n";749 return undef;727 unless ($item->{class} eq "metadata") { 728 carp "$name within REJECTIONS is not of type METADATA"; 729 exit($PS_EXIT_PROG_ERROR); 730 } 731 my $limits = $item->{value}; # List of rejection limits 732 733 # Check the FILTER first 734 foreach my $limit (@$limits) { 735 if ($limit->{name} eq 'FILTER') { 736 if ($limit->{value} eq '*' or 737 (defined $filter and 738 $limit->{value} eq $filter)) { 739 last; 740 } 741 next TYPES; # Doesn't match --- look at the next one 742 } 743 } 744 745 foreach my $limit (@$limits) { 746 return $limit->{value} if $limit->{name} eq $name; 747 } 748 carp "Unable to find limit $name in REJECTIONS list for $type.\n"; 749 return undef; 750 750 } 751 751 } 752 752 753 753 if (not defined $filter) { 754 carp "Unable to find type $type with no FILTER in REJECTIONS list.\n";754 carp "Unable to find type $type with no FILTER in REJECTIONS list.\n"; 755 755 } else { 756 carp "Unable to find type $type with FILTER $filter in REJECTIONS list.\n";756 carp "Unable to find type $type with FILTER $filter in REJECTIONS list.\n"; 757 757 } 758 758 return undef; … … 762 762 sub filename 763 763 { 764 my $self = shift; # Configuration object765 my $name = shift; # Name of the file766 my $output = shift; # For replacing {OUTPUT}767 my $component = shift; # For replacing {CHIP.NAME} and {CELL.NAME}764 my $self = shift; # Configuration object 765 my $name = shift; # Name of the file 766 my $output = shift; # For replacing {OUTPUT} 767 my $component = shift; # For replacing {CHIP.NAME} and {CELL.NAME} 768 768 769 769 unless (defined $self and defined $name and defined $output) { 770 carp "Programming error: required inputs left undefined";771 exit($PS_EXIT_PROG_ERROR);772 } 773 774 my $filerules; # File rules770 carp "Programming error: required inputs left undefined"; 771 exit($PS_EXIT_PROG_ERROR); 772 } 773 774 my $filerules; # File rules 775 775 if (defined $self->{filerules}) { 776 $filerules = $self->{filerules};776 $filerules = $self->{filerules}; 777 777 } else { 778 # Get the file rules from the camera configuration779 780 my $camera = $self->{camera}; # Camera configuration781 unless (defined $camera) {782 carp "Camera has not yet been defined.\n";783 return undef;784 }785 786 $filerules = metadataLookup($camera, 'FILERULES');# File rules787 unless (defined $filerules) {788 carp "Can't find FILERULES list in camera configuration.\n";789 return undef;790 }791 792 if ($filerules->{class} eq "scalar" and $filerules->{type} eq "STR") {793 # Allow indirection to a file794 my $filename = $self->_find_config($filerules->{value}); # Resolved filename795 # Read the file796 my $file;# File handle797 unless (open $file, $filename) {798 carp "Unable to open filerules file $filename: $!";799 exit($PS_EXIT_CONFIG_ERROR);800 }801 my @contents = <$file>;802 close $file;803 $filerules = $parser->parse( join '', @contents);804 } elsif ($filerules->{class} eq "metadata") {805 $filerules = $filerules->{value};806 } else {807 carp "Can't interpret FILERULES in camera configuration.\n";808 return undef;809 }810 $self->{filerules} = $filerules;778 # Get the file rules from the camera configuration 779 780 my $camera = $self->{camera}; # Camera configuration 781 unless (defined $camera) { 782 carp "Camera has not yet been defined.\n"; 783 return undef; 784 } 785 786 $filerules = metadataLookup($camera, 'FILERULES'); # File rules 787 unless (defined $filerules) { 788 carp "Can't find FILERULES list in camera configuration.\n"; 789 return undef; 790 } 791 792 if ($filerules->{class} eq "scalar" and $filerules->{type} eq "STR") { 793 # Allow indirection to a file 794 my $filename = $self->_find_config($filerules->{value}); # Resolved filename 795 # Read the file 796 my $file; # File handle 797 unless (open $file, $filename) { 798 carp "Unable to open filerules file $filename: $!"; 799 exit($PS_EXIT_CONFIG_ERROR); 800 } 801 my @contents = <$file>; 802 close $file; 803 $filerules = $parser->parse( join '', @contents); 804 } elsif ($filerules->{class} eq "metadata") { 805 $filerules = $filerules->{value}; 806 } else { 807 carp "Can't interpret FILERULES in camera configuration.\n"; 808 return undef; 809 } 810 $self->{filerules} = $filerules; 811 811 } 812 812 813 813 my $file = _mdLookupMDwithRedirect($filerules, $name); # The file of interest 814 814 unless (defined $file) { 815 carp "Can't find $name within FILERULES in camera configuration.\n";816 return undef;815 carp "Can't find $name within FILERULES in camera configuration.\n"; 816 return undef; 817 817 } 818 818 819 819 my $filename = metadataLookupStr($file, "FILENAME.RULE"); # File name 820 820 unless (defined $filename) { 821 carp "Can't find FILENAME.RULE for $name within FILERULES in camera configuration.\n";822 return undef;821 carp "Can't find FILENAME.RULE for $name within FILERULES in camera configuration.\n"; 822 return undef; 823 823 } 824 824 825 825 $filename =~ s/\{OUTPUT\}/$output/; 826 826 if ($filename =~ /\{CHIP\.NAME\}/) { 827 unless (defined $component) {828 carp "Programming error";829 exit($PS_EXIT_PROG_ERROR);830 }831 $filename =~ s/\{CHIP\.NAME\}/$component/;832 $filename =~ s/\{CELL\.NAME\}/$component/;827 unless (defined $component) { 828 carp "Programming error"; 829 exit($PS_EXIT_PROG_ERROR); 830 } 831 $filename =~ s/\{CHIP\.NAME\}/$component/; 832 $filename =~ s/\{CELL\.NAME\}/$component/; 833 833 } 834 834 … … 839 839 sub extname_rule 840 840 { 841 my $self = shift; # Configuration object842 my $name = shift; # Name of the EXTNAME to build843 my $component = shift; # For replacing {CHIP.NAME}841 my $self = shift; # Configuration object 842 my $name = shift; # Name of the EXTNAME to build 843 my $component = shift; # For replacing {CHIP.NAME} 844 844 845 845 unless (defined $self and defined $name) { 846 carp "Programming error";847 exit($PS_EXIT_PROG_ERROR);846 carp "Programming error"; 847 exit($PS_EXIT_PROG_ERROR); 848 848 } 849 849 850 850 my $camera = $self->{camera}; # Camera configuration 851 851 unless (defined $camera) { 852 carp "Camera has not yet been defined.\n";853 return undef;854 } 855 856 my $extname_rules = metadataLookupMD($camera, 'EXTNAME.RULES'); # File rules852 carp "Camera has not yet been defined.\n"; 853 return undef; 854 } 855 856 my $extname_rules = metadataLookupMD($camera, 'EXTNAME.RULES'); # File rules 857 857 unless (defined $extname_rules) { 858 carp "Can't find EXTNAME.RULES in camera configuration.\n";859 return undef;858 carp "Can't find EXTNAME.RULES in camera configuration.\n"; 859 return undef; 860 860 } 861 861 862 862 my $extname = metadataLookupStr($extname_rules, $name); # File name 863 863 unless (defined $extname) { 864 carp "Can't find $name within EXTNAME.RULES in camera configuration.\n";865 return undef;864 carp "Can't find $name within EXTNAME.RULES in camera configuration.\n"; 865 return undef; 866 866 } 867 867 868 868 if ($extname =~ /\{CHIP\.NAME\}/) { 869 unless (defined $component) {870 carp "Programming error";871 exit($PS_EXIT_PROG_ERROR);872 }873 $extname =~ s/\{CHIP\.NAME\}/$component/;869 unless (defined $component) { 870 carp "Programming error"; 871 exit($PS_EXIT_PROG_ERROR); 872 } 873 $extname =~ s/\{CHIP\.NAME\}/$component/; 874 874 } 875 875 … … 880 880 sub tessellation_catdir 881 881 { 882 my $self = shift; # Configuration object883 my $tess_id = shift; # Tessellation identifier882 my $self = shift; # Configuration object 883 my $tess_id = shift; # Tessellation identifier 884 884 885 885 unless (defined $self and defined $self->{_siteConfig} and defined $tess_id) { 886 carp "Programming error";887 exit($PS_EXIT_PROG_ERROR);886 carp "Programming error"; 887 exit($PS_EXIT_PROG_ERROR); 888 888 } 889 889 890 890 my $tessellations = metadataLookupMD($self->{_siteConfig}, 'TESSELLATIONS'); # Tessellations 891 891 unless (defined $tessellations) { 892 carp "Can't find TESSELLATIONS in site configuration.\n";893 exit($PS_EXIT_CONFIG_ERROR);892 carp "Can't find TESSELLATIONS in site configuration.\n"; 893 exit($PS_EXIT_CONFIG_ERROR); 894 894 } 895 895 896 896 my $catdir = metadataLookupStr($tessellations, $tess_id); 897 897 unless (defined $catdir) { 898 print "Can't find tessellation identifier $tess_id in TESSELLATIONS in site configuration, assuming it is a filename.\n";899 return $tess_id;898 print "Can't find tessellation identifier $tess_id in TESSELLATIONS in site configuration, assuming it is a filename.\n"; 899 return $tess_id; 900 900 } 901 901 … … 903 903 my $scheme = file_scheme($catdir); # The scheme, e.g., file, path, neb 904 904 if (defined $scheme and lc($scheme) eq 'neb') { 905 carp "Tessellation $tess_id refers to a Nebulous path: $catdir\n";906 exit($PS_EXIT_CONFIG_ERROR);905 carp "Tessellation $tess_id refers to a Nebulous path: $catdir\n"; 906 exit($PS_EXIT_CONFIG_ERROR); 907 907 } 908 908 … … 914 914 sub dvo_catdir 915 915 { 916 my $self = shift; # Configuration object917 my $dvodb = shift; # DVO db identifier916 my $self = shift; # Configuration object 917 my $dvodb = shift; # DVO db identifier 918 918 919 919 unless (defined $self and defined $self->{_siteConfig} and defined $dvodb) { 920 carp "Programming error";921 exit($PS_EXIT_PROG_ERROR);920 carp "Programming error"; 921 exit($PS_EXIT_PROG_ERROR); 922 922 } 923 923 924 924 my $catdirs = metadataLookupMD($self->{_siteConfig}, 'DVO.CATDIRS'); # Tessellations 925 925 unless (defined $catdirs) { 926 carp "Can't find DVO.CATDIRS in site configuration.\n";927 exit($PS_EXIT_CONFIG_ERROR);926 carp "Can't find DVO.CATDIRS in site configuration.\n"; 927 exit($PS_EXIT_CONFIG_ERROR); 928 928 } 929 929 930 930 my $catdir = metadataLookupStr($catdirs, $dvodb); 931 931 unless (defined $catdir) { 932 print "Can't find dvodb identifier $dvodb in DVO.CATDIR in site configuration, assuming filename\n";933 return $dvodb;932 print "Can't find dvodb identifier $dvodb in DVO.CATDIR in site configuration, assuming filename\n"; 933 return $dvodb; 934 934 } 935 935 … … 937 937 my $scheme = file_scheme($catdir); # The scheme, e.g., file, path, neb 938 938 if (defined $scheme and lc($scheme) eq 'neb') { 939 carp "DVO catdir $dvodb refers to a Nebulous path: $catdir\n";940 exit($PS_EXIT_CONFIG_ERROR);939 carp "DVO catdir $dvodb refers to a Nebulous path: $catdir\n"; 940 exit($PS_EXIT_CONFIG_ERROR); 941 941 } 942 942 … … 947 947 sub psastro_catdir 948 948 { 949 my $self = shift; # Configuration object950 my $dvodb = shift; # DVO db identifier949 my $self = shift; # Configuration object 950 my $dvodb = shift; # DVO db identifier 951 951 952 952 unless (defined $self and defined $self->{_siteConfig} and defined $dvodb) { 953 carp "Programming error";954 exit($PS_EXIT_PROG_ERROR);953 carp "Programming error"; 954 exit($PS_EXIT_PROG_ERROR); 955 955 } 956 956 957 957 my $catdirs = metadataLookupMD($self->{_siteConfig}, 'PSASTRO.CATDIRS'); # Tessellations 958 958 unless (defined $catdirs) { 959 carp "Can't find PSASTRO.CATDIRS in site configuration.\n";960 exit($PS_EXIT_CONFIG_ERROR);959 carp "Can't find PSASTRO.CATDIRS in site configuration.\n"; 960 exit($PS_EXIT_CONFIG_ERROR); 961 961 } 962 962 963 963 my $catdir = metadataLookupStr($catdirs, $dvodb); 964 964 unless (defined $catdir) { 965 print "Can't find dvodb identifier $dvodb in PSASTRO.CATDIR in site configuration, assuming filename.\n";966 return $dvodb;965 print "Can't find dvodb identifier $dvodb in PSASTRO.CATDIR in site configuration, assuming filename.\n"; 966 return $dvodb; 967 967 } 968 968 … … 970 970 my $scheme = file_scheme($catdir); # The scheme, e.g., file, path, neb 971 971 if (defined $scheme and lc($scheme) eq 'neb') { 972 carp "PSASTRO catdir $dvodb refers to a Nebulous path: $catdir\n";973 exit($PS_EXIT_CONFIG_ERROR);972 carp "PSASTRO catdir $dvodb refers to a Nebulous path: $catdir\n"; 973 exit($PS_EXIT_CONFIG_ERROR); 974 974 } 975 975 … … 980 980 sub dvo_cameradir 981 981 { 982 my $self = shift; # Configuration object982 my $self = shift; # Configuration object 983 983 984 984 unless (defined $self) { 985 carp "Programming error";986 exit($PS_EXIT_PROG_ERROR);985 carp "Programming error"; 986 exit($PS_EXIT_PROG_ERROR); 987 987 } 988 988 989 989 my $camera = $self->{camera}; # Camera configuration 990 990 unless (defined $camera) { 991 carp "Camera has not yet been defined.\n";992 return undef;991 carp "Camera has not yet been defined.\n"; 992 return undef; 993 993 } 994 994 995 995 my $dir = metadataLookupStr($camera, "DVO.CAMERADIR"); # Directory of interest 996 996 unless (defined $dir) { 997 carp "Can't find DVO.CAMERADIR in camera configuration.\n";998 return undef;997 carp "Can't find DVO.CAMERADIR in camera configuration.\n"; 998 return undef; 999 999 } 1000 1000 … … 1006 1006 sub reduction 1007 1007 { 1008 my $self = shift; # Configuration object1009 my $reduction = shift; # Reduction class1010 my $name = shift; # Symbolic name of recipe1008 my $self = shift; # Configuration object 1009 my $reduction = shift; # Reduction class 1010 my $name = shift; # Symbolic name of recipe 1011 1011 1012 1012 unless (defined $self and defined $reduction and defined $name) { 1013 carp "Programming error --- inputs undefined";1014 exit($PS_EXIT_PROG_ERROR);1013 carp "Programming error --- inputs undefined"; 1014 exit($PS_EXIT_PROG_ERROR); 1015 1015 } 1016 1016 1017 1017 my $reductionClasses; 1018 1018 if (defined $self->{reductionClasses}) { 1019 $reductionClasses = $self->{reductionClasses};1019 $reductionClasses = $self->{reductionClasses}; 1020 1020 } else { 1021 # load and save the reductionClasses table1022 1023 # need to have a valid camear1024 my $camera = $self->{camera}; # Camera configuration1025 unless (defined $camera) {1026 carp "Camera has not yet been defined.\n";1027 return undef;1028 }1029 1030 $reductionClasses = metadataLookup($camera, 'REDUCTION');# File rules1031 1032 unless (defined $reductionClasses) {1033 carp "Can't find REDUCTION list in camera configuration.\n";1034 return undef;1035 }1036 1037 if ($reductionClasses->{class} eq "scalar" and $reductionClasses->{type} eq "STR") {1038 # Allow indirection to a file1039 my $filename = $self->_find_config($reductionClasses->{value}); # Resolved filename1040 # Read the file1041 my $file;# File handle1042 unless (open $file, $filename) {1043 carp "Unable to open reductionClasses file $filename: $!";1044 exit($PS_EXIT_CONFIG_ERROR);1045 }1046 my @contents = <$file>;1047 close $file;1048 $reductionClasses = $parser->parse( join '', @contents);1049 } elsif ($reductionClasses->{class} eq "metadata") {1050 $reductionClasses = $reductionClasses->{value};1051 } else {1052 carp "Can't interpret REDUCTIONS in camera configuration.\n";1053 return undef;1054 }1055 $self->{reductionClasses} = $reductionClasses;1021 # load and save the reductionClasses table 1022 1023 # need to have a valid camear 1024 my $camera = $self->{camera}; # Camera configuration 1025 unless (defined $camera) { 1026 carp "Camera has not yet been defined.\n"; 1027 return undef; 1028 } 1029 1030 $reductionClasses = metadataLookup($camera, 'REDUCTION'); # File rules 1031 1032 unless (defined $reductionClasses) { 1033 carp "Can't find REDUCTION list in camera configuration.\n"; 1034 return undef; 1035 } 1036 1037 if ($reductionClasses->{class} eq "scalar" and $reductionClasses->{type} eq "STR") { 1038 # Allow indirection to a file 1039 my $filename = $self->_find_config($reductionClasses->{value}); # Resolved filename 1040 # Read the file 1041 my $file; # File handle 1042 unless (open $file, $filename) { 1043 carp "Unable to open reductionClasses file $filename: $!"; 1044 exit($PS_EXIT_CONFIG_ERROR); 1045 } 1046 my @contents = <$file>; 1047 close $file; 1048 $reductionClasses = $parser->parse( join '', @contents); 1049 } elsif ($reductionClasses->{class} eq "metadata") { 1050 $reductionClasses = $reductionClasses->{value}; 1051 } else { 1052 carp "Can't interpret REDUCTIONS in camera configuration.\n"; 1053 return undef; 1054 } 1055 $self->{reductionClasses} = $reductionClasses; 1056 1056 } 1057 1057 1058 1058 my $class = metadataLookupMD($reductionClasses, $reduction) or # Class of interest 1059 (carp "Can't find $reduction in REDUCTION in camera configuration.\n" and1060 exit($PS_EXIT_CONFIG_ERROR));1059 (carp "Can't find $reduction in REDUCTION in camera configuration.\n" and 1060 exit($PS_EXIT_CONFIG_ERROR)); 1061 1061 1062 1062 my $actual = metadataLookupStr($class, $name) or # The actual recipe name of interest 1063 (carp "Can't find $name in $class in REDUCTION in camera configuration.\n" and1064 exit($PS_EXIT_CONFIG_ERROR));1063 (carp "Can't find $name in $class in REDUCTION in camera configuration.\n" and 1064 exit($PS_EXIT_CONFIG_ERROR)); 1065 1065 1066 1066 return $actual; … … 1069 1069 sub skycell_file 1070 1070 { 1071 my $self = shift; # Configuration object1072 my $tess_id = shift; # Tessellation identifier1073 my $skycell_id = shift; # Skycell identifier1074 my $outname = shift; # Output name1075 my $verbose = shift; # Verbose?1071 my $self = shift; # Configuration object 1072 my $tess_id = shift; # Tessellation identifier 1073 my $skycell_id = shift; # Skycell identifier 1074 my $outname = shift; # Output name 1075 my $verbose = shift; # Verbose? 1076 1076 1077 1077 unless (defined $self and defined $tess_id and defined $skycell_id and defined $outname) { 1078 carp "Input parameters not defined";1079 return 0;1078 carp "Input parameters not defined"; 1079 return 0; 1080 1080 } 1081 1081 … … 1084 1084 my $tess_dir = $self->tessellation_catdir( $tess_id ); # Tessellation catdir for DVO 1085 1085 unless (defined $tess_dir) { 1086 carp "Can't get list of tessellations.";1087 return 0;1086 carp "Can't get list of tessellations."; 1087 return 0; 1088 1088 } 1089 1089 $tess_dir = $self->convert_filename_absolute( $tess_dir ); 1090 1090 1091 1091 unless ($self->file_exists( $outname )) { 1092 my $outnameResolved = $self->file_create( $outname ); # Resolved filename, for Nebulous1093 my $command = "$dvoImageExtract -D CATDIR $tess_dir $skycell_id -o $outnameResolved";1094 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =1095 run(command => $command, verbose => $verbose);1096 die "Unable to perform dvoImageExtract for $tess_id $skycell_id\n" unless ($success and $self->file_exists( $outname ));1092 my $outnameResolved = $self->file_create( $outname ); # Resolved filename, for Nebulous 1093 my $command = "$dvoImageExtract -D CATDIR $tess_dir $skycell_id -o $outnameResolved"; 1094 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 1095 run(command => $command, verbose => $verbose); 1096 die "Unable to perform dvoImageExtract for $tess_id $skycell_id\n" unless ($success and $self->file_exists( $outname )); 1097 1097 } 1098 1098 … … 1103 1103 sub _interpolate_env 1104 1104 { 1105 my $dir = shift; # Directory of interest1105 my $dir = shift; # Directory of interest 1106 1106 1107 1107 return undef unless defined $dir; 1108 1108 1109 1109 while ($dir =~ /\$\{?(\w*)[\}\/:]?/) { 1110 my $name = $1;# Environment variable name1111 my $value = $ENV{$name}; # Environment variable value1112 unless (defined $value) {1113 carp "Unable to find environment variable $name";1114 exit($PS_EXIT_SYS_ERROR);1115 }1116 $dir =~ s/\$\{?$name\}?/$value\//;1110 my $name = $1; # Environment variable name 1111 my $value = $ENV{$name}; # Environment variable value 1112 unless (defined $value) { 1113 carp "Unable to find environment variable $name"; 1114 exit($PS_EXIT_SYS_ERROR); 1115 } 1116 $dir =~ s/\$\{?$name\}?/$value\//; 1117 1117 } 1118 1118 return $dir; … … 1121 1121 sub metadataLookup 1122 1122 { 1123 my $mdc = shift; # Metadata config to look up1124 my $name = shift; # Name of item to look up1123 my $mdc = shift; # Metadata config to look up 1124 my $name = shift; # Name of item to look up 1125 1125 1126 1126 unless (defined $mdc and defined $name) { 1127 carp "Programming error";1128 exit($PS_EXIT_PROG_ERROR);1127 carp "Programming error"; 1128 exit($PS_EXIT_PROG_ERROR); 1129 1129 } 1130 1130 1131 1131 # Iterate through the array of hashes 1132 1132 foreach my $item (@$mdc) { 1133 if ($item->{name} eq $name) {1134 return $item;1135 }1133 if ($item->{name} eq $name) { 1134 return $item; 1135 } 1136 1136 } 1137 1137 … … 1146 1146 my $item = metadataLookup(@_); 1147 1147 return undef if not defined $item; 1148 my $name = shift; # Name of item1148 my $name = shift; # Name of item 1149 1149 carp "$name within metadata is not of type STR.\n" unless $item->{type} eq "STR"; 1150 1150 return $item->{value}; … … 1156 1156 my $item = metadataLookup(@_); 1157 1157 return undef if not defined $item; 1158 my $name = shift; # Name of item1158 my $name = shift; # Name of item 1159 1159 carp "$name within metadata is not of type METADATA.\n" unless $item->{class} eq "metadata"; 1160 1160 return $item->{value}; … … 1166 1166 my $item = metadataLookup(@_); 1167 1167 return undef if not defined $item; 1168 my $name = shift; # Name of item1168 my $name = shift; # Name of item 1169 1169 carp "$name within metadata is not of type BOOL.\n" unless $item->{type} eq "BOOL"; 1170 1170 return $item->{value}; … … 1174 1174 sub _mdLookupMDwithRedirect 1175 1175 { 1176 my $mdc = shift; # Metadata config to look up1177 my $name = shift; # Name of item to look ip1176 my $mdc = shift; # Metadata config to look up 1177 my $name = shift; # Name of item to look ip 1178 1178 1179 1179 unless (defined $mdc and defined $name) { 1180 carp "Programming error";1181 exit($PS_EXIT_PROG_ERROR);1180 carp "Programming error"; 1181 exit($PS_EXIT_PROG_ERROR); 1182 1182 } 1183 1183 1184 1184 # Iterate through the array of hashes 1185 1185 foreach my $item (@$mdc) { 1186 if ($item->{name} eq $name) {1187 if ($item->{class} eq "metadata") {1188 return $item->{value};1189 }1190 if ($item->{class} eq "scalar" and $item->{type} eq "STR") {1191 # Redirect1192 return _mdLookupMDwithRedirect($mdc, $item->{value});1193 }1194 carp "$name within metadata is not of type METADATA or STR.\n";1195 return undef;1196 }1186 if ($item->{name} eq $name) { 1187 if ($item->{class} eq "metadata") { 1188 return $item->{value}; 1189 } 1190 if ($item->{class} eq "scalar" and $item->{type} eq "STR") { 1191 # Redirect 1192 return _mdLookupMDwithRedirect($mdc, $item->{value}); 1193 } 1194 carp "$name within metadata is not of type METADATA or STR.\n"; 1195 return undef; 1196 } 1197 1197 } 1198 1198
Note:
See TracChangeset
for help on using the changeset viewer.
