Skip to content

Commit

Permalink
Avoid prompt on non interactive console
Browse files Browse the repository at this point in the history
Change-Id: Ice7078eb6b2b6f60af8178e13c852d42ce73529b
  • Loading branch information
ssbarnea authored and Gerrit Code Review committed Jun 1, 2017
1 parent 2c0d003 commit 0901114
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions rdopkg/helpers.py
Expand Up @@ -3,6 +3,7 @@
import contextlib
import os
import re
import sys
import yaml

from rdopkg import exception
Expand All @@ -11,20 +12,26 @@


def confirm(msg, default_yes=True):
if default_yes:
options = '[Yn]'
if sys.stdout.isatty():
if default_yes:
options = '[Yn]'
else:
options = '[Ny]'
print('')
i = raw_input(log.term.important("%s %s " % (msg, options))).lower()
if not i:
if default_yes:
return
else:
raise exception.UserAbort()
if i != 'y' and i != 'yes':
raise exception.UserAbort()
print('')
else:
options = '[Ny]'
print('')
i = raw_input(log.term.important("%s %s " % (msg, options))).lower()
if not i:
if default_yes:
return
else:
raise exception.UserAbort()
if i != 'y' and i != 'yes':
raise exception.UserAbort()
print('')


def download_file(url):
Expand Down

0 comments on commit 0901114

Please sign in to comment.