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

Unified Diff: chromite/lib/cros_build_lib.py

Issue 6005004: WIP Chromite supporting "LEGACY" mode, as requested by Anush. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: Created 10 years 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 side-by-side diff with in-line comments
Download patch
Index: chromite/lib/cros_build_lib.py
diff --git a/chromite/lib/cros_build_lib.py b/chromite/lib/cros_build_lib.py
index 87fa133b75cab27180bd1c575ec2fe655fc78e45..ae74f8e84a2ef27de15c0d12057ac995170b1e1a 100644
--- a/chromite/lib/cros_build_lib.py
+++ b/chromite/lib/cros_build_lib.py
@@ -6,6 +6,7 @@
import os
import re
+import signal
import subprocess
import sys
@@ -29,7 +30,8 @@ class RunCommandError(Exception):
def RunCommand(cmd, print_cmd=True, error_ok=False, error_message=None,
exit_code=False, redirect_stdout=False, redirect_stderr=False,
- cwd=None, input=None, enter_chroot=False, shell=False):
+ cwd=None, input=None, enter_chroot=False, shell=False,
+ ignore_sigint=False):
"""Runs a command.
Args:
@@ -46,6 +48,10 @@ def RunCommand(cmd, print_cmd=True, error_ok=False, error_message=None,
cwd must point to the scripts directory.
shell: If shell is True, the specified command will be executed through
the shell.
+ ignore_sigint: If True, we'll ignore signal.SIGINT before calling the
+ child. This is the desired behavior if we know our child will handle
+ Ctrl-C. If we don't do this, I think we and the child will both get
+ Ctrl-C at the same time, which means we'll forcefully kill the child.
Returns:
A CommandResult object.
@@ -80,7 +86,14 @@ def RunCommand(cmd, print_cmd=True, error_ok=False, error_message=None,
try:
proc = subprocess.Popen(cmd, cwd=cwd, stdin=stdin, stdout=stdout,
stderr=stderr, shell=shell)
- (cmd_result.output, cmd_result.error) = proc.communicate(input)
+ if ignore_sigint:
+ old_sigint = signal.signal(signal.SIGINT, signal.SIG_IGN)
+ try:
+ (cmd_result.output, cmd_result.error) = proc.communicate(input)
+ finally:
+ if ignore_sigint:
+ signal.signal(signal.SIGINT, old_sigint)
+
if exit_code:
cmd_result.returncode = proc.returncode
« chromite/chromite.sh ('K') | « chromite/chromite.sh ('k') | chromite/lib/text_menu.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698