212819a6d4157ad4f4917480bb417b2ce6bd5de3
[senf.git] / Examples / Sniffer / site_scons / senfutil.py
1 import sys, os
2
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
7
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))
11     def butfirst(l):
12         i = iter(l); i.next()
13         for e in i : yield e
14
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'
19
20 __file__ = findsenf(); del findsenf
21 sys.path.append(os.path.dirname(__file__))
22 execfile(__file__, locals(), globals())