scripts/release/release.py
changeset 1846 ac30e04bcbba
parent 1835 3f30b7b14c57
child 1847 15ad1ee02dc5
equal deleted inserted replaced
1845:2651cb3979db 1846:ac30e04bcbba
    44 import functools
    44 import functools
    45 import os
    45 import os
    46 import re
    46 import re
    47 import subprocess
    47 import subprocess
    48 import sys
    48 import sys
       
    49 import threading
    49 
    50 
    50 import error
    51 import error
    51 import log
    52 import log
    52 import util
    53 import util
    53 
    54 
    81 
    82 
    82 class FileAccessError(Error):
    83 class FileAccessError(Error):
    83   """An error occured while accessing a file."""
    84   """An error occured while accessing a file."""
    84 
    85 
    85 
    86 
       
    87 def getString(prompt):
       
    88   """Prompt for and return a string."""
       
    89   prompt += ' '
       
    90   log.stdout.write(prompt)
       
    91   log.stdout.flush()
       
    92 
       
    93   response = sys.stdin.readline()
       
    94   log.terminal_echo(prompt + response.strip())
       
    95   if not response:
       
    96     raise AbortedByUser('Aborted by ctrl+D')
       
    97 
       
    98   return response.strip()
       
    99 
       
   100 
    86 def confirm(prompt, default=False):
   101 def confirm(prompt, default=False):
    87   """Ask a yes/no question and return the answer.
   102   """Ask a yes/no question and return the answer.
    88 
   103 
    89   Will reprompt the user until one of "yes", "no", "y" or "n" is
   104   Will reprompt the user until one of "yes", "no", "y" or "n" is
    90   entered. The input is case insensitive.
   105   entered. The input is case insensitive.
    95 
   110 
    96   Returns:
   111   Returns:
    97     True if the user answered affirmatively, False otherwise.
   112     True if the user answered affirmatively, False otherwise.
    98   """
   113   """
    99   if default:
   114   if default:
   100     question = prompt + ' [Yn] '
   115     question = prompt + ' [Yn]'
   101   else:
   116   else:
   102     question = prompt + ' [yN] '
   117     question = prompt + ' [yN]'
   103   while True:
   118   while True:
   104     try:
   119     answer = getString(question)
   105       answer = raw_input(question).strip().lower()
       
   106     except EOFError:
       
   107       raise AbortedByUser('Aborted by ctrl+D')
       
   108     if not answer:
   120     if not answer:
   109       return default
   121       return default
   110     elif answer in ('y', 'yes'):
   122     elif answer in ('y', 'yes'):
   111       return True
   123       return True
   112     elif answer in ('n', 'no'):
   124     elif answer in ('n', 'no'):
   113       return False
   125       return False
   114     else:
   126     else:
   115       log.error('Please answer yes or no.')
   127       log.error('Please answer yes or no.')
   116 
       
   117 
       
   118 def getString(prompt):
       
   119   """Prompt for and return a string."""
       
   120   try:
       
   121     return raw_input(prompt + ' ').strip()
       
   122   except EOFError:
       
   123     raise AbortedByUser('Aborted by ctrl+D')
       
   124 
   128 
   125 
   129 
   126 def getNumber(prompt):
   130 def getNumber(prompt):
   127   """Prompt for and return a number.
   131   """Prompt for and return a number.
   128 
   132