167
sys.stderr.write(msg + "\n")
168
sys.exit(1)
169
170
+def prompt(prompt_text):
171
+ """ Prompt the user to choose one of the choices
172
+
173
+ Choices are identified in the prompt_text by square brackets around
174
+ a single letter option.
175
+ """
176
+ choices = set(m.group(1) for m in re.finditer(r"\[(.)\]", prompt_text))
177
+ while True:
178
+ response = raw_input(prompt_text).strip().lower()
179
+ if not response:
180
+ continue
181
+ response = response[0]
182
+ if response in choices:
183
+ return response
184
+
185
def write_pipe(c, stdin):
186
if verbose:
187
sys.stderr.write('Writing pipe: %s\n' % str(c))
1793
if os.stat(template_file).st_mtime > mtime:
1794
return True
1795
1781
- while True:
1782
- response = raw_input("Submit template unchanged. Submit anyway? [y]es, [n]o (skip this patch) ")
1783
- if response == 'y':
1784
- return True
1785
- if response == 'n':
1786
- return False
1796
+ response = prompt("Submit template unchanged. Submit anyway? [y]es, [n]o (skip this patch) ")
1797
+ if response == 'y':
1798
+ return True
1799
+ if response == 'n':
1800
+ return False
1801
1802
def get_diff_description(self, editedFiles, filesToAdd, symlinks):
1803
# diff
2359
" --prepare-p4-only")
2360
break
2361
if i < last:
2348
- quit = False
2349
- while True:
2350
- # prompt for what to do, or use the option/variable
2351
- if self.conflict_behavior == "ask":
2352
- print("What do you want to do?")
2353
- response = raw_input("[s]kip this commit but apply"
2354
- " the rest, or [q]uit? ")
2355
- if not response:
2356
- continue
2357
- elif self.conflict_behavior == "skip":
2358
- response = "s"
2359
- elif self.conflict_behavior == "quit":
2360
- response = "q"
2361
- else:
2362
- die("Unknown conflict_behavior '%s'" %
2363
- self.conflict_behavior)
2364
-
2365
- if response[0] == "s":
2366
- print("Skipping this commit, but applying the rest")
2367
- break
2368
- if response[0] == "q":
2369
- print("Quitting")
2370
- quit = True
2371
- break
2372
- if quit:
2362
+ # prompt for what to do, or use the option/variable
2363
+ if self.conflict_behavior == "ask":
2364
+ print("What do you want to do?")
2365
+ response = prompt("[s]kip this commit but apply the rest, or [q]uit? ")
2366
+ elif self.conflict_behavior == "skip":
2367
+ response = "s"
2368
+ elif self.conflict_behavior == "quit":
2369
+ response = "q"
2370
+ else:
2371
+ die("Unknown conflict_behavior '%s'" %
2372
+ self.conflict_behavior)
2373
+
2374
+ if response == "s":
2375
+ print("Skipping this commit, but applying the rest")
2376
+ if response == "q":
2377
+ print("Quitting")
2378
break
2379
2380
chdir(self.oldWorkingDirectory)