X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Examples%2FSniffer%2Fsite_scons%2Fsenfutil.py;h=ceabee87feba6c07f11de897387577e2e16523cd;hb=4101c2b818ec67e7469ebb44f030eed2185c4ab0;hp=212819a6d4157ad4f4917480bb417b2ce6bd5de3;hpb=1f270d560ae6f4b70bbca1e671c29aaf55bc8922;p=senf.git diff --git a/Examples/Sniffer/site_scons/senfutil.py b/Examples/Sniffer/site_scons/senfutil.py index 212819a..ceabee8 100644 --- a/Examples/Sniffer/site_scons/senfutil.py +++ b/Examples/Sniffer/site_scons/senfutil.py @@ -1,22 +1,22 @@ -import sys, os def findsenf(sysdirs = ('/usr/local/lib/senf','/usr/lib/senf'), subdirs = ('', 'senf', 'Senf', 'SENF')): - from os.path import join, sep, exists, normpath - from itertools import starmap, product, chain + import os, itertools + + def ancestors(d): + p = d.split(os.path.sep) + return (os.path.join(p[0]+os.path.sep,*p[1:i]) for i in range(len(p),0,-1)) - def joinpaths(*p): return starmap(join, product(*p)) - def existing(l): return (e for e in l if exists(e)) - def ancestors(d): p = d.split(sep); return (join(p[0]+sep,*p[1:i]) for i in range(len(p),0,-1)) - def butfirst(l): - i = iter(l); i.next() - for e in i : yield e + for d in itertools.chain(ancestors(os.getcwd()),sysdirs): + for s in subdirs: + py = os.path.join(d,s,'site_scons/senfutil.py') + if os.path.exists(py) and not os.path.samefile(py,__file__): return py - try: return normpath(existing(butfirst(joinpaths( - chain(ancestors(os.getcwd()),sysdirs), - subdirs,('site_scons/senfutil.py',)))).next()) - except StopIteration: raise ImportError, 'senfutil not found' + raise ImportError, 'senfutil not found' -__file__ = findsenf(); del findsenf +# replace module with real senfutil +import sys, os +__file__ = findsenf() sys.path.append(os.path.dirname(__file__)) +del sys, os, findsenf execfile(__file__, locals(), globals())