Jim Stichnoth | 16178a1 | 2014-09-02 14:11:57 -0700 | [diff] [blame] | 1 | import os |
Karl Schimpf | a667fb8 | 2014-05-19 14:56:51 -0700 | [diff] [blame] | 2 | import subprocess |
| 3 | import sys |
| 4 | |
| 5 | def shellcmd(command, echo=True): |
Karl Schimpf | a667fb8 | 2014-05-19 14:56:51 -0700 | [diff] [blame] | 6 | if not isinstance(command, str): |
| 7 | command = ' '.join(command) |
| 8 | |
Jim Stichnoth | 118ca79 | 2014-09-30 10:52:04 -0700 | [diff] [blame] | 9 | if echo: print '[cmd]', command |
| 10 | |
Karl Schimpf | a667fb8 | 2014-05-19 14:56:51 -0700 | [diff] [blame] | 11 | stdout_result = subprocess.check_output(command, shell=True) |
| 12 | if echo: sys.stdout.write(stdout_result) |
| 13 | return stdout_result |
Jim Stichnoth | 16178a1 | 2014-09-02 14:11:57 -0700 | [diff] [blame] | 14 | |
| 15 | def FindBaseNaCl(): |
| 16 | """Find the base native_client/ directory.""" |
| 17 | nacl = 'native_client' |
| 18 | path_list = os.getcwd().split(os.sep) |
| 19 | if nacl not in path_list: |
| 20 | return None |
| 21 | last_index = len(path_list) - path_list[::-1].index(nacl) |
| 22 | return os.sep.join(path_list[:last_index]) |