summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2019-07-04 17:35:11 -0400
committerDavid Pursehouse <dpursehouse@collab.net>2019-07-11 06:26:40 +0000
commitab85fe7c535bfa97c067354d8a23e39b849f6728 (patch)
tree3de17ed8b68af5cef82eaf5553ca3de41bd7e955
parent4f42a9706715c9c5add46632343f7108aabcd530 (diff)
downloadgit-repo-ab85fe7c535bfa97c067354d8a23e39b849f6728.tar.gz
use print() instead of sys.stdout.write()
We're relying on sys.stdout.write() to flush its buffer which isn't guaranteed, and is not the case in Python 3. Change to use print() everywhere to be standard, and utilize the end= keyword to get the EOL semantics we need. We can't use print's flush= keyword as that's only in Python 3. Leave behind a TODO to clean it up when we can drop Python 2. Bug: https://crbug.com/gerrit/10418 Change-Id: I562128c7f1e6d154f4a6ecdf33a70fa2811dc2af Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/230392 Tested-by: Mike Frysinger <vapier@google.com> Reviewed-by: David Pursehouse <dpursehouse@collab.net>
-rw-r--r--subcmds/init.py12
-rw-r--r--subcmds/upload.py15
2 files changed, 19 insertions, 8 deletions
diff --git a/subcmds/init.py b/subcmds/init.py
index 6c8b1ddc..1c809ab4 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -294,7 +294,9 @@ to update the working directory files.
294 sys.exit(1) 294 sys.exit(1)
295 295
296 def _Prompt(self, prompt, value): 296 def _Prompt(self, prompt, value):
297 sys.stdout.write('%-10s [%s]: ' % (prompt, value)) 297 print('%-10s [%s]: ' % (prompt, value), end='')
298 # TODO: When we require Python 3, use flush=True w/print above.
299 sys.stdout.flush()
298 a = sys.stdin.readline().strip() 300 a = sys.stdin.readline().strip()
299 if a == '': 301 if a == '':
300 return value 302 return value
@@ -328,7 +330,9 @@ to update the working directory files.
328 330
329 print() 331 print()
330 print('Your identity is: %s <%s>' % (name, email)) 332 print('Your identity is: %s <%s>' % (name, email))
331 sys.stdout.write('is this correct [y/N]? ') 333 print('is this correct [y/N]? ', end='')
334 # TODO: When we require Python 3, use flush=True w/print above.
335 sys.stdout.flush()
332 a = sys.stdin.readline().strip().lower() 336 a = sys.stdin.readline().strip().lower()
333 if a in ('yes', 'y', 't', 'true'): 337 if a in ('yes', 'y', 't', 'true'):
334 break 338 break
@@ -370,7 +374,9 @@ to update the working directory files.
370 out.printer(fg='black', attr=c)(' %-6s ', c) 374 out.printer(fg='black', attr=c)(' %-6s ', c)
371 out.nl() 375 out.nl()
372 376
373 sys.stdout.write('Enable color display in this user account (y/N)? ') 377 print('Enable color display in this user account (y/N)? ', end='')
378 # TODO: When we require Python 3, use flush=True w/print above.
379 sys.stdout.flush()
374 a = sys.stdin.readline().strip().lower() 380 a = sys.stdin.readline().strip().lower()
375 if a in ('y', 'yes', 't', 'true', 'on'): 381 if a in ('y', 'yes', 't', 'true', 'on'):
376 gc.SetString('color.ui', 'auto') 382 gc.SetString('color.ui', 'auto')
diff --git a/subcmds/upload.py b/subcmds/upload.py
index e7e5b1bf..d0dd3837 100644
--- a/subcmds/upload.py
+++ b/subcmds/upload.py
@@ -221,7 +221,9 @@ Gerrit Code Review: https://www.gerritcodereview.com/
221 for commit in commit_list: 221 for commit in commit_list:
222 print(' %s' % commit) 222 print(' %s' % commit)
223 223
224 sys.stdout.write('to %s (y/N)? ' % remote.review) 224 print('to %s (y/N)? ' % remote.review, end='')
225 # TODO: When we require Python 3, use flush=True w/print above.
226 sys.stdout.flush()
225 answer = sys.stdin.readline().strip().lower() 227 answer = sys.stdin.readline().strip().lower()
226 answer = answer in ('y', 'yes', '1', 'true', 't') 228 answer = answer in ('y', 'yes', '1', 'true', 't')
227 229
@@ -360,10 +362,13 @@ Gerrit Code Review: https://www.gerritcodereview.com/
360 362
361 # if they want to auto upload, let's not ask because it could be automated 363 # if they want to auto upload, let's not ask because it could be automated
362 if answer is None: 364 if answer is None:
363 sys.stdout.write('Uncommitted changes in ' + branch.project.name) 365 print()
364 sys.stdout.write(' (did you forget to amend?):\n') 366 print('Uncommitted changes in %s (did you forget to amend?):'
365 sys.stdout.write('\n'.join(changes) + '\n') 367 % branch.project.name)
366 sys.stdout.write('Continue uploading? (y/N) ') 368 print('\n'.join(changes))
369 print('Continue uploading? (y/N) ', end='')
370 # TODO: When we require Python 3, use flush=True w/print above.
371 sys.stdout.flush()
367 a = sys.stdin.readline().strip().lower() 372 a = sys.stdin.readline().strip().lower()
368 if a not in ('y', 'yes', 't', 'true', 'on'): 373 if a not in ('y', 'yes', 't', 'true', 'on'):
369 print("skipping upload", file=sys.stderr) 374 print("skipping upload", file=sys.stderr)