Index: infra/tools/cros_pin/execute.py |
diff --git a/infra/tools/cros_pin/execute.py b/infra/tools/cros_pin/execute.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f770d248b3c5bfd03e94f008095d3f14cccb0db2 |
--- /dev/null |
+++ b/infra/tools/cros_pin/execute.py |
@@ -0,0 +1,36 @@ |
+# Copyright 2015 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import os |
+import subprocess |
+import threading |
ghost stip (do not use)
2015/10/15 20:02:54
remove unused import
|
+ |
+from infra.tools.cros_pin.logger import LOGGER |
+ |
+ |
+def call(cmd, cwd=None, dry_run=False): |
ghost stip (do not use)
2015/10/15 20:02:54
this whole function seems overkill. this is just t
dnj
2015/10/15 21:06:41
Well, execute stuff and:
1) Print output to STDERR
|
+ LOGGER.info("Executing command %s (cwd=%s)", cmd, (cwd or os.getcwd())) |
+ if dry_run: |
+ LOGGER.info('Dry Run: Not actually executing.') |
+ return (0, "") |
+ proc = subprocess.Popen( |
+ cmd, |
+ stdout=subprocess.PIPE, |
+ stderr=subprocess.STDOUT, |
+ cwd=cwd) |
+ |
+ output = [] |
+ for line in iter(proc.stdout.readline, b''): |
+ LOGGER.debug('[%s]: %s', cmd[0], line.rstrip()) |
+ output.append(line) |
+ |
+ proc.wait() |
+ return proc.returncode, ''.join(output) |
+ |
+ |
+def check_call(cmd, **kwargs): |
+ rv, stdout = call(cmd, **kwargs) |
+ if rv != 0: |
+ raise subprocess.CalledProcessError(rv, cmd, None) |
+ return stdout |