Skip to content
This repository
Browse code

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...
commit 2d04b62fb6f9a8dfde1afffb020941f6bc3c42c9 1 parent 38f10d3
vrachnis vrachnis authored vrachnis committed

Showing 2 changed files with 30 additions and 2 deletions. Show diff stats Hide diff stats

  1. +7 2 txclib/project.py
  2. +23 0 txclib/utils.py
9 txclib/project.py
@@ -86,9 +86,14 @@ def _get_transifex_config(self, txrc_file):
86 86 orig_hostname = txrc.get(section, 'hostname')
87 87 hostname = visit_hostname(orig_hostname)
88 88 if hostname != orig_hostname:
89   - msg = "Changing hostname %s to %s."
  89 + msg = "Hostname %s should be changed to %s."
90 90 logger.info(msg % (orig_hostname, hostname))
91   - txrc.set(section, 'hostname', hostname)
  91 + if sys.stdin.isatty() and confirm('Change it now?', default=True):
  92 + txrc.set(section, 'hostname', hostname)
  93 + msg = 'Hostname changed'
  94 + logger.info(msg)
  95 + else:
  96 + hostname = orig_hostname
92 97 self._save_txrc_file(txrc)
93 98 return txrc
94 99
23 txclib/utils.py
@@ -154,6 +154,29 @@ def mkdir_p(path):
154 154 raise
155 155
156 156
  157 +def confirm(prompt='Continue?', default=True):
  158 + """
  159 + Prompt the user for a Yes/No answer.
  160 +
  161 + Args:
  162 + prompt: The text displayed to the user ([Y/n] will be appended)
  163 + default: If the default value will be yes or no
  164 + """
  165 + valid_yes = ['Y', 'y', 'Yes', 'yes', ]
  166 + valid_no = ['N', 'n', 'No', 'no', ]
  167 + if default:
  168 + prompt = prompt + '[Y/n]'
  169 + valid_yes.append('')
  170 + else:
  171 + prompt = prompt + '[y/N]'
  172 + valid_no.append('')
  173 +
  174 + ans = raw_input(prompt)
  175 + while (ans not in valid_yes and ans not in valid_no):
  176 + ans = raw_input(prompt)
  177 +
  178 + return ans in valid_yes
  179 +
157 180
158 181 # Stuff for command line colored output
159 182

0 comments on commit 2d04b62

Please sign in to comment.
Something went wrong with that request. Please try again.