From: Zooko O'Whielacronx Date: Mon, 15 Oct 2007 17:25:04 +0000 (-0700) Subject: setup: generalize the kludge of finding an executable (i.e. trial or twistd) when... X-Git-Tag: allmydata-tahoe-0.6.1~12 X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/statistics?a=commitdiff_plain;h=5b476d73ee1e9e89f7398c3541838321caef9001;p=tahoe-lafs%2Ftahoe-lafs.git setup: generalize the kludge of finding an executable (i.e. trial or twistd) when there might be only a .py script version of it available --- diff --git a/src/allmydata/util/find_exe.py b/src/allmydata/util/find_exe.py new file mode 100644 index 00000000..f15a4030 --- /dev/null +++ b/src/allmydata/util/find_exe.py @@ -0,0 +1,28 @@ +import os, sys +from twisted.python.procutils import which + +def find_exe(exename): + """ + Look for something named exename or exename + ".py". + + This is a kludge. + + @return: a list containing one element which is the path to the exename + (if it is thought to be executable), or else the first element being + sys.executable and the second element being the path to the + exename + ".py", or else return False if one can't be found + """ + exes = which(exename) + exe = exes and exes[0] + if not exe: + exe = os.path.join(sys.prefix, 'scripts', exename + '.py') + if os.path.exists(exe): + path, ext = os.path.splitext(exe) + if ext.lower() in [".exe", ".bat",]: + cmd = [exe,] + else: + cmd = [sys.executable, exe,] + return cmd + else: + return False +