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.realpath(os.path.dirname(os.path.dirname( |
| 15 __file__))) |
14 | 16 |
15 # TODO(sosa): Move logging to logging module. | 17 # TODO(sosa): Move logging to logging module. |
16 | 18 |
17 class RunCommandException(Exception): | 19 class RunCommandException(Exception): |
18 """Raised when there is an error in RunCommand.""" | 20 """Raised when there is an error in RunCommand.""" |
19 pass | 21 pass |
20 | 22 |
21 | 23 |
22 def GetCallerName(): | 24 def GetCallerName(): |
23 """Returns the name of the calling module with __main__.""" | 25 """Returns the name of the calling module with __main__.""" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 either via a VM or remote machine on the same network. | 292 either via a VM or remote machine on the same network. |
291 """ | 293 """ |
292 ifconfig_output = RunCommand(['/sbin/ifconfig', device], | 294 ifconfig_output = RunCommand(['/sbin/ifconfig', device], |
293 redirect_stdout=True, print_cmd=False) | 295 redirect_stdout=True, print_cmd=False) |
294 match = re.search('.*inet addr:(\d+\.\d+\.\d+\.\d+).*', ifconfig_output) | 296 match = re.search('.*inet addr:(\d+\.\d+\.\d+\.\d+).*', ifconfig_output) |
295 if match: | 297 if match: |
296 return match.group(1) | 298 return match.group(1) |
297 else: | 299 else: |
298 Warning('Failed to find ip address in %s' % ifconfig_output) | 300 Warning('Failed to find ip address in %s' % ifconfig_output) |
299 return None | 301 return None |
| 302 |
| 303 |
| 304 def MountImage(image_path, root_dir, stateful_dir, read_only): |
| 305 """Mounts a Chromium OS image onto mount dir points.""" |
| 306 from_dir = os.path.dirname(image_path) |
| 307 image = os.path.basename(image_path) |
| 308 extra_args = [] |
| 309 if read_only: extra_args.append('--read_only') |
| 310 cmd = ['./mount_gpt_image.sh', |
| 311 '--from=%s' % from_dir, |
| 312 '--image=%s' % image, |
| 313 '--rootfs_mountpt=%s' % root_dir, |
| 314 '--stateful_mountpt=%s' % stateful_dir, |
| 315 ] |
| 316 cmd.extend(extra_args) |
| 317 RunCommand(cmd, print_cmd=False, redirect_stdout=True, redirect_stderr=True, |
| 318 cwd=_CROSUTILS_DIRECTORY) |
| 319 |
| 320 |
| 321 def UnmountImage(root_dir, stateful_dir): |
| 322 """Unmounts a Chromium OS image specified by mount dir points.""" |
| 323 RunCommand(['./mount_gpt_image.sh', |
| 324 '--unmount', |
| 325 '--rootfs_mountpt=%s' % root_dir, |
| 326 '--stateful_mountpt=%s' % stateful_dir, |
| 327 ], print_cmd=False, redirect_stdout=True, redirect_stderr=True, |
| 328 cwd=_CROSUTILS_DIRECTORY) |
OLD | NEW |