1 """This lets you find files with just a path name relative to where
2 the program's executable code script sits."""
3
4 import sys
5
6 _scriptname = sys.argv[0]
7
8
9
10
11 import os
12
13 __version__ = "$Revision: 1.6 $"
14
15
17 for t in pathlist:
18 if t == '':
19 t = '.'
20 tmp = '%s/%s' % (t, s)
21 if os.access(tmp, access) and os.path.isdir(tmp):
22 return tmp
23 raise RuntimeError, "Can't find %s" % s
24
25
27 for t in pathlist:
28 if t == '':
29 t = '.'
30 tmp = '%s/%s' % (t, s)
31 if os.access(tmp, access):
32 return tmp
33 raise RuntimeError, "Can't find %s" % s
34
35
37 """Find an executable program.
38 It searches first in the directory of the currently executing
39 python script. Optionally, it then looks at PATH.
40 If general=False, the function should fail unless
41 the executable is in the same directory as the currently
42 executing python script."""
43 p = [ os.path.dirname( _scriptname ) ]
44
45 if general:
46 p.extend( os.environ['PATH'].split(':') )
47
48 return _search(p, s, os.X_OK)
49
50
51
53 """Find a module. Returns pathname."""
54 p = [ os.path.dirname( _scriptname ) ]
55
56 if general:
57 p.extend( sys.path )
58
59 return _search(p, "%s.py" % s, os.R_OK)
60
61
63 """Find an operating-system dependent executable program."""
64 return executable('bin__' + os.uname()[0] + '/' + nm, general)
65
66
67
69 """Find a data file."""
70 p = [ '.', os.path.dirname( _scriptname ) ]
71 return _search(p, s, os.R_OK)
72
73
74
76 """Find a directory."""
77 p = [ os.path.dirname( _scriptname ) ]
78 return _searchdir(p, s, os.X_OK)
79
80
81
82
83 if __name__ == '__main__':
84 assert data("find_home.py")
85