3 def findsenf(sysdirs = ('/usr/local/lib/senf','/usr/lib/senf'),
4 subdirs = ('', 'senf', 'Senf', 'SENF')):
5 from os.path import join, sep, exists, normpath
6 from itertools import starmap, product, chain
8 def joinpaths(*p): return starmap(join, product(*p))
9 def existing(l): return (e for e in l if exists(e))
10 def ancestors(d): p = d.split(sep); return (join(p[0]+sep,*p[1:i]) for i in range(len(p),0,-1))
15 try: return normpath(existing(butfirst(joinpaths(
16 chain(ancestors(os.getcwd()),sysdirs),
17 subdirs,('site_scons/senfutil.py',)))).next())
18 except StopIteration: raise ImportError, 'senfutil not found'
20 __file__ = findsenf(); del findsenf
21 sys.path.append(os.path.dirname(__file__))
22 execfile(__file__, locals(), globals())