diff options
author | cmtice <cmtice@google.com> | 2015-04-22 09:25:53 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-04-26 04:18:33 +0000 |
commit | 5c09fc2966ac49263ce7154c2905f2a86aeda297 (patch) | |
tree | afb3ec9829c59f98cf1cabdc2a26c71465cf9153 /utils | |
parent | d7d5084ffa40651b5adbaea4f4659a51e1045f06 (diff) | |
download | toolchain-utils-5c09fc2966ac49263ce7154c2905f2a86aeda297.tar.gz |
Fix current problem with machine locks.
Currently if crosperf can't access the default locks directory, it
assumes that it is safe to proceed without locks and it uses machines
without checking locks. This script does two things: It causes
crosperf to fail if it can't access a locks directory; and it allows
the user to specify an alternate locks directory. As a by-product it
also adds a boolean prompting function to utils/misc.py
BUG=None
TEST=Tested with default directory accessible & inaccessible; tested using
local locks directory.
Change-Id: I6f24f772986813bf089f5f4e40335a15e8ee4837
Reviewed-on: https://chrome-internal-review.googlesource.com/214129
Reviewed-by: Luis Lozano <llozano@chromium.org>
Commit-Queue: Caroline Tice <cmtice@google.com>
Tested-by: Caroline Tice <cmtice@google.com>
Diffstat (limited to 'utils')
-rw-r--r-- | utils/misc.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/utils/misc.py b/utils/misc.py index 064d7b28..6ebef65f 100644 --- a/utils/misc.py +++ b/utils/misc.py @@ -550,3 +550,56 @@ def ApplyGerritPatches(chromeos_root, logger.GetLogger().LogError('Failed to apply patch "{0}"'.format(pi_str)) return False return True + + +def BooleanPrompt(prompt='Do you want to continue?', default=True, + true_value='yes', false_value='no', prolog=None): + """Helper function for processing boolean choice prompts. + + Args: + prompt: The question to present to the user. + default: Boolean to return if the user just presses enter. + true_value: The text to display that represents a True returned. + false_value: The text to display that represents a False returned. + prolog: The text to display before prompt. + + Returns: + True or False. + """ + true_value, false_value = true_value.lower(), false_value.lower() + true_text, false_text = true_value, false_value + if true_value == false_value: + raise ValueError('true_value and false_value must differ: got %r' + % true_value) + + if default: + true_text = true_text[0].upper() + true_text[1:] + else: + false_text = false_text[0].upper() + false_text[1:] + + prompt = ('\n%s (%s/%s)? ' % (prompt, true_text, false_text)) + + if prolog: + prompt = ('\n%s\n%s' % (prolog, prompt)) + + while True: + try: + response = raw_input(prompt).lower() + except EOFError: + # If the user hits CTRL+D, or stdin is disabled, use the default. + print() + response = None + except KeyboardInterrupt: + # If the user hits CTRL+C, just exit the process. + print() + Die('CTRL+C detected; exiting') + + if not response: + return default + if true_value.startswith(response): + if not false_value.startswith(response): + return True + # common prefix between the two... + elif false_value.startswith(response): + return False + |