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