3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
6 Licensed under the Apache License, Version 2.0 (the
"License");
7 you may not use
this file except in compliance with the License.
8 You may obtain a copy of the License at
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an
"AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License
for the specific language governing permissions and
16 limitations under the License.
23 Please email comments or questions to the
public Ensembl
24 developers list at <http:
26 Questions may also be sent to the Ensembl help desk at
31 package Bio::EnsEMBL::Analysis::Programs;
34 use vars qw( %Program_Paths );
43 #print STDERR "importing: $_\n";
44 $Program_Paths{ $_ } = 0;
46 my( $home, @PATH, @missing );
48 $home = cwd() or die
"Can't save cwd";
51 @PATH = split /:/, $ENV{
'PATH'};
53 s|/?$|/|; # Append / to each path
56 # For each program, check there is an executable
57 foreach my $program (keys %Program_Paths) {
60 if ($program =~ m|/|) {
64 $path =~ s{^~([^/]*)}{ $1 ? (getpwnam($1))[7]
65 : (getpwuid($>))[7] }e;
66 if (my $real = _is_prog( $H, $path )) {
67 $Program_Paths{ $program } = $real;
70 # Or search through all paths
72 foreach my $path (@PATH) {
74 if (my $real = _is_prog( $H, $path, $program )) {
75 $Program_Paths{ $program } = $real;
81 _go_home( $H ); # Return to home directory
83 # Make a list of all missing programs
84 foreach my $program (keys %Program_Paths) {
85 push( @missing, $program ) unless $Program_Paths{ $program };
88 # Give informative death message if programs weren't found
90 throw(
"Unable to locate the following programs as '". (getpwuid($<))[0].
"' on host '". hostname().
"' :\t".
91 join (
" --> " , @missing )) ;
95 # Recursive function which follows links, or tests final destination
97 my( $h, $path, $prog ) = @_;
99 # Need to split path if $prog not provided
101 ($path, $prog) = $path =~ m|(.*?)([^/]+)$|;
104 if (-l
"$path$prog") {
106 _follow( $h, $path ) or
return;
107 unless (-x readlink($prog)) {
108 confess
"Can't read link '$path$prog' : $!";
111 $path = cwd() or confess
"Can't determine cwd";
112 return "$path/$prog";
113 } elsif (-f _ and -x _) {
115 _follow( $h, $path ) or
return;
116 $path = cwd() or confess
"Can't determine cwd";
117 return "$path/$prog";
119 # Not a link or an executable plain file
124 # To avoid unnecessary chdir'ing
126 my( $H, $path ) = @_;
128 # Chdir without arguments goes to home dir.
129 # Can't use defined in test since $path may contain
130 # a real null string.
131 if ( ! $path and $path ne
'0' ) {
133 } elsif (chdir($path)) {
143 # Go home unless we're already there
145 if (chdir( $H->[0] )) {
148 confess
"Can't go home to [ ", $H->[0],
' ]';
162 /usr/local/bin/this_one
163 ~me/some/path/my_prog
164 ~/../jane/bin/her_prog );
166 # Can also do at run time
169 $path_to_prog = $Bio::EnsEMBL::Analysis::Programs::Program_Paths{ $prog };
173 B<Programs> is used to check at compile time
for the
174 presence of executables which will be called from your
175 script. Arguments passed via the use statement
176 can be just the program name, or an absolute or
177 relative path to the program. Tildes are expanded
178 correctly (I<not>
using "glob"). Failure to find any
179 one program is fatal, and a list of all failures is
180 printed, along with the host
''s name.
182 If you want to check
for a program during
run time,
183 the
import funtion can be called directly, as shown above.
185 The paths to each program found are stored in the
186 B<%Program_Paths> hash, which is keyed on the original
191 If the executable is in the root directory, then it
''s found
192 path will appear as
"//prog" in %Program_Paths, not
"/prog".
196 B<James Gilbert> Email jgrg@sanger.ac.uk