diff options
Diffstat (limited to 'llvm_tools/subprocess_helpers.py')
-rw-r--r-- | llvm_tools/subprocess_helpers.py | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/llvm_tools/subprocess_helpers.py b/llvm_tools/subprocess_helpers.py index 8845112c..bc87db85 100644 --- a/llvm_tools/subprocess_helpers.py +++ b/llvm_tools/subprocess_helpers.py @@ -1,58 +1,59 @@ # -*- coding: utf-8 -*- -# Copyright 2019 The Chromium OS Authors. All rights reserved. +# Copyright 2019 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Helpers/wrappers for the subprocess module for migration to python3.""" -from __future__ import print_function import subprocess def CheckCommand(cmd): - """Executes the command using Popen().""" + """Executes the command using Popen().""" - cmd_obj = subprocess.Popen( - cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='UTF-8') + cmd_obj = subprocess.Popen( + cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="UTF-8" + ) - stdout, _ = cmd_obj.communicate() + stdout, _ = cmd_obj.communicate() - if cmd_obj.returncode: - print(stdout) - raise subprocess.CalledProcessError(cmd_obj.returncode, cmd) + if cmd_obj.returncode: + print(stdout) + raise subprocess.CalledProcessError(cmd_obj.returncode, cmd) def check_output(cmd, cwd=None): - """Wrapper for pre-python3 subprocess.check_output().""" + """Wrapper for pre-python3 subprocess.check_output().""" - return subprocess.check_output(cmd, encoding='UTF-8', cwd=cwd) + return subprocess.check_output(cmd, encoding="UTF-8", cwd=cwd) def check_call(cmd, cwd=None): - """Wrapper for pre-python3 subprocess.check_call().""" + """Wrapper for pre-python3 subprocess.check_call().""" - subprocess.check_call(cmd, encoding='UTF-8', cwd=cwd) + subprocess.check_call(cmd, encoding="UTF-8", cwd=cwd) # FIXME: CTRL+C does not work when executing a command inside the chroot via # `cros_sdk`. def ChrootRunCommand(chroot_path, cmd, verbose=False): - """Runs the command inside the chroot.""" + """Runs the command inside the chroot.""" - exec_chroot_cmd = ['cros_sdk', '--'] - exec_chroot_cmd.extend(cmd) + exec_chroot_cmd = ["cros_sdk", "--"] + exec_chroot_cmd.extend(cmd) - return ExecCommandAndCaptureOutput( - exec_chroot_cmd, cwd=chroot_path, verbose=verbose) + return ExecCommandAndCaptureOutput( + exec_chroot_cmd, cwd=chroot_path, verbose=verbose + ) def ExecCommandAndCaptureOutput(cmd, cwd=None, verbose=False): - """Executes the command and prints to stdout if possible.""" + """Executes the command and prints to stdout if possible.""" - out = check_output(cmd, cwd=cwd).rstrip() + out = check_output(cmd, cwd=cwd).rstrip() - if verbose and out: - print(out) + if verbose and out: + print(out) - return out + return out |