package Util::HEAdas; ############################################################################## # # DESCRIPTION: This sub-class adds HEAdas environment initialization # # HISTORY # HISTORY: $Log: HEAdas.pm,v $ # HISTORY: Revision 1.3 2007/01/31 16:04:08 apsop # HISTORY: Update to version being used by swift. Merge in intializations previous done by ftools. Override variables unitentionally picked up from the starting environment. # HISTORY: # HISTORY: Revision 1.2 2006/08/01 20:35:34 apsop # HISTORY: Add in CVS history indicator. # HISTORY: # HISTORY: 1.0 -> 1.1 2001-03-05 # HISTORY: Modified the way the PATH and LD_LIBRARY_PATH environment variables # HISTORY: are set to make the more robust. # HISTORY: # HISTORY: 1.1 -> 2.0 2002-04-18 # HISTORY: Made this a subclass of ParfileTool to better handle FTOOLS # HISTORY: and HEAdas, not to mention PseudoFtools. # HISTORY: # HISTORY: 2.0 -> 2.1 2004-02-11 # HISTORY: The environment method now returns a reference to a hash # HISTORY: # HISTORY: 2.1 -> 2.2 2004-03-09 # HISTORY: Moved HEADASNOQUERY environment variable to ParfileTool.pm # # VERSION: 2.2 # ############################################################################## use Util::ParfileTool; @ISA=("Util::ParfileTool"); use strict; use Util::Ftool; use Util::Xanadu; my $INSTALL_DIR; my @BINS=(); my @LIBS=(); my $SYSPFILES; my %ENVIRONMENT=(); my %SCRIPT_ENVIRONMENT=(); my $VERSION; ######################################################################### # ######################################################################### sub new { my $self=shift; my $tool=shift; $self->SUPER::new($tool,$SYSPFILES, \@BINS, \@LIBS); } # end of constructor ###################### # ACCESSORS: ###################### ######################################################################## # Returns a hash of environment variables which must # be set before running this tool ######################################################################## sub environment { my $self=shift; if ($self->{IS_SCRIPT} ) { return {%{$self->SUPER::environment()}, %ENVIRONMENT, %SCRIPT_ENVIRONMENT}; } else { return {%{$self->SUPER::environment()}, %ENVIRONMENT}; } } # end of environment method #################################################################### # This method does all the initialization for this class, given # the name of the machine-specific instalation directory. # Note this method must be called after the corresponding method is called # for the Ftools. #################################################################### sub install_dir { my $self=shift; if(@_) { $INSTALL_DIR=shift; ##################################################### # set the executable directories and # the parfile directory ##################################################### @BINS=("$INSTALL_DIR/bin"); @LIBS=("$INSTALL_DIR/lib"); $SYSPFILES = "$INSTALL_DIR/syspfiles"; ########################################## # parse the version name ########################################## ($VERSION) = $INSTALL_DIR =~ m|/\w*\.([^/]*)/|; ##################################################### # Set the environment variables ##################################################### $ENVIRONMENT{HEADAS}=$INSTALL_DIR; ## $ENVIRONMENT{HEADASOUTPUT}="stdout"; ## $ENVIRONMENT{HEADASERROR }="stderr"; $ENVIRONMENT{HEADASPROMPT}="/dev/null"; $ENVIRONMENT{LHEAPERL}=$^X; # <- perl version running this script ##################################################### # special stuff for scripts ##################################################### my $ftools = Util::Ftool->install_dir; $SCRIPT_ENVIRONMENT{HOME} = '.'; # my $envPERLLIB = $ENV{PERLLIB} || ''; # $SCRIPT_ENVIRONMENT{PERLLIB} = "$INSTALL_DIR/lib/perl:$envPERLLIB"; $SCRIPT_ENVIRONMENT{PERLLIB} = "$INSTALL_DIR/lib/perl"; $SCRIPT_ENVIRONMENT{PERL5LIB} = "$INSTALL_DIR/lib/perl"; # $envPERLLIB = $ENV{PERL5LIB} || ''; # $SCRIPT_ENVIRONMENT{PERL5LIB} = "$INSTALL_DIR/lib/perl:$envPERLLIB"; $SCRIPT_ENVIRONMENT{PATH} = join(":", @BINS, "$ftools/bin", $ENV{PATH}); # ack # push(@LIBS, "$ftools/lib"); # $SCRIPT_ENVIRONMENT{PFILES} = ".;$SYSPFILES:$ftools/syspfiles"; # need Xanadu setup too my $xanadu = Util::Xanadu->new('ximage'); my $xanenv = $xanadu->environment; my @keys = keys(%$xanenv); @SCRIPT_ENVIRONMENT{@keys} = @{$xanenv}{@keys}; push(@LIBS, $xanadu->libs); } return $INSTALL_DIR; } ############################################################## # returns the version of the package being used. # Note this version name is derived by parsing the name # of the instalation directory. ############################################################ sub version { my $self=shift; return $VERSION; } #################################################### # assemble the error message. # Override the generic message to specify "FTOOL" #################################################### sub error_message { my $self=shift; my $message="Error from HEAdas Task $self->{COMMAND} - ". "exit status $self->{STATUS}"; return $message; } sub DESTROY { my $self = shift; # check for an overridden destructor... $self->SUPER::DESTROY if $self->can("SUPER::DESTROY"); } 1;