Permalink
Browse files

Notify the user when the transifex host needs to be changed in the co…

…nfiguration instead of doing it automatically.

A prompt will appear when a user is running it interactively.
  • Loading branch information...
1 parent 38f10d3 commit 2d04b62fb6f9a8dfde1afffb020941f6bc3c42c9 Vrachnis Ilias-Dimitrios committed with vrachnis Apr 24, 2012
Showing with 30 additions and 2 deletions.
  1. +7 −2 txclib/project.py
  2. +23 −0 txclib/utils.py
View
@@ -86,9 +86,14 @@ def _get_transifex_config(self, txrc_file):
orig_hostname = txrc.get(section, 'hostname')
hostname = visit_hostname(orig_hostname)
if hostname != orig_hostname:
- msg = "Changing hostname %s to %s."
+ msg = "Hostname %s should be changed to %s."
logger.info(msg % (orig_hostname, hostname))
- txrc.set(section, 'hostname', hostname)
+ if sys.stdin.isatty() and confirm('Change it now?', default=True):
+ txrc.set(section, 'hostname', hostname)
+ msg = 'Hostname changed'
+ logger.info(msg)
+ else:
+ hostname = orig_hostname
self._save_txrc_file(txrc)
return txrc
View
@@ -154,6 +154,29 @@ def mkdir_p(path):
raise
+def confirm(prompt='Continue?', default=True):
+ """
+ Prompt the user for a Yes/No answer.
+
+ Args:
+ prompt: The text displayed to the user ([Y/n] will be appended)
+ default: If the default value will be yes or no
+ """
+ valid_yes = ['Y', 'y', 'Yes', 'yes', ]
+ valid_no = ['N', 'n', 'No', 'no', ]
+ if default:
+ prompt = prompt + '[Y/n]'
+ valid_yes.append('')
+ else:
+ prompt = prompt + '[y/N]'
+ valid_no.append('')
+
+ ans = raw_input(prompt)
+ while (ans not in valid_yes and ans not in valid_no):
+ ans = raw_input(prompt)
+
+ return ans in valid_yes
+
# Stuff for command line colored output

0 comments on commit 2d04b62

Please sign in to comment.