Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(491)

Side by Side Diff: infra/tools/cros_pin/execute.py

Issue 1403313002: Added `cros_pin` CrOS pin-bump tool. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: contextmanager, cleanup. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698