6 """Unix-like tools and helpers."""
13 __author__ =
'Wim Lavrijsen (WLavrijsen@lbl.gov)'
15 __all__ = [
'FindFile',
'which',
'where',
21 """Find <filename> with rights <access> through <pathlist>."""
24 if os.path.dirname( filename ):
25 if os.access( filename, access ):
30 f = os.path.join( path, filename )
31 if os.access( f, access ):
39 def which( filename, env = os.environ ):
40 """Search for <filename> through the PATH in environment <env>. Only executable
41 files will be returned."""
49 return FindFile( filename, p.split( os.pathsep ), os.X_OK )
53 def where( filename, prepath = [] ):
54 """Search for <filename> in the python path and the given <prepath>."""
57 pathlist = prepath + sys.path
59 for ext
in [
'',
'.py',
'.pyc',
'.so' ]:
60 result =
FindFile( filename + ext, pathlist, os.R_OK )
68 """the python equivalent to the C++ PathResolver for datafiles.
71 pathlist = os.getenv(
'DATAPATH').
split(os.pathsep)
73 if not isinstance(pathlist, list):
74 raise TypeError(
"pathlist must be a list or an iterable (got %s)" %
77 return FindFile(fname, pathlist, access)