Wrap raw_input() around a try/except to reduce the number of false-positive in breakpad

R=dpranke@chromium.org
BUG=
TEST=

Review URL: http://codereview.chromium.org/6706007

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@80182 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
maruel@chromium.org 14 years ago
parent 421982fe08
commit 90541738bc

@ -8,6 +8,7 @@ import logging
import os import os
import posixpath import posixpath
import re import re
import sys
import time import time
import scm import scm
@ -49,6 +50,14 @@ class DiffFilterer(object):
print(line) print(line)
def ask_for_data(prompt):
try:
return raw_input(prompt)
except KeyboardInterrupt:
# Hide the exception.
sys.exit(1)
### SCM abstraction layer ### SCM abstraction layer
# Factory Method for SCM wrapper creation # Factory Method for SCM wrapper creation
@ -353,11 +362,11 @@ class GitWrapper(SCMWrapper):
while True: while True:
try: try:
# TODO(maruel): That can't work with --jobs. # TODO(maruel): That can't work with --jobs.
action = str(raw_input("Cannot fast-forward merge, attempt to " action = ask_for_data(
"rebase? (y)es / (q)uit / (s)kip : ")) 'Cannot fast-forward merge, attempt to rebase? '
'(y)es / (q)uit / (s)kip : ')
except ValueError: except ValueError:
gclient_utils.Error('Invalid Character') raise gclient_utils.Error('Invalid Character')
continue
if re.match(r'yes|y', action, re.I): if re.match(r'yes|y', action, re.I):
self._AttemptRebase(upstream_branch, files, options, self._AttemptRebase(upstream_branch, files, options,
printed_path=printed_path) printed_path=printed_path)
@ -540,11 +549,11 @@ class GitWrapper(SCMWrapper):
re.match(r'cannot rebase: your index contains uncommitted changes', re.match(r'cannot rebase: your index contains uncommitted changes',
e.stderr)): e.stderr)):
while True: while True:
rebase_action = str(raw_input("Cannot rebase because of unstaged " rebase_action = ask_for_data(
"changes.\n'git reset --hard HEAD' ?\n" 'Cannot rebase because of unstaged changes.\n'
"WARNING: destroys any uncommitted " '\'git reset --hard HEAD\' ?\n'
"work in your current branch!" 'WARNING: destroys any uncommitted work in your current branch!'
" (y)es / (q)uit / (s)how : ")) ' (y)es / (q)uit / (s)how : ')
if re.match(r'yes|y', rebase_action, re.I): if re.match(r'yes|y', rebase_action, re.I):
self._Run(['reset', '--hard', 'HEAD'], options) self._Run(['reset', '--hard', 'HEAD'], options)
# Should this be recursive? # Should this be recursive?

@ -43,6 +43,7 @@ DEFAULT_SERVER = 'http://codereview.appspot.com'
POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s' POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s'
DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup' DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup'
def DieWithError(message): def DieWithError(message):
print >> sys.stderr, message print >> sys.stderr, message
sys.exit(1) sys.exit(1)
@ -98,6 +99,14 @@ def usage(more):
return hook return hook
def ask_for_data(prompt):
try:
return raw_input(prompt)
except KeyboardInterrupt:
# Hide the exception.
sys.exit(1)
def FixUrl(server): def FixUrl(server):
"""Fix a server url to defaults protocol to http:// if none is specified.""" """Fix a server url to defaults protocol to http:// if none is specified."""
if not server: if not server:
@ -526,7 +535,7 @@ def GetCodereviewSettingsInteractively():
server = settings.GetDefaultServerUrl(error_ok=True) server = settings.GetDefaultServerUrl(error_ok=True)
prompt = 'Rietveld server (host[:port])' prompt = 'Rietveld server (host[:port])'
prompt += ' [%s]' % (server or DEFAULT_SERVER) prompt += ' [%s]' % (server or DEFAULT_SERVER)
newserver = raw_input(prompt + ': ') newserver = ask_for_data(prompt + ':')
if not server and not newserver: if not server and not newserver:
newserver = DEFAULT_SERVER newserver = DEFAULT_SERVER
if newserver and newserver != server: if newserver and newserver != server:
@ -536,7 +545,7 @@ def GetCodereviewSettingsInteractively():
prompt = caption prompt = caption
if initial: if initial:
prompt += ' ("x" to clear) [%s]' % initial prompt += ' ("x" to clear) [%s]' % initial
new_val = raw_input(prompt + ': ') new_val = ask_for_data(prompt + ':')
if new_val == 'x': if new_val == 'x':
RunGit(['config', '--unset-all', 'rietveld.' + name], error_ok=True) RunGit(['config', '--unset-all', 'rietveld.' + name], error_ok=True)
elif new_val and new_val != initial: elif new_val and new_val != initial:
@ -1113,7 +1122,7 @@ def SendUpstream(parser, args, cmd):
branches = [base_branch, cl.GetBranchRef()] branches = [base_branch, cl.GetBranchRef()]
if not options.force: if not options.force:
subprocess.call(['git', 'diff', '--stat'] + branches) subprocess.call(['git', 'diff', '--stat'] + branches)
raw_input("About to commit; enter to confirm.") ask_for_data('About to commit; enter to confirm.')
# We want to squash all this branch's commits into one commit with the # We want to squash all this branch's commits into one commit with the
# proper description. # proper description.
@ -1198,7 +1207,7 @@ to run 'git cl push' instead.
Choose wisely, if you get this wrong, your commit might appear to succeed but Choose wisely, if you get this wrong, your commit might appear to succeed but
will instead be silently ignored.""" will instead be silently ignored."""
print(message) print(message)
raw_input('[Press enter to dcommit or ctrl-C to quit]') ask_for_data('[Press enter to dcommit or ctrl-C to quit]')
return SendUpstream(parser, args, 'dcommit') return SendUpstream(parser, args, 'dcommit')
@ -1208,7 +1217,7 @@ def CMDpush(parser, args):
if settings.GetIsGitSvn(): if settings.GetIsGitSvn():
print('This appears to be an SVN repository.') print('This appears to be an SVN repository.')
print('Are you sure you didn\'t mean \'git cl dcommit\'?') print('Are you sure you didn\'t mean \'git cl dcommit\'?')
raw_input('[Press enter to push or ctrl-C to quit]') ask_for_data('[Press enter to push or ctrl-C to quit]')
return SendUpstream(parser, args, 'push') return SendUpstream(parser, args, 'push')

Loading…
Cancel
Save