Changeset 23185
- Timestamp:
- Mar 4, 2009, 3:16:07 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/PS-IPP-Config/lib/PS/IPP/Config.pm (modified) (87 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/PS-IPP-Config/lib/PS/IPP/Config.pm
r21320 r23185 71 71 unless (defined $class) { 72 72 carp "Programming error"; 73 exit($PS_EXIT_PROG_ERROR);73 return undef; 74 74 } 75 75 … … 85 85 unless (open $file, $name) { 86 86 carp "Unable to open ipprc file $name: $!"; 87 exit($PS_EXIT_CONFIG_ERROR);87 return undef; 88 88 } 89 89 my @contents = <$file>; # Contents of the ipprc file … … 95 95 unless (defined $path) { 96 96 carp "PATH is not set in $name\n"; 97 exit($PS_EXIT_CONFIG_ERROR);97 return undef; 98 98 } 99 99 … … 112 112 bless $self, $class; 113 113 114 $self->load_site() ;115 $self->load_system() ;116 117 $self->define_camera($camera) if defined $camera;114 $self->load_site() or return undef; 115 $self->load_system() or return undef; 116 117 ( $self->define_camera($camera) or return undef ) if defined $camera; 118 118 119 119 return $self; … … 148 148 unless ($found) { 149 149 carp "Unable to find camera configuration file $filename\n"; 150 exit($PS_EXIT_CONFIG_ERROR);150 return undef; 151 151 } 152 152 } … … 158 158 159 159 carp "Unable to find configuration file: $filename"; 160 exit($PS_EXIT_CONFIG_ERROR);160 return undef; 161 161 } 162 162 … … 170 170 unless (defined $self) { 171 171 carp "Programming error"; 172 exit($PS_EXIT_PROG_ERROR);172 return undef; 173 173 } 174 174 … … 176 176 unless (defined $filename) { 177 177 carp "Unable to find site configuration file\n"; 178 exit($PS_EXIT_CONFIG_ERROR);178 return undef; 179 179 } 180 180 181 181 my $realfile = $self->_find_config($filename); # Resolved filename, after hunting the PATH 182 ( carp "Unable to find site configuration" and return undef ) unless defined $realfile; 182 183 183 184 # Read the file … … 185 186 unless (open $file, $realfile) { 186 187 carp "Unable to open site configuration file $realfile: $!"; 187 exit($PS_EXIT_CONFIG_ERROR);188 return undef; 188 189 } 189 190 … … 194 195 unless (defined $self->{_siteConfig}) { 195 196 carp "Failure to parse the site configuration file $realfile"; 196 exit($PS_EXIT_CONFIG_ERROR);197 return undef; 197 198 } 198 199 … … 207 208 unless (defined $self) { 208 209 carp "Programming error"; 209 exit($PS_EXIT_PROG_ERROR);210 return undef; 210 211 } 211 212 … … 213 214 unless (defined $filename) { 214 215 carp "Unable to find system configuration file\n"; 215 exit($PS_EXIT_CONFIG_ERROR);216 return undef; 216 217 } 217 218 218 219 my $realfile = $self->_find_config($filename); # Resolved filename, after hunting the PATH 220 ( carp "Unable to find system configuration" and return undef ) unless defined $realfile; 219 221 220 222 # Read the file … … 222 224 unless (open $file, $realfile) { 223 225 carp "Unable to open system configuration file $realfile: $!"; 224 exit($PS_EXIT_CONFIG_ERROR);226 return undef; 225 227 } 226 228 my @contents = <$file>; … … 230 232 unless (defined $self->{_systemConfig}) { 231 233 carp "Failure to define system configuration"; 232 exit($PS_EXIT_CONFIG_ERROR);234 return undef; 233 235 } 234 236 … … 244 246 unless (defined $self and defined $name) { 245 247 carp "Programming error"; 246 exit($PS_EXIT_PROG_ERROR);248 return undef; 247 249 } 248 250 … … 251 253 unless (defined $filename) { 252 254 carp "Unable to find configuration file for camera $name\n"; 253 exit($PS_EXIT_CONFIG_ERROR);255 return undef; 254 256 } 255 257 256 258 my $realfile = $self->_find_config($filename); # Resolved filename, after hunting the PATH 259 ( carp "Unable to find camera configuration" and return undef ) unless defined $realfile; 257 260 258 261 # Read the file … … 260 263 unless (open $file, $realfile) { 261 264 carp "Unable to open camera configuration file $realfile: $!"; 262 exit($PS_EXIT_CONFIG_ERROR);265 return undef; 263 266 } 264 267 my @contents = <$file>; … … 269 272 unless (defined $self->{camera}) { 270 273 carp "Failure to define camera"; 271 exit($PS_EXIT_CONFIG_ERROR);274 return undef; 272 275 } 273 276 … … 326 329 unless (defined $self and defined $name) { 327 330 carp "Programming error"; 328 exit($PS_EXIT_PROG_ERROR);331 return undef; 329 332 } 330 333 … … 333 336 unless (defined $pathname) { 334 337 carp "Unable to find datapath $name\n" ; 335 exit($PS_EXIT_CONFIG_ERROR);338 return undef; 336 339 } 337 340 … … 340 343 341 344 # convert the database name and the table ID to a image source id 342 sub source_id 345 sub source_id 343 346 { 344 347 my $self = shift; … … 351 354 my $admindb = "ippadmin"; 352 355 353 die "dbserver not defined in configuration"unless defined($dbserver);354 die "dbuser not defined in configuration"unless defined($dbuser);355 die "dbpassword not defined in configuration"unless defined($dbpassword);356 die "dbname not defined in configuration"unless defined($dbname);356 ( carp "dbserver not defined in configuration" and return undef ) unless defined($dbserver); 357 ( carp "dbuser not defined in configuration" and return undef ) unless defined($dbuser); 358 ( carp "dbpassword not defined in configuration" and return undef ) unless defined($dbpassword); 359 ( carp "dbname not defined in configuration" and return undef ) unless defined($dbname); 357 360 358 361 my $dsn = "DBI:mysql:host=$dbserver;database=$admindb"; … … 363 366 $stmt->execute(); 364 367 my $ref = $stmt->fetchrow_hashref(); 365 die "ippdb $dbname not found"unless ($ref);368 ( carp "ippdb $dbname not found" and return undef ) unless ($ref); 366 369 367 370 my $proj_id = $ref->{proj_id}; … … 382 385 if ($@) { 383 386 carp "Can't find Nebulous::Client."; 384 exit($PS_EXIT_PROG_ERROR);387 return undef; 385 388 } 386 389 … … 390 393 unless (defined $server) { 391 394 carp "Unable to find NEB_SERVER in camera configuration file."; 392 exit($PS_EXIT_CONFIG_ERROR);393 } 394 395 my $neb = Nebulous::Client->new( proxy => $server );396 unless (defined $neb) {395 return undef; 396 } 397 398 my $neb = eval { Nebulous::Client->new( proxy => $server ); }; 399 if ($@ or not defined $neb) { 397 400 carp "Unable to find NEB_SERVER in camera configuration file."; 398 exit($PS_EXIT_CONFIG_ERROR);401 return undef; 399 402 } 400 403 … … 415 418 if ($scheme) { 416 419 $scheme = lc($scheme); 417 # print "scheme: $scheme\n";420 # print "scheme: $scheme\n"; 418 421 419 422 if ($scheme eq 'neb') { 420 $self->_neb_start() ;423 $self->_neb_start() or ( carp "Can't start Nebulous" and return undef ); 421 424 my $neb = $self->{nebulous}; # Nebulous handle 422 425 if ($create_if_doesnt_exist) { 423 unless ($neb->stat( $name )) { 424 # print "entry $name not found, creating...\n"; 425 my $uri = $neb->create( $name ); 426 unless(defined $uri) { 426 my $status = eval { $neb->stat( $name ); }; 427 ( carp "Unable to stat Nebulous handle $name" and return undef ) if $@; 428 unless ($status) { 429 # print "entry $name not found, creating...\n"; 430 my $uri = eval { $neb->create( $name ); }; 431 if ($@ or not defined $uri) { 427 432 carp "unable to instantiate $name."; 428 exit($PS_EXIT_DATA_ERROR);433 return undef; 429 434 } 430 435 my $path = URI->new( $uri )->path; 431 # print "created path: $path\n";436 # print "created path: $path\n"; 432 437 return $path; 433 438 } 434 439 } 435 my $path = $neb->find( $name );436 if (not defined $path) { 437 carp "neb entry $name not found, not created\n"; 438 exit($PS_EXIT_DATA_ERROR);439 } 440 # print "found path: $path\n";440 my $path = eval { $neb->find( $name ); }; 441 if ($@ or not defined $path) { 442 carp "neb entry $name not found, not created\n"; 443 return undef; 444 } 445 # print "found path: $path\n"; 441 446 return $path; 442 447 } … … 444 449 if ($scheme eq 'path' or $scheme eq 'file') { 445 450 # guaranteed to have a scheme (path:// or file://) 446 $name = $self->convert_filename_absolute( $name ) ;447 # print "resolved path to $name\n";451 $name = $self->convert_filename_absolute( $name ) or return undef; 452 # print "resolved path to $name\n"; 448 453 } 449 454 } … … 454 459 if (! -e $dir) { 455 460 my $rc = system "mkdir -p $dir"; 456 die "failed to create directory for $name"unless (!$rc);461 ( carp "failed to create directory for $name" and return undef ) unless (!$rc); 457 462 } elsif (! -d $dir ) { 458 die "parent for $name exists and is not a directory"; 459 } 460 461 open F, ">$name" or die "failed to create $name"; 463 carp "parent for $name exists and is not a directory"; 464 return undef; 465 } 466 467 open F, ">$name" or ( carp "failed to create $name" and return undef ); 462 468 close F; 463 # print "created target $name\n";469 # print "created target $name\n"; 464 470 } 465 471 … … 473 479 my $name = shift; # File name to check 474 480 475 $self->file_prepare( $name ) ;481 $self->file_prepare( $name ) or return undef; 476 482 477 483 my $scheme = file_scheme($name); # The scheme, e.g., file://, path:// … … 479 485 $scheme = lc($scheme); 480 486 if ($scheme eq 'neb') { 481 $self->_neb_start(); 482 return $self->{nebulous}->open_create( $name ); 487 $self->_neb_start() or ( carp "Unable to start Nebulous" and return undef ); 488 my $fh = eval { $self->{nebulous}->open_create( $name ); }; 489 if ($@ or not defined $fh) { 490 carp "Unable to open/create Nebulous handle $name"; 491 return undef; 492 } 493 return $fh; 483 494 } 484 495 if ($scheme eq 'path' or $scheme eq 'file') { 485 496 # guaranteed to have a scheme (path:// or file://) 486 $name = $self->convert_filename_absolute( $name ) ;497 $name = $self->convert_filename_absolute( $name ) or return undef; 487 498 } 488 499 } … … 490 501 if (-f $name) { 491 502 carp "Unable to create file $name --- file exists."; 492 exit($PS_EXIT_SYS_ERROR);503 return undef; 493 504 } 494 505 … … 496 507 unless (open $fh, '>', $name) { 497 508 carp "Unable to create file $name --- $!"; 498 exit($PS_EXIT_SYS_ERROR);509 return undef; 499 510 } 500 511 return $fh; … … 507 518 my $name = shift; # File name to check 508 519 509 $self->file_prepare( $name ) ;520 $self->file_prepare( $name ) or return undef; 510 521 511 522 my $scheme = file_scheme($name); # The scheme, e.g., file://, path:// … … 513 524 $scheme = lc($scheme); 514 525 if ($scheme eq 'neb') { 515 $self->_neb_start(); 516 return $self->{nebulous}->open_create( $name ); 526 $self->_neb_start() or ( carp "Unable to start Nebulous" and return undef ); 527 my $fh = eval { $self->{nebulous}->open_create( $name ) }; 528 if ($@ or not defined $fh) { 529 carp "Unable to open/create Nebulous handle $name"; 530 return undef; 531 } 532 return $fh; 517 533 } 518 534 if ($scheme eq 'path' or $scheme eq 'file') { 519 535 # guaranteed to have a scheme (path:// or file://) 520 $name = $self->convert_filename_absolute( $name ) ;536 $name = $self->convert_filename_absolute( $name ) or return undef; 521 537 } 522 538 } … … 525 541 unless (open $fh, '>>', $name) { 526 542 carp "Unable to create file $name --- $!"; 527 exit($PS_EXIT_SYS_ERROR);543 return undef; 528 544 } 529 545 return $fh; … … 536 552 my $name = shift; # File name to check 537 553 538 $self->file_prepare( $name ) ;554 $self->file_prepare( $name ) or return undef; 539 555 540 556 my $scheme = file_scheme($name); # The scheme, e.g., file://, path:// 541 557 if (defined $scheme and lc($scheme) eq 'neb') { 542 $self->_neb_start(); 543 $name = $self->{nebulous}->create( $name ); 558 $self->_neb_start() or ( carp "Unable to start Nebulous" and return undef ); 559 $name = eval { $self->{nebulous}->create( $name ) }; 560 if ($@ or not defined $name) { 561 carp "Unable to create Nebulous handle $name"; 562 return undef; 563 } 544 564 } 545 565 … … 555 575 my $scheme = file_scheme($name); # The scheme, e.g., file://, path:// 556 576 if (defined $scheme and lc($scheme) eq 'neb') { 557 $self->_neb_start(); 558 return (defined $self->{nebulous}->find_instances( $name ) ? 1 : 0); 577 $self->_neb_start() or ( carp "Unable to start Nebulous" and return undef ); 578 my $found = eval { $self->{nebulous}->find_instances( $name ); }; 579 ( carp "Unable to find instances of Nebulous handle $name" and return undef ) if $@; 580 return (defined $found ? 1 : 0); 559 581 } 560 582 … … 569 591 my $target = shift; # Name of target file 570 592 571 $self->file_prepare( $target ) ;593 $self->file_prepare( $target ) or return undef; 572 594 573 595 my $scheme = file_scheme($target); # The scheme, e.g., file://, path:// 574 596 if (defined $scheme and lc($scheme) eq 'neb') { 575 $self->_neb_start(); 576 $target = $self->{nebulous}->create( $target ); 597 $self->_neb_start() or ( carp "Unable to start Nebulous" and return undef ); 598 $target = eval { $self->{nebulous}->create( $target ); }; 599 if ($@ or not defined $target) { 600 carp "Unable to create Nebulous handle"; 601 return undef; 602 } 577 603 } 578 604 $target = $self->file_resolve( $target ); 579 605 $source = $self->file_resolve( $source ); 580 606 581 system("cp $source $target") == 0 or (carp "Can't copy file $source to $target." and 582 exit($PS_EXIT_DATA_ERROR)); 607 system("cp $source $target") == 0 or ( carp "Can't copy file $source to $target." and return undef ); 583 608 return 1; 584 609 } … … 593 618 my $preserve = shift; 594 619 595 die "pathname must be defined"unless ($pathname);620 ( carp "pathname must be defined" and return undef ) unless ($pathname); 596 621 597 622 my $fileRef; … … 602 627 603 628 if ($preserve) { 604 # we want to keep the file just create it in the current directory 629 # we want to keep the file just create it in the current directory 605 630 $fileName = "./$base"; 606 open $fileRef, ">$fileName" or die "can't open $fileName for output";631 open $fileRef, ">$fileName" or ( carp "can't open $fileName for output" and return undef ); 607 632 } else { 608 633 # we really want a tempfile, so put it in /tmp … … 621 646 my $scheme = file_scheme($name); # The scheme, e.g., file://, path:// 622 647 if (defined $scheme and lc($scheme) eq 'neb') { 623 $self->_neb_start(); 624 $status = $self->{nebulous}->delete( $name ); 648 $self->_neb_start() or ( carp "Unable to start Nebulous" and return undef ); 649 $status = eval { $self->{nebulous}->delete( $name ); }; 650 ( carp "Unable to delete Nebulous handle $name" and return undef ) if $@; 625 651 } else { 626 my $resolved = $self->file_resolve($name) ;627 if ( $resolved &&-e $resolved) {652 my $resolved = $self->file_resolve($name) or return undef; 653 if (defined $resolved and -e $resolved) { 628 654 $status = unlink($resolved); 629 655 } … … 638 664 my $name = shift; 639 665 640 die "need name"unless $name;666 ( carp "need redirection target" and return undef ) unless $name; 641 667 642 668 my $filename = $self->file_resolve($name, 1); 643 669 644 die "cannot resolve $name"unless $filename;670 ( carp "cannot resolve $name" and return undef ) unless $filename; 645 671 646 672 if (! open(STDOUT, ">>$filename") ) { … … 651 677 while (! open STDOUT, ">>$filename" ) { 652 678 if ($try == $max_tries) { 653 die "failed to redirect stdout to $filename after trying $max_tries times"; 679 carp "failed to redirect stdout to $filename after trying $max_tries times"; 680 return undef; 654 681 } 655 682 sleep 5; … … 658 685 print STDERR " redirect stdout to $filename succeded on try $try\n"; 659 686 } 660 open STDERR, ">>$filename" or die "failed to redirect stderr to $filename"; 687 open STDERR, ">>$filename" or ( carp "failed to redirect stderr to $filename" and return undef ); 688 689 return 1; 661 690 } 662 691 … … 676 705 my $name = shift; # File name for which to prepare 677 706 my $workdir = shift; # Working directory 678 my $template = shift; # Template filename from which to get working directory if 707 my $template = shift; # Template filename from which to get working directory if 679 708 680 709 if (defined $workdir) { … … 692 721 # not guaranteed to have a scheme (path:// or file://) - might be /PATH/foobar 693 722 # a relative path (PATH/foobar) is invalid here 694 my $resolved = $self->convert_filename_absolute( $name ) ;723 my $resolved = $self->convert_filename_absolute( $name ) or return undef; 695 724 my ( $vol, $dirs, $file ) = File::Spec->splitpath( $resolved ); 696 725 unless (-d $dirs) { 697 system("mkdir -p $dirs") == 0 or ( carp "Can't create directory $dirs" and exit($PS_EXIT_DATA_ERROR));726 system("mkdir -p $dirs") == 0 or ( carp "Can't create directory $dirs" and return undef ); 698 727 } 699 728 … … 716 745 # not guaranteed to have a scheme (path:// or file://) - might be /PATH/foobar 717 746 # a relative path (PATH/foobar) is invalid here 718 my $resolved = $self->convert_filename_absolute( $outroot ) ;747 my $resolved = $self->convert_filename_absolute( $outroot ) or return undef; 719 748 my ( $vol, $dirs, $file ) = File::Spec->splitpath( $resolved ); 720 749 unless (-d $dirs) { 721 system("mkdir -p $dirs") == 0 or ( carp "Can't create directory $dirs" and exit($PS_EXIT_DATA_ERROR));750 system("mkdir -p $dirs") == 0 or ( carp "Can't create directory $dirs" and return undef ); 722 751 } 723 752 … … 734 763 unless (defined $self and defined $name) { 735 764 carp "Programming error"; 736 exit($PS_EXIT_PROG_ERROR);765 return undef; 737 766 } 738 767 … … 741 770 742 771 ## if this is already an absolute path (/PATH/file), just return the path 743 unless (defined $scheme) { 772 unless (defined $scheme) { 744 773 if ($name =~ m|^/|) { return $name; } 745 774 # without a leading slash, this is an error 746 775 carp "Relative file name provided: relative paths are not permitted."; 747 exit($PS_EXIT_SYS_ERROR);776 return undef; 748 777 } 749 778 … … 751 780 752 781 if (lc($scheme) eq 'file') { 753 # the above strips of the leading slash; replace it for file:// 782 # the above strips of the leading slash; replace it for file:// 754 783 $name = '/' . $name; 755 784 return $name; … … 764 793 } 765 794 766 # looks like we cannot reach here without an invalid scheme. 767 # programming error? 768 # return $name; 769 770 carp "Programming error"; 771 exit($PS_EXIT_PROG_ERROR); 795 # It's already absolute 796 return $name; 772 797 } 773 798 … … 777 802 my $self = shift; # Configuration object 778 803 my $name = shift; # raw name 779 804 780 805 unless (defined $self and defined $name) { 781 806 carp "Programming error"; 782 exit($PS_EXIT_PROG_ERROR);783 } 784 807 return undef; 808 } 809 785 810 # First, check to see if it's already in a relative form 786 811 my $scheme = file_scheme($name); # The scheme, e.g., file, path … … 790 815 # We may as well search for a 'better' path 791 816 # guaranteed to have a scheme (path:// or file://) 792 $name = $self->convert_filename_absolute( $name ) ;817 $name = $self->convert_filename_absolute( $name ) or return undef; 793 818 } elsif ($scheme eq 'neb') { 794 819 # No chance of changing anything --- move along … … 796 821 } 797 822 } 798 823 799 824 $name = File::Spec->canonpath( $name); # Clean up 800 825 my @dirs = File::Spec->splitdir( $name ); 801 826 802 827 my $path_list = metadataLookupMD($self->{_siteConfig}, 'DATAPATH'); # List of paths 803 828 my $best_path; … … 809 834 $path =~ s|/*$||; 810 835 my @path_dirs = File::Spec->splitdir( $path ); 811 836 812 837 # Check if the path is suitable 813 838 next if scalar @path_dirs > scalar @dirs; … … 823 848 } 824 849 } 825 850 826 851 $name =~ s|^/||; 827 852 $name =~ s|/$||; … … 845 870 unless (defined $self and defined $name and defined $type) { 846 871 carp "Programming error"; 847 exit($PS_EXIT_PROG_ERROR);872 return undef; 848 873 } 849 874 … … 854 879 return undef; 855 880 } 856 881 857 882 # rejections are saved as a recipe: REJECTIONS 858 883 my @rejContents = `ppConfigDump -dump-recipe REJECTIONS -camera $camera -`; 859 884 860 885 # load from resulting psMetadataConfig 861 886 $self->{rejection} = $parser->parse( join '', @rejContents); # The rejection metadata 862 887 unless (defined $self->{rejection}) { 863 888 carp "Unable to parse REJECTION recipe for $camera."; 864 exit($PS_EXIT_CONFIG_ERROR);889 return undef; 865 890 } 866 891 } … … 873 898 unless ($item->{class} eq "metadata") { 874 899 carp "$name within REJECTIONS is not of type METADATA"; 875 exit($PS_EXIT_PROG_ERROR);900 return undef; 876 901 } 877 902 my $limits = $item->{value}; # List of rejection limits … … 880 905 foreach my $limit (@$limits) { 881 906 if ($limit->{name} eq 'FILTER') { 882 if ($limit->{value} eq '*' or 883 (defined $filter and 884 $limit->{value} eq $filter)) { 907 if ($limit->{value} eq '*' or (defined $filter and $limit->{value} eq $filter)) { 885 908 last; 886 909 } … … 888 911 } 889 912 } 890 913 891 914 foreach my $limit (@$limits) { 892 915 return $limit->{value} if $limit->{name} eq $name; … … 915 938 unless (defined $self and defined $name and defined $output) { 916 939 carp "Programming error: required inputs left undefined"; 917 exit($PS_EXIT_PROG_ERROR);940 return undef; 918 941 } 919 942 … … 929 952 return undef; 930 953 } 931 954 932 955 $filerules = metadataLookup($camera, 'FILERULES'); # File rules 933 956 unless (defined $filerules) { … … 935 958 return undef; 936 959 } 937 960 938 961 if ($filerules->{class} eq "scalar" and $filerules->{type} eq "STR") { 939 962 # Allow indirection to a file 940 963 my $filename = $self->_find_config($filerules->{value}); # Resolved filename 964 ( carp "Unable to find file rules file" and return undef ) unless defined $filename; 965 941 966 # Read the file 942 967 my $file; # File handle 943 968 unless (open $file, $filename) { 944 969 carp "Unable to open filerules file $filename: $!"; 945 exit($PS_EXIT_CONFIG_ERROR);970 return undef; 946 971 } 947 972 my @contents = <$file>; … … 973 998 unless (defined $component) { 974 999 carp "Programming error"; 975 exit($PS_EXIT_PROG_ERROR);1000 return undef; 976 1001 } 977 1002 $filename =~ s/\{CHIP\.NAME\}/$component/; … … 980 1005 981 1006 return $filename; 982 } 1007 } 983 1008 984 1009 # Return an EXTNAME From the EXTNAME.RULE table in the camera configuration … … 991 1016 unless (defined $self and defined $name) { 992 1017 carp "Programming error"; 993 exit($PS_EXIT_PROG_ERROR);1018 return undef; 994 1019 } 995 1020 … … 1015 1040 unless (defined $component) { 1016 1041 carp "Programming error"; 1017 exit($PS_EXIT_PROG_ERROR);1042 return undef; 1018 1043 } 1019 1044 $extname =~ s/\{CHIP\.NAME\}/$component/; … … 1021 1046 1022 1047 return $extname; 1023 } 1048 } 1024 1049 1025 1050 # Return catdir for tessellation, from TESSELLATIONS within the site configuration … … 1031 1056 unless (defined $self and defined $self->{_siteConfig} and defined $tess_id) { 1032 1057 carp "Programming error"; 1033 exit($PS_EXIT_PROG_ERROR);1058 return undef; 1034 1059 } 1035 1060 … … 1037 1062 unless (defined $tessellations) { 1038 1063 carp "Can't find TESSELLATIONS in site configuration.\n"; 1039 exit($PS_EXIT_CONFIG_ERROR);1064 return undef; 1040 1065 } 1041 1066 … … 1050 1075 if (defined $scheme and lc($scheme) eq 'neb') { 1051 1076 carp "Tessellation $tess_id refers to a Nebulous path: $catdir\n"; 1052 exit($PS_EXIT_CONFIG_ERROR);1077 return undef; 1053 1078 } 1054 1079 … … 1065 1090 unless (defined $self and defined $self->{_siteConfig} and defined $dvodb) { 1066 1091 carp "Programming error"; 1067 exit($PS_EXIT_PROG_ERROR);1092 return undef; 1068 1093 } 1069 1094 … … 1071 1096 unless (defined $catdirs) { 1072 1097 carp "Can't find DVO.CATDIRS in site configuration.\n"; 1073 exit($PS_EXIT_CONFIG_ERROR);1098 return undef; 1074 1099 } 1075 1100 … … 1084 1109 if (defined $scheme and lc($scheme) eq 'neb') { 1085 1110 carp "DVO catdir $dvodb refers to a Nebulous path: $catdir\n"; 1086 exit($PS_EXIT_CONFIG_ERROR);1111 return undef; 1087 1112 } 1088 1113 … … 1098 1123 unless (defined $self and defined $self->{_siteConfig} and defined $dvodb) { 1099 1124 carp "Programming error"; 1100 exit($PS_EXIT_PROG_ERROR);1125 return undef; 1101 1126 } 1102 1127 … … 1104 1129 unless (defined $catdirs) { 1105 1130 carp "Can't find PSASTRO.CATDIRS in site configuration.\n"; 1106 exit($PS_EXIT_CONFIG_ERROR);1131 return undef; 1107 1132 } 1108 1133 … … 1117 1142 if (defined $scheme and lc($scheme) eq 'neb') { 1118 1143 carp "PSASTRO catdir $dvodb refers to a Nebulous path: $catdir\n"; 1119 exit($PS_EXIT_CONFIG_ERROR);1144 return undef; 1120 1145 } 1121 1146 … … 1130 1155 unless (defined $self) { 1131 1156 carp "Programming error"; 1132 exit($PS_EXIT_PROG_ERROR);1157 return undef; 1133 1158 } 1134 1159 … … 1158 1183 unless (defined $self and defined $reduction and defined $name) { 1159 1184 carp "Programming error --- inputs undefined"; 1160 exit($PS_EXIT_PROG_ERROR);1185 return undef; 1161 1186 } 1162 1187 … … 1180 1205 return undef; 1181 1206 } 1182 1207 1183 1208 if ($reductionClasses->{class} eq "scalar" and $reductionClasses->{type} eq "STR") { 1184 1209 # Allow indirection to a file 1185 1210 my $filename = $self->_find_config($reductionClasses->{value}); # Resolved filename 1211 ( carp "Unable to find reduction classes file" and return undef ) unless defined $filename; 1186 1212 # Read the file 1187 1213 my $file; # File handle 1188 1214 unless (open $file, $filename) { 1189 1215 carp "Unable to open reductionClasses file $filename: $!"; 1190 exit($PS_EXIT_CONFIG_ERROR);1216 return undef; 1191 1217 } 1192 1218 my @contents = <$file>; … … 1203 1229 1204 1230 my $class = metadataLookupMD($reductionClasses, $reduction) or # Class of interest 1205 (carp "Can't find $reduction in REDUCTION in camera configuration.\n" and 1206 exit($PS_EXIT_CONFIG_ERROR)); 1231 ( carp "Can't find $reduction in REDUCTION in camera configuration.\n" and return undef ); 1207 1232 1208 1233 my $actual = metadataLookupStr($class, $name) or # The actual recipe name of interest 1209 (carp "Can't find $name in $class in REDUCTION in camera configuration.\n" and 1210 exit($PS_EXIT_CONFIG_ERROR)); 1234 (carp "Can't find $name in $class in REDUCTION in camera configuration.\n" and return undef ); 1211 1235 1212 1236 return $actual; … … 1226 1250 } 1227 1251 1228 my $dvoImageExtract = can_run('dvoImageExtract') or die "Can't find dvoImageExtract";1229 1252 my $dvoImageExtract = can_run('dvoImageExtract') or ( carp "Can't find dvoImageExtract" and return undef ); 1253 1230 1254 my $tess_dir = $self->tessellation_catdir( $tess_id ); # Tessellation catdir for DVO 1231 1255 unless (defined $tess_dir) { 1232 1256 carp "Can't get list of tessellations."; 1233 return 0;1234 } 1235 $tess_dir = $self->convert_filename_absolute( $tess_dir ) ;1257 return undef; 1258 } 1259 $tess_dir = $self->convert_filename_absolute( $tess_dir ) or return undef; 1236 1260 1237 1261 unless ($self->file_exists( $outname )) { 1238 my $outnameResolved = $self->file_create( $outname ) ; # Resolved filename, for Nebulous1262 my $outnameResolved = $self->file_create( $outname ) or return undef; # Resolved filename, for Nebulous 1239 1263 my $command = "$dvoImageExtract -D CATDIR $tess_dir $skycell_id -o $outnameResolved"; 1240 1264 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 1241 1265 run(command => $command, verbose => $verbose); 1242 die "Unable to perform dvoImageExtract for $tess_id $skycell_id\n"unless ($success and $self->file_exists( $outname ));1266 ( carp "Unable to perform dvoImageExtract for $tess_id $skycell_id\n" and return undef ) unless ($success and $self->file_exists( $outname )); 1243 1267 } 1244 1268 … … 1258 1282 unless (defined $value) { 1259 1283 carp "Unable to find environment variable $name"; 1260 exit($PS_EXIT_SYS_ERROR);1284 return undef; 1261 1285 } 1262 1286 $dir =~ s/\$\{?$name\}?/$value\//; … … 1272 1296 unless (defined $mdc and defined $name) { 1273 1297 carp "Programming error"; 1274 exit($PS_EXIT_PROG_ERROR);1298 return undef; 1275 1299 } 1276 1300 … … 1285 1309 return undef; 1286 1310 } 1287 1311 1288 1312 1289 1313 # Lookup the metadata, checking the type is STR … … 1325 1349 unless (defined $mdc and defined $name) { 1326 1350 carp "Programming error"; 1327 exit($PS_EXIT_PROG_ERROR);1351 return undef; 1328 1352 } 1329 1353
Note:
See TracChangeset
for help on using the changeset viewer.
