2015-02-19 02:00:11 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import os.path
|
|
|
|
import site
|
2017-04-25 16:45:34 +01:00
|
|
|
import sys
|
|
|
|
|
2015-02-19 02:00:11 +00:00
|
|
|
|
|
|
|
def main():
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
2015-02-19 18:12:44 +00:00
|
|
|
Check if the given prefix is included in sys.path for the given
|
|
|
|
python version; if not find an alternate valid prefix. Print the
|
|
|
|
result to standard out.
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
2015-02-19 18:12:44 +00:00
|
|
|
if len(sys.argv) != 3:
|
2017-04-25 16:45:34 +01:00
|
|
|
msg = "usage: %s <prefix> <python version>\n" % os.path.basename(sys.argv[0])
|
2015-02-19 02:00:11 +00:00
|
|
|
sys.stderr.write(msg)
|
|
|
|
return 1
|
|
|
|
python_prefix = sys.argv[1]
|
2015-02-19 18:12:44 +00:00
|
|
|
python_version = sys.argv[2]
|
2017-04-25 16:45:34 +01:00
|
|
|
path = "%s/lib/python%s" % (python_prefix, python_version)
|
2015-02-19 18:12:44 +00:00
|
|
|
path = os.path.normpath(path)
|
2017-04-25 16:45:34 +01:00
|
|
|
if path[-1] != "/":
|
|
|
|
path += "/"
|
2015-02-19 02:00:11 +00:00
|
|
|
prefix = None
|
|
|
|
for p in sys.path:
|
2015-02-19 18:12:44 +00:00
|
|
|
if p.startswith(path):
|
2015-02-19 18:18:33 +00:00
|
|
|
prefix = python_prefix
|
2015-02-19 02:00:11 +00:00
|
|
|
break
|
|
|
|
if not prefix:
|
|
|
|
prefix = site.PREFIXES[-1]
|
2017-04-25 16:45:34 +01:00
|
|
|
sys.stdout.write("%s\n" % prefix)
|
2015-02-19 02:00:11 +00:00
|
|
|
return 0
|
|
|
|
|
2017-04-25 16:45:34 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2015-02-19 02:00:11 +00:00
|
|
|
sys.exit(main())
|