Mercurial > hg
comparison contrib/simplemerge @ 45055:4c1b4805db57
pycompat: change users of pycompat.{stdin,stdout,stderr} to use procutil.std*
On Python 3, pycompat.{stdin,stdout,stderr} are usually block-buffered even if
connected to a TTY. procutil.{stdin,stdout,stderr} provide consistent behavior
across platforms and Python versions.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Mon, 06 Jul 2020 17:44:25 +0200 |
parents | 99e231afc29c |
children | c102b704edb5 |
comparison
equal
deleted
inserted
replaced
45054:922dbf0df4f1 | 45055:4c1b4805db57 |
---|---|
43 class ParseError(Exception): | 43 class ParseError(Exception): |
44 """Exception raised on errors in parsing the command line.""" | 44 """Exception raised on errors in parsing the command line.""" |
45 | 45 |
46 | 46 |
47 def showhelp(): | 47 def showhelp(): |
48 pycompat.stdout.write(usage) | 48 procutil.stdout.write(usage) |
49 pycompat.stdout.write(b'\noptions:\n') | 49 procutil.stdout.write(b'\noptions:\n') |
50 | 50 |
51 out_opts = [] | 51 out_opts = [] |
52 for shortopt, longopt, default, desc in options: | 52 for shortopt, longopt, default, desc in options: |
53 out_opts.append( | 53 out_opts.append( |
54 ( | 54 ( |
60 b'%s' % desc, | 60 b'%s' % desc, |
61 ) | 61 ) |
62 ) | 62 ) |
63 opts_len = max([len(opt[0]) for opt in out_opts]) | 63 opts_len = max([len(opt[0]) for opt in out_opts]) |
64 for first, second in out_opts: | 64 for first, second in out_opts: |
65 pycompat.stdout.write(b' %-*s %s\n' % (opts_len, first, second)) | 65 procutil.stdout.write(b' %-*s %s\n' % (opts_len, first, second)) |
66 | 66 |
67 | 67 |
68 try: | 68 try: |
69 for fp in (sys.stdin, pycompat.stdout, sys.stderr): | 69 for fp in (sys.stdin, procutil.stdout, sys.stderr): |
70 procutil.setbinary(fp) | 70 procutil.setbinary(fp) |
71 | 71 |
72 opts = {} | 72 opts = {} |
73 try: | 73 try: |
74 bargv = [a.encode('utf8') for a in sys.argv[1:]] | 74 bargv = [a.encode('utf8') for a in sys.argv[1:]] |
90 **pycompat.strkwargs(opts) | 90 **pycompat.strkwargs(opts) |
91 ) | 91 ) |
92 ) | 92 ) |
93 except ParseError as e: | 93 except ParseError as e: |
94 e = stringutil.forcebytestr(e) | 94 e = stringutil.forcebytestr(e) |
95 pycompat.stdout.write(b"%s: %s\n" % (sys.argv[0].encode('utf8'), e)) | 95 procutil.stdout.write(b"%s: %s\n" % (sys.argv[0].encode('utf8'), e)) |
96 showhelp() | 96 showhelp() |
97 sys.exit(1) | 97 sys.exit(1) |
98 except error.Abort as e: | 98 except error.Abort as e: |
99 pycompat.stderr.write(b"abort: %s\n" % e) | 99 procutil.stderr.write(b"abort: %s\n" % e) |
100 sys.exit(255) | 100 sys.exit(255) |
101 except KeyboardInterrupt: | 101 except KeyboardInterrupt: |
102 sys.exit(255) | 102 sys.exit(255) |