Chromium Code Reviews| Index: native_client_sdk/src/tools/oshelpers.py |
| diff --git a/native_client_sdk/src/tools/oshelpers.py b/native_client_sdk/src/tools/oshelpers.py |
| index e9655a2d9faecda91b2a8a14a20acbef156f092a..0cfebc072b9531ea7b805d5b124b9df7ac9a7142 100755 |
| --- a/native_client_sdk/src/tools/oshelpers.py |
| +++ b/native_client_sdk/src/tools/oshelpers.py |
| @@ -469,12 +469,50 @@ def Zip(args): |
| return 0 |
| +def Which(args): |
| + """A Unix style which. |
| + |
| + Looks for all arguments in the PATH environment variable, and prints their |
| + path if they are executable files. |
| + |
| + Note: If you pass an argument with a path to which, it will just test if it |
| + is executable, not if it is in the path. |
| + """ |
| + parser = optparse.OptionParser(usage='usage: which args...') |
| + _, files = parser.parse_args(args) |
| + if files == 0: |
|
Sam Clegg
2013/02/09 01:28:14
if not files:
binji
2013/02/09 01:44:43
Done. Whoops.
|
| + return |
|
Sam Clegg
2013/02/09 01:28:14
parser.error("no files specified")?
No need for r
binji
2013/02/09 01:44:43
It's not an error to run which without arguments.
Sam Clegg
2013/02/09 01:49:28
Ha! At least it should return non-zero here then.
binji
2013/02/09 02:31:44
Done.
|
| + |
| + env_path = os.environ.get('PATH', '') |
| + paths = env_path.split(os.pathsep) |
| + |
| + def IsExecutableFile(path): |
| + return os.path.isfile(path) and os.access(path, os.X_OK) |
| + |
| + retval = 0 |
| + for filename in files: |
| + if os.path.sep in filename: |
| + if IsExecutableFile(filename): |
| + print filename |
| + continue |
| + |
| + for path in paths: |
| + filepath = os.path.join(path, filename) |
| + if IsExecutableFile(filepath): |
| + print os.path.abspath(os.path.join(path, filename)) |
|
Sam Clegg
2013/02/09 01:28:14
Might want to also append try adding .com .bat and
binji
2013/02/09 01:44:43
Not needed in this CL, we can add it later if desi
|
| + break |
| + else: |
| + retval = 1 |
| + return retval |
| + |
| + |
| FuncMap = { |
| 'cp': Copy, |
| 'mkdir': Mkdir, |
| 'mv': Move, |
| 'rm': Remove, |
| 'zip': Zip, |
| + 'which': Which, |
| } |