##// END OF EJS Templates
scmposix: another suppression on IOError subscripting...
Augie Fackler -
r43781:667f56d7 default
parent child Browse files
Show More
@@ -1,97 +1,97 b''
1 from __future__ import absolute_import
1 from __future__ import absolute_import
2
2
3 import array
3 import array
4 import errno
4 import errno
5 import fcntl
5 import fcntl
6 import os
6 import os
7 import sys
7 import sys
8
8
9 from .pycompat import getattr
9 from .pycompat import getattr
10 from . import (
10 from . import (
11 encoding,
11 encoding,
12 pycompat,
12 pycompat,
13 util,
13 util,
14 )
14 )
15
15
16 # BSD 'more' escapes ANSI color sequences by default. This can be disabled by
16 # BSD 'more' escapes ANSI color sequences by default. This can be disabled by
17 # $MORE variable, but there's no compatible option with Linux 'more'. Given
17 # $MORE variable, but there's no compatible option with Linux 'more'. Given
18 # OS X is widely used and most modern Unix systems would have 'less', setting
18 # OS X is widely used and most modern Unix systems would have 'less', setting
19 # 'less' as the default seems reasonable.
19 # 'less' as the default seems reasonable.
20 fallbackpager = b'less'
20 fallbackpager = b'less'
21
21
22
22
23 def _rcfiles(path):
23 def _rcfiles(path):
24 rcs = [os.path.join(path, b'hgrc')]
24 rcs = [os.path.join(path, b'hgrc')]
25 rcdir = os.path.join(path, b'hgrc.d')
25 rcdir = os.path.join(path, b'hgrc.d')
26 try:
26 try:
27 rcs.extend(
27 rcs.extend(
28 [
28 [
29 os.path.join(rcdir, f)
29 os.path.join(rcdir, f)
30 for f, kind in util.listdir(rcdir)
30 for f, kind in util.listdir(rcdir)
31 if f.endswith(b".rc")
31 if f.endswith(b".rc")
32 ]
32 ]
33 )
33 )
34 except OSError:
34 except OSError:
35 pass
35 pass
36 return rcs
36 return rcs
37
37
38
38
39 def systemrcpath():
39 def systemrcpath():
40 path = []
40 path = []
41 if pycompat.sysplatform == b'plan9':
41 if pycompat.sysplatform == b'plan9':
42 root = b'lib/mercurial'
42 root = b'lib/mercurial'
43 else:
43 else:
44 root = b'etc/mercurial'
44 root = b'etc/mercurial'
45 # old mod_python does not set sys.argv
45 # old mod_python does not set sys.argv
46 if len(getattr(sys, 'argv', [])) > 0:
46 if len(getattr(sys, 'argv', [])) > 0:
47 p = os.path.dirname(os.path.dirname(pycompat.sysargv[0]))
47 p = os.path.dirname(os.path.dirname(pycompat.sysargv[0]))
48 if p != b'/':
48 if p != b'/':
49 path.extend(_rcfiles(os.path.join(p, root)))
49 path.extend(_rcfiles(os.path.join(p, root)))
50 path.extend(_rcfiles(b'/' + root))
50 path.extend(_rcfiles(b'/' + root))
51 return path
51 return path
52
52
53
53
54 def userrcpath():
54 def userrcpath():
55 if pycompat.sysplatform == b'plan9':
55 if pycompat.sysplatform == b'plan9':
56 return [encoding.environ[b'home'] + b'/lib/hgrc']
56 return [encoding.environ[b'home'] + b'/lib/hgrc']
57 elif pycompat.isdarwin:
57 elif pycompat.isdarwin:
58 return [os.path.expanduser(b'~/.hgrc')]
58 return [os.path.expanduser(b'~/.hgrc')]
59 else:
59 else:
60 confighome = encoding.environ.get(b'XDG_CONFIG_HOME')
60 confighome = encoding.environ.get(b'XDG_CONFIG_HOME')
61 if confighome is None or not os.path.isabs(confighome):
61 if confighome is None or not os.path.isabs(confighome):
62 confighome = os.path.expanduser(b'~/.config')
62 confighome = os.path.expanduser(b'~/.config')
63
63
64 return [
64 return [
65 os.path.expanduser(b'~/.hgrc'),
65 os.path.expanduser(b'~/.hgrc'),
66 os.path.join(confighome, b'hg', b'hgrc'),
66 os.path.join(confighome, b'hg', b'hgrc'),
67 ]
67 ]
68
68
69
69
70 def termsize(ui):
70 def termsize(ui):
71 try:
71 try:
72 import termios
72 import termios
73
73
74 TIOCGWINSZ = termios.TIOCGWINSZ # unavailable on IRIX (issue3449)
74 TIOCGWINSZ = termios.TIOCGWINSZ # unavailable on IRIX (issue3449)
75 except (AttributeError, ImportError):
75 except (AttributeError, ImportError):
76 return 80, 24
76 return 80, 24
77
77
78 for dev in (ui.ferr, ui.fout, ui.fin):
78 for dev in (ui.ferr, ui.fout, ui.fin):
79 try:
79 try:
80 try:
80 try:
81 fd = dev.fileno()
81 fd = dev.fileno()
82 except AttributeError:
82 except AttributeError:
83 continue
83 continue
84 if not os.isatty(fd):
84 if not os.isatty(fd):
85 continue
85 continue
86 arri = fcntl.ioctl(fd, TIOCGWINSZ, b'\0' * 8)
86 arri = fcntl.ioctl(fd, TIOCGWINSZ, b'\0' * 8)
87 height, width = array.array(r'h', arri)[:2]
87 height, width = array.array(r'h', arri)[:2]
88 if width > 0 and height > 0:
88 if width > 0 and height > 0:
89 return width, height
89 return width, height
90 except ValueError:
90 except ValueError:
91 pass
91 pass
92 except IOError as e:
92 except IOError as e:
93 if e[0] == errno.EINVAL:
93 if e[0] == errno.EINVAL: # pytype: disable=unsupported-operands
94 pass
94 pass
95 else:
95 else:
96 raise
96 raise
97 return 80, 24
97 return 80, 24
General Comments 0
You need to be logged in to leave comments. Login now