diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2012-11-26 17:06:27 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2012-11-26 17:06:27 -0500 |
commit | b43b83beead92ff7cf28a5fe5a2710537268aae1 (patch) | |
tree | d9c29b14cd18a9df520f36d7e85eb460c30fa7a9 /common.py | |
parent | cb8db5d30ee769304c2c2b00f2a7d9bcb3c4098f (diff) |
Read locations of binary files from path instead of config.py.
Diffstat (limited to 'common.py')
-rw-r--r-- | common.py | 25 |
1 files changed, 23 insertions, 2 deletions
@@ -2,6 +2,29 @@ import sys | |||
2 | from collections import defaultdict | 2 | from collections import defaultdict |
3 | from textwrap import dedent | 3 | from textwrap import dedent |
4 | 4 | ||
5 | def get_executable(prog, hint, optional=False): | ||
6 | import os | ||
7 | def is_exe(fpath): | ||
8 | return os.path.isfile(fpath) and os.access(fpath, os.X_OK) | ||
9 | |||
10 | fpath, fname = os.path.split(prog) | ||
11 | if fpath: | ||
12 | if is_exe(prog): | ||
13 | return prog | ||
14 | else: | ||
15 | for path in os.environ["PATH"].split(os.pathsep): | ||
16 | exe_file = os.path.join(path, prog) | ||
17 | if is_exe(exe_file): | ||
18 | return exe_file | ||
19 | |||
20 | if not optional: | ||
21 | sys.stderr.write("Cannot find executable '%s' in PATH. This is a part " | ||
22 | "of '%s' which should be added to PATH to run." % | ||
23 | (prog, hint)) | ||
24 | sys.exit(1) | ||
25 | else: | ||
26 | return None | ||
27 | |||
5 | def recordtype(typename, field_names, default=0): | 28 | def recordtype(typename, field_names, default=0): |
6 | ''' Mutable namedtuple. Recipe from George Sakkis of MIT.''' | 29 | ''' Mutable namedtuple. Recipe from George Sakkis of MIT.''' |
7 | field_names = tuple(map(str, field_names)) | 30 | field_names = tuple(map(str, field_names)) |
@@ -87,5 +110,3 @@ def load_params(fname): | |||
87 | raise IOError("Invalid param file: %s\n%s" % (fname, e)) | 110 | raise IOError("Invalid param file: %s\n%s" % (fname, e)) |
88 | 111 | ||
89 | return params | 112 | return params |
90 | |||
91 | |||