aboutsummaryrefslogtreecommitdiffstats
path: root/common.py
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2012-11-26 17:06:27 -0500
committerJonathan Herman <hermanjl@cs.unc.edu>2012-11-26 17:06:27 -0500
commitb43b83beead92ff7cf28a5fe5a2710537268aae1 (patch)
treed9c29b14cd18a9df520f36d7e85eb460c30fa7a9 /common.py
parentcb8db5d30ee769304c2c2b00f2a7d9bcb3c4098f (diff)
Read locations of binary files from path instead of config.py.
Diffstat (limited to 'common.py')
-rw-r--r--common.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/common.py b/common.py
index 984f584..0990cfe 100644
--- a/common.py
+++ b/common.py
@@ -2,6 +2,29 @@ import sys
2from collections import defaultdict 2from collections import defaultdict
3from textwrap import dedent 3from textwrap import dedent
4 4
5def 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
5def recordtype(typename, field_names, default=0): 28def 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