Mercurial > public > mercurial-scm > hg
comparison mercurial/scmposix.py @ 30311:80708959161a
scmutil: narrow ImportError handling in termwidth()
The array module must exist. It's sufficient to suppress the ImportError of
termios. Also salvaged the comment why we have to handle AttributeError, from
7002bb17cc5e.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 20 Oct 2016 21:50:29 +0900 |
parents | 5c379b1f56c7 |
children | 1ad1c5017043 |
comparison
equal
deleted
inserted
replaced
30310:5c379b1f56c7 | 30311:80708959161a |
---|---|
1 from __future__ import absolute_import | 1 from __future__ import absolute_import |
2 | 2 |
3 import array | |
3 import errno | 4 import errno |
4 import fcntl | 5 import fcntl |
5 import os | 6 import os |
6 import sys | 7 import sys |
7 | 8 |
41 else: | 42 else: |
42 return [os.path.expanduser('~/.hgrc')] | 43 return [os.path.expanduser('~/.hgrc')] |
43 | 44 |
44 def termwidth(ui): | 45 def termwidth(ui): |
45 try: | 46 try: |
46 import array | |
47 import termios | 47 import termios |
48 TIOCGWINSZ = termios.TIOCGWINSZ # unavailable on IRIX (issue3449) | |
49 except (AttributeError, ImportError): | |
50 return 80 | |
51 if True: | |
48 for dev in (ui.ferr, ui.fout, ui.fin): | 52 for dev in (ui.ferr, ui.fout, ui.fin): |
49 try: | 53 try: |
50 try: | 54 try: |
51 fd = dev.fileno() | 55 fd = dev.fileno() |
52 except AttributeError: | 56 except AttributeError: |
53 continue | 57 continue |
54 if not os.isatty(fd): | 58 if not os.isatty(fd): |
55 continue | 59 continue |
56 try: | 60 if True: |
57 arri = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 8) | 61 arri = fcntl.ioctl(fd, TIOCGWINSZ, '\0' * 8) |
58 width = array.array('h', arri)[1] | 62 width = array.array('h', arri)[1] |
59 if width > 0: | 63 if width > 0: |
60 return width | 64 return width |
61 except AttributeError: | |
62 pass | |
63 except ValueError: | 65 except ValueError: |
64 pass | 66 pass |
65 except IOError as e: | 67 except IOError as e: |
66 if e[0] == errno.EINVAL: | 68 if e[0] == errno.EINVAL: |
67 pass | 69 pass |
68 else: | 70 else: |
69 raise | 71 raise |
70 except ImportError: | |
71 pass | |
72 return 80 | 72 return 80 |