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