ATLAS Offline Software
Loading...
Searching...
No Matches
python.Utils.unixtools Namespace Reference

Functions

 FindFile (filename, pathlist, access)
 helper -------------------------------------------------------------------—
 which (filename, env=os.environ)
 UNIX-style which ---------------------------------------------------------—.
 where (filename, prepath=[])
 "which" for python files -------------------------------------------------—
 find_datafile (fname, pathlist=None, access=os.R_OK)
 pathresolver-like helper function --------------------------------------—
 find_calibfile (fname, pathlist=None, access=os.R_OK)
 pathresolver-like helper function --------------------------------------—

Variables

str __version__ = '1.0.0'
 data ________________________________________________________________________
str __author__ = 'Wim Lavrijsen (WLavrijsen@lbl.gov)'
list __all__

Detailed Description

Unix-like tools and helpers.

Function Documentation

◆ find_calibfile()

python.Utils.unixtools.find_calibfile ( fname,
pathlist = None,
access = os.R_OK )

pathresolver-like helper function --------------------------------------—

the python equivalent to the C++ PathResolver for calibfiles.

Definition at line 80 of file unixtools.py.

80def find_calibfile(fname, pathlist=None, access=os.R_OK):
81 """the python equivalent to the C++ PathResolver for calibfiles.
82 """
83 if pathlist is None:
84 pathlist = os.getenv('CALIBPATH').split(os.pathsep)
85
86 return find_datafile(fname, pathlist, access)
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177

◆ find_datafile()

python.Utils.unixtools.find_datafile ( fname,
pathlist = None,
access = os.R_OK )

pathresolver-like helper function --------------------------------------—

the python equivalent to the C++ PathResolver for datafiles.

Definition at line 67 of file unixtools.py.

67def find_datafile(fname, pathlist=None, access=os.R_OK):
68 """the python equivalent to the C++ PathResolver for datafiles.
69 """
70 if pathlist is None:
71 pathlist = os.getenv('DATAPATH').split(os.pathsep)
72
73 if not isinstance(pathlist, list):
74 raise TypeError("pathlist must be a list or an iterable (got %s)" %
75 type(pathlist))
76
77 return FindFile(fname, pathlist, access)
78

◆ FindFile()

python.Utils.unixtools.FindFile ( filename,
pathlist,
access )

helper -------------------------------------------------------------------—

Find <filename> with rights <access> through <pathlist>.

Definition at line 20 of file unixtools.py.

20def FindFile( filename, pathlist, access ):
21 """Find <filename> with rights <access> through <pathlist>."""
22
23 # special case for those filenames that already contain a path
24 if os.path.dirname( filename ):
25 if os.access( filename, access ):
26 return filename
27
28 # test the file name in all possible paths until first found
29 for path in pathlist:
30 f = os.path.join( path, filename )
31 if os.access( f, access ):
32 return f
33
34 # no such accessible file avalailable
35 return None
36
37

◆ where()

python.Utils.unixtools.where ( filename,
prepath = [] )

"which" for python files -------------------------------------------------—

Search for <filename> in the python path and the given <prepath>.

Definition at line 53 of file unixtools.py.

53def where( filename, prepath = [] ):
54 """Search for <filename> in the python path and the given <prepath>."""
55
56 # look in the given path and in the python path
57 pathlist = prepath + sys.path
58
59 for ext in [ '', '.py', '.pyc', '.so' ]:
60 result = FindFile( filename + ext, pathlist, os.R_OK )
61 if result:
62 break
63
64 return result
65

◆ which()

python.Utils.unixtools.which ( filename,
env = os.environ )

UNIX-style which ---------------------------------------------------------—.

Search for <filename> through the PATH in environment <env>. Only executable
files will be returned.

Definition at line 39 of file unixtools.py.

39def which( filename, env = os.environ ):
40 """Search for <filename> through the PATH in environment <env>. Only executable
41files will be returned."""
42
43 # retrieve the value of the PATH environment variable
44 try:
45 p = env[ 'PATH' ]
46 except KeyError:
47 p = os.defpath
48
49 return FindFile( filename, p.split( os.pathsep ), os.X_OK )
50
51

Variable Documentation

◆ __all__

list python.Utils.unixtools.__all__
private
Initial value:
1= [ 'FindFile', 'which', 'where',
2 'find_datafile',]

Definition at line 15 of file unixtools.py.

◆ __author__

str python.Utils.unixtools.__author__ = 'Wim Lavrijsen (WLavrijsen@lbl.gov)'
private

Definition at line 13 of file unixtools.py.

◆ __version__

str python.Utils.unixtools.__version__ = '1.0.0'
private

data ________________________________________________________________________

Definition at line 12 of file unixtools.py.