diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-04-10 14:35:37 -0400 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-04-10 14:35:37 -0400 |
commit | 4162cc0c57de22566efa6e2dab224909279f2a47 (patch) | |
tree | a8628096c4161e658c385b07b026371a2ef5e3c4 /common.py | |
parent | 37a410ab7d4ba991a075a3b2f4d24a656f4544ca (diff) |
run_exps will run any command whose last argument is the duration.
Diffstat (limited to 'common.py')
-rw-r--r-- | common.py | 47 |
1 files changed, 25 insertions, 22 deletions
@@ -7,29 +7,34 @@ import sys | |||
7 | from collections import defaultdict | 7 | from collections import defaultdict |
8 | from textwrap import dedent | 8 | from textwrap import dedent |
9 | 9 | ||
10 | def get_executable(prog, hint='unknown', optional=False): | 10 | def get_executable(prog, cwd="."): |
11 | '''Search for @prog in system PATH. Print @hint if no binary is found.''' | 11 | '''Search for @prog in system PATH and @cwd.''' |
12 | 12 | ||
13 | def is_exe(fpath): | 13 | cwd_path = "%s/%s" % (cwd, prog) |
14 | return os.path.isfile(fpath) and os.access(fpath, os.X_OK) | 14 | if is_executable(cwd_path): |
15 | 15 | return cwd_path | |
16 | fpath, fname = os.path.split(prog) | ||
17 | if fpath: | ||
18 | if is_exe(prog): | ||
19 | return prog | ||
20 | else: | 16 | else: |
21 | for path in os.environ["PATH"].split(os.pathsep): | 17 | for path in os.environ["PATH"].split(os.pathsep): |
22 | exe_file = os.path.join(path, prog) | 18 | exe_file = os.path.join(path, prog) |
23 | if is_exe(exe_file): | 19 | if is_executable(exe_file): |
24 | return exe_file | 20 | return exe_file |
25 | 21 | ||
26 | if not optional: | 22 | full_cwd = os.path.abspath(cwd) |
27 | sys.stderr.write("Cannot find executable '%s' in PATH. This is a part " | 23 | raise IOError("Cannot find executable '%s'! (cwd='%s')" % (prog, full_cwd)) |
28 | "of '%s' which should be added to PATH to run.\n" % | 24 | |
29 | (prog, hint)) | 25 | def get_executable_hint(prog, hint, optional=False): |
30 | sys.exit(1) | 26 | '''Search for @prog in system PATH. Print @hint if no binary is found. |
31 | else: | 27 | Die if not @optional.''' |
32 | return None | 28 | try: |
29 | prog = get_executable(prog) | ||
30 | except IOError: | ||
31 | if not optional: | ||
32 | sys.stderr.write(("Cannot find executable '%s' in PATH. This is " +\ | ||
33 | "a part of '%s' which should be added to PATH.\n")\ | ||
34 | % (prog, hint)) | ||
35 | sys.exit(1) | ||
36 | |||
37 | return prog | ||
33 | 38 | ||
34 | def get_config_option(option): | 39 | def get_config_option(option): |
35 | '''Search for @option in installed kernel config (if present). | 40 | '''Search for @option in installed kernel config (if present). |
@@ -174,14 +179,12 @@ def ft_freq(): | |||
174 | return freq | 179 | return freq |
175 | 180 | ||
176 | 181 | ||
177 | def uname_matches(reg): | 182 | def kernel(): |
178 | data = subprocess.check_output(["uname", "-r"]) | 183 | return subprocess.check_output(["uname", "-r"]) |
179 | return bool( re.match(reg, data) ) | ||
180 | 184 | ||
181 | def is_executable(fname): | 185 | def is_executable(fname): |
182 | '''Return whether the file passed in is executable''' | 186 | '''Return whether the file passed in is executable''' |
183 | mode = os.stat(fname)[stat.ST_MODE] | 187 | return os.path.isfile(fname) and os.access(fname, os.X_OK) |
184 | return mode & stat.S_IXUSR and mode & stat.S_IRUSR | ||
185 | 188 | ||
186 | def is_device(dev): | 189 | def is_device(dev): |
187 | if not os.path.exists(dev): | 190 | if not os.path.exists(dev): |