-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_epd.py
More file actions
executable file
·64 lines (51 loc) · 2.38 KB
/
find_epd.py
File metadata and controls
executable file
·64 lines (51 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#! /usr/bin/env python
'''
Recursively looks for EPD
Writes to STDOUT and STDERR the found library and the found include directory. In this way,
this script can be executed within CMAKE and the Python Libraries and Includes can be set to the STDOUT and STDERR streams
Checks for a minimum version of Python, default 2.7, but can be specified as a command-line argument
The root paths it starts looking for EPD in are contained in the 'check_dirs' global variable
'''
import os, sys, getpass
check_dirs = ['/opt/local/lib', '/home/%s' % getpass.getuser(), '/usr/share/', '/home/ecuzzill', '/opt/local', '/opt']
def main():
if len(sys.argv) == 2:
min_py_version = sys.argv[1]
#make sure it's a version by casting to float
try:
min_py_version = 'libpython' + str(float(min_py_version))
except ValueError:
min_py_version = 'libpython2.7'
else:
min_py_version = 'libpython2.7'
found = False
for d in check_dirs:
for (dname, dnames, fnames) in os.walk(d):
for r in dnames:
#found an 'epd'-ish directory
if r.find('epd') >= 0:
full_dir = '%s/%s' % (dname, r)
lib_exists = False
#find the library
for lib in [x for x in os.listdir(full_dir + '/lib/') if x.find('libpython') >=0 ]:
lib_version = '.'.join(lib.split('.')[:2])
if lib_version >= min_py_version:
lib_exists = True
break
if not lib_exists:
break
lib = '%s/lib/%s.so' % (full_dir, lib_version)
include_dir = '%s/include/%s' % (full_dir, min_py_version[3:])
#success if this passes
if os.path.isfile(lib) and os.path.isdir(include_dir):
bin_path = '%s/bin/python' % (full_dir)
unicode_support = os.system("%s -c 'import sys; sys.exit(sys.maxunicode > 65535)'" % (bin_path))
if unicode_support == 0:
sys.stdout.write(lib)
sys.stderr.write(include_dir)
found = True
break
if found:
break
if __name__ == '__main__':
main()