Fix sample bootstrap senfutil.py (Examples/Sniffer/site_scons/senfutil.py)
[senf.git] / Examples / Sniffer / site_scons / senfutil.py
1
2 def findsenf(sysdirs = ('/usr/local/lib/senf','/usr/lib/senf'),
3              subdirs = ('', 'senf', 'Senf', 'SENF')):
4     import os, itertools
5
6     def ancestors(d):
7         p = d.split(os.path.sep)
8         return (os.path.join(p[0]+os.path.sep,*p[1:i]) for i in range(len(p),0,-1))
9
10     for d in itertools.chain(ancestors(os.getcwd()),sysdirs):
11         for s in subdirs:
12             py = os.path.join(d,s,'site_scons/senfutil.py')
13             if os.path.exists(py) and not os.path.samefile(py,__file__): return py
14
15     raise ImportError, 'senfutil not found'
16
17 # replace module with real senfutil
18 import sys, os
19 __file__ = findsenf()
20 sys.path.append(os.path.dirname(__file__))
21 del sys, os, findsenf
22 execfile(__file__, locals(), globals())