From ab85fe7c535bfa97c067354d8a23e39b849f6728 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 4 Jul 2019 17:35:11 -0400 Subject: 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 Reviewed-by: David Pursehouse --- subcmds/init.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'subcmds/init.py') 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. sys.exit(1) def _Prompt(self, prompt, value): - sys.stdout.write('%-10s [%s]: ' % (prompt, value)) + print('%-10s [%s]: ' % (prompt, value), end='') + # TODO: When we require Python 3, use flush=True w/print above. + sys.stdout.flush() a = sys.stdin.readline().strip() if a == '': return value @@ -328,7 +330,9 @@ to update the working directory files. print() print('Your identity is: %s <%s>' % (name, email)) - sys.stdout.write('is this correct [y/N]? ') + print('is this correct [y/N]? ', end='') + # TODO: When we require Python 3, use flush=True w/print above. + sys.stdout.flush() a = sys.stdin.readline().strip().lower() if a in ('yes', 'y', 't', 'true'): break @@ -370,7 +374,9 @@ to update the working directory files. out.printer(fg='black', attr=c)(' %-6s ', c) out.nl() - sys.stdout.write('Enable color display in this user account (y/N)? ') + print('Enable color display in this user account (y/N)? ', end='') + # TODO: When we require Python 3, use flush=True w/print above. + sys.stdout.flush() a = sys.stdin.readline().strip().lower() if a in ('y', 'yes', 't', 'true', 'on'): gc.SetString('color.ui', 'auto') -- cgit v1.2.3-54-g00ecf