Chromium Code Reviews| 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 re | 9 import re |
| 10 import subprocess | 10 import subprocess |
| 11 import sys | 11 import sys |
| 12 | 12 |
| 13 _STDOUT_IS_TTY = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty() | 13 _STDOUT_IS_TTY = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty() |
| 14 CROSUTILS_DIRECTORY = os.path.dirname(os.path.dirname( | |
| 15 os.path.realpath(__file__))) | |
| 16 | 14 |
| 17 # TODO(sosa): Move logging to logging module. | 15 # TODO(sosa): Move logging to logging module. |
| 18 | 16 |
| 19 class RunCommandException(Exception): | 17 class RunCommandException(Exception): |
| 20 """Raised when there is an error in RunCommand.""" | 18 """Raised when there is an error in RunCommand.""" |
| 21 pass | 19 pass |
| 22 | 20 |
| 23 | 21 |
| 24 def GetCallerName(): | 22 def GetCallerName(): |
| 25 """Returns the name of the calling module with __main__.""" | 23 """Returns the name of the calling module with __main__.""" |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 | 317 |
| 320 | 318 |
| 321 def UnmountImage(root_dir, stateful_dir): | 319 def UnmountImage(root_dir, stateful_dir): |
| 322 """Unmounts a Chromium OS image specified by mount dir points.""" | 320 """Unmounts a Chromium OS image specified by mount dir points.""" |
| 323 RunCommand(['./mount_gpt_image.sh', | 321 RunCommand(['./mount_gpt_image.sh', |
| 324 '--unmount', | 322 '--unmount', |
| 325 '--rootfs_mountpt=%s' % root_dir, | 323 '--rootfs_mountpt=%s' % root_dir, |
| 326 '--stateful_mountpt=%s' % stateful_dir, | 324 '--stateful_mountpt=%s' % stateful_dir, |
| 327 ], print_cmd=False, redirect_stdout=True, redirect_stderr=True, | 325 ], print_cmd=False, redirect_stdout=True, redirect_stderr=True, |
| 328 cwd=CROSUTILS_DIRECTORY) | 326 cwd=CROSUTILS_DIRECTORY) |
| 327 | |
| 328 | |
| 329 def GetCrosUtilsPath(from_source=True): | |
|
petkov
2011/03/28 20:48:56
s/from_source/to_src/
sosa
2011/03/28 20:57:34
renamed to source_path_dir
On 2011/03/28 20:48:56
| |
| 330 """Return the path to src/scripts. | |
| 331 | |
| 332 Args: | |
| 333 from_src: If True, returns the path to the src location. | |
| 334 """ | |
| 335 if IsInsideChroot(): | |
| 336 if from_source: | |
| 337 return os.path.join(os.getenv('HOME'), 'trunk', 'src', 'scripts') | |
| 338 else: | |
|
petkov
2011/03/28 20:48:56
remove?
sosa
2011/03/28 20:57:34
Done.
| |
| 339 return os.path.join('/usr/lib/crosutils') | |
| 340 | |
| 341 # Outside the chroot => from_source. | |
| 342 return os.path.join(os.path.dirname(os.path.realpath(__file__)), '..') | |
| 343 | |
| 344 | |
| 345 # TODO(sosa): Copied from chromite. | |
|
petkov
2011/03/28 20:48:56
what's left to do?
sosa
2011/03/28 20:57:34
Done.
| |
| 346 def IsInsideChroot(): | |
| 347 """Returns True if we are inside chroot.""" | |
| 348 return os.path.exists('/etc/debian_chroot') | |
| 349 | |
| 350 | |
| 351 # TODO(sosa): Remove once all callers use method. | |
| 352 CROSUTILS_DIRECTORY = GetCrosUtilsPath(True) | |
|
petkov
2011/03/28 20:48:56
you can still keep the constant at the beginning o
sosa
2011/03/28 20:57:34
I thought so too, but python complains. It's prob
| |
| OLD | NEW |