OLD | NEW |
(Empty) | |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import os |
| 6 import subprocess |
| 7 |
| 8 from infra.tools.cros_pin.logger import LOGGER |
| 9 |
| 10 |
| 11 def call(cmd, cwd=None, dry_run=False): |
| 12 LOGGER.info("Executing command %s (cwd=%s)", cmd, (cwd or os.getcwd())) |
| 13 if dry_run: |
| 14 LOGGER.info('Dry Run: Not actually executing.') |
| 15 return (0, "") |
| 16 |
| 17 output = [] |
| 18 proc = subprocess.Popen( |
| 19 cmd, |
| 20 stdout=subprocess.PIPE, |
| 21 stderr=subprocess.STDOUT, |
| 22 cwd=cwd) |
| 23 |
| 24 for line in iter(proc.stdout.readline, b''): |
| 25 LOGGER.debug('[%s]: %s', cmd[0], line.rstrip()) |
| 26 output.append(line) |
| 27 proc.wait() |
| 28 |
| 29 return proc.returncode, ''.join(output) |
| 30 |
| 31 |
| 32 def check_call(cmd, **kwargs): |
| 33 rv, stdout = call(cmd, **kwargs) |
| 34 if rv != 0: |
| 35 raise subprocess.CalledProcessError(rv, cmd, None) |
| 36 return stdout |
OLD | NEW |