##// END OF EJS Templates
scmutil: narrow ImportError handling in termwidth()...
Yuya Nishihara -
r30311:80708959 default
parent child Browse files
Show More
@@ -1,72 +1,72 b''
1 1 from __future__ import absolute_import
2 2
3 import array
3 4 import errno
4 5 import fcntl
5 6 import os
6 7 import sys
7 8
8 9 from . import (
9 10 encoding,
10 11 osutil,
11 12 )
12 13
13 14 def _rcfiles(path):
14 15 rcs = [os.path.join(path, 'hgrc')]
15 16 rcdir = os.path.join(path, 'hgrc.d')
16 17 try:
17 18 rcs.extend([os.path.join(rcdir, f)
18 19 for f, kind in osutil.listdir(rcdir)
19 20 if f.endswith(".rc")])
20 21 except OSError:
21 22 pass
22 23 return rcs
23 24
24 25 def systemrcpath():
25 26 path = []
26 27 if sys.platform == 'plan9':
27 28 root = 'lib/mercurial'
28 29 else:
29 30 root = 'etc/mercurial'
30 31 # old mod_python does not set sys.argv
31 32 if len(getattr(sys, 'argv', [])) > 0:
32 33 p = os.path.dirname(os.path.dirname(sys.argv[0]))
33 34 if p != '/':
34 35 path.extend(_rcfiles(os.path.join(p, root)))
35 36 path.extend(_rcfiles('/' + root))
36 37 return path
37 38
38 39 def userrcpath():
39 40 if sys.platform == 'plan9':
40 41 return [encoding.environ['home'] + '/lib/hgrc']
41 42 else:
42 43 return [os.path.expanduser('~/.hgrc')]
43 44
44 45 def termwidth(ui):
45 46 try:
46 import array
47 47 import termios
48 TIOCGWINSZ = termios.TIOCGWINSZ # unavailable on IRIX (issue3449)
49 except (AttributeError, ImportError):
50 return 80
51 if True:
48 52 for dev in (ui.ferr, ui.fout, ui.fin):
49 53 try:
50 54 try:
51 55 fd = dev.fileno()
52 56 except AttributeError:
53 57 continue
54 58 if not os.isatty(fd):
55 59 continue
56 try:
57 arri = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 8)
60 if True:
61 arri = fcntl.ioctl(fd, TIOCGWINSZ, '\0' * 8)
58 62 width = array.array('h', arri)[1]
59 63 if width > 0:
60 64 return width
61 except AttributeError:
62 pass
63 65 except ValueError:
64 66 pass
65 67 except IOError as e:
66 68 if e[0] == errno.EINVAL:
67 69 pass
68 70 else:
69 71 raise
70 except ImportError:
71 pass
72 72 return 80
General Comments 0
You need to be logged in to leave comments. Login now