-
Notifications
You must be signed in to change notification settings - Fork 9
/
binary_utils.py
executable file
·60 lines (48 loc) · 1.57 KB
/
binary_utils.py
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
#!/usr/bin/env python3
import os
import sys
class Binary:
"""
This class aims to retrieve binaries by name.
First, look into matam directories (cf below).
Then look into the PATH.
If no match occured, return None
Matam organisation:
matam_root_dir/
/bin/
/scripts/
binary_utils.py
/componentsearch/
/ovgraphbuild/bin/
/sga/src/
/sortmerna/
/vsearch/bin/
/RDPTools/
/Krona/KronaTools/bin/
"""
_matam_root, _ = os.path.split(os.path.dirname(os.path.realpath(__file__)))
_matam_bin_dirs = [ 'bin/',
'scripts/',
'componentsearch/',
'ovgraphbuild/bin/',
'sga/src/SGA',
'sortmerna/',
'vsearch/bin/',
'RDPTools/',
'Krona/KronaTools/bin/'
]
def _is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
def which(program):
path_to_look_for = [ os.path.join(Binary._matam_root, d) for d in Binary._matam_bin_dirs ]
path_to_look_for.extend(os.environ["PATH"].split(os.pathsep))
for path in path_to_look_for:
path = path.strip('"')
exe_file = os.path.join(path, program)
if Binary._is_exe(exe_file):
return exe_file
def assert_which(program):
p = Binary.which(program)
if p:
return p
sys.exit('No valid binary found for %s' % program)