| OLD | NEW |
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Common python commands used by various build scripts.""" | 5 """Common python commands used by various build scripts.""" |
| 6 | 6 |
| 7 import inspect | 7 import inspect |
| 8 import os | 8 import os |
| 9 import subprocess | 9 import subprocess |
| 10 import sys | 10 import sys |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 def Info(message): | 131 def Info(message): |
| 132 """Emits a blue informational message and continues execution. | 132 """Emits a blue informational message and continues execution. |
| 133 | 133 |
| 134 Keyword arguments: | 134 Keyword arguments: |
| 135 message: The message to be emitted. | 135 message: The message to be emitted. |
| 136 """ | 136 """ |
| 137 print >> sys.stderr, ( | 137 print >> sys.stderr, ( |
| 138 Color(_STDOUT_IS_TTY).Color(Color.BLUE, '\nINFO: ' + message)) | 138 Color(_STDOUT_IS_TTY).Color(Color.BLUE, '\nINFO: ' + message)) |
| 139 | 139 |
| 140 | 140 |
| 141 def FindRepoDir(): | 141 def FindRepoDir(path=None): |
| 142 """Returns the nearest higher-level repo dir from the cwd.""" | 142 """Returns the nearest higher-level repo dir from the specified path. |
| 143 cwd = os.getcwd() | 143 |
| 144 while cwd != '/': | 144 Args: |
| 145 repo_dir = os.path.join(cwd, '.repo') | 145 path: The path to use. Defaults to cwd. |
| 146 """ |
| 147 if path is None: |
| 148 path = os.getcwd() |
| 149 while path != '/': |
| 150 repo_dir = os.path.join(path, '.repo') |
| 146 if os.path.isdir(repo_dir): | 151 if os.path.isdir(repo_dir): |
| 147 return repo_dir | 152 return repo_dir |
| 148 cwd = os.path.dirname(cwd) | 153 path = os.path.dirname(path) |
| 149 return None | 154 return None |
| 150 | 155 |
| 151 | 156 |
| 152 def ReinterpretPathForChroot(path): | 157 def ReinterpretPathForChroot(path): |
| 153 """Returns reinterpreted path from outside the chroot for use inside. | 158 """Returns reinterpreted path from outside the chroot for use inside. |
| 154 | 159 |
| 155 Keyword arguments: | 160 Keyword arguments: |
| 156 path: The path to reinterpret. Must be in src tree. | 161 path: The path to reinterpret. Must be in src tree. |
| 157 """ | 162 """ |
| 158 root_path = os.path.join(FindRepoDir(), '..') | 163 root_path = os.path.join(FindRepoDir(path), '..') |
| 159 | 164 |
| 160 path_abs_path = os.path.abspath(path) | 165 path_abs_path = os.path.abspath(path) |
| 161 root_abs_path = os.path.abspath(root_path) | 166 root_abs_path = os.path.abspath(root_path) |
| 162 | 167 |
| 163 # Strip the repository root from the path and strip first /. | 168 # Strip the repository root from the path and strip first /. |
| 164 relative_path = path_abs_path.replace(root_abs_path, '')[1:] | 169 relative_path = path_abs_path.replace(root_abs_path, '')[1:] |
| 165 | 170 |
| 166 if relative_path == path_abs_path: | 171 if relative_path == path_abs_path: |
| 167 raise Exception('Error: path is outside your src tree, cannot reinterpret.') | 172 raise Exception('Error: path is outside your src tree, cannot reinterpret.') |
| 168 | 173 |
| 169 new_path = os.path.join('/home', os.getenv('USER'), 'trunk', relative_path) | 174 new_path = os.path.join('/home', os.getenv('USER'), 'trunk', relative_path) |
| 170 return new_path | 175 return new_path |
| 171 | 176 |
| OLD | NEW |