##// END OF EJS Templates
smcposix: pass unicode as first argument to array.array...
Pulkit Goyal -
r31339:7c09b071 default
parent child Browse files
Show More
@@ -1,79 +1,79 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 . import (
9 from . import (
10 encoding,
10 encoding,
11 osutil,
11 osutil,
12 pycompat,
12 pycompat,
13 )
13 )
14
14
15 def _rcfiles(path):
15 def _rcfiles(path):
16 rcs = [os.path.join(path, 'hgrc')]
16 rcs = [os.path.join(path, 'hgrc')]
17 rcdir = os.path.join(path, 'hgrc.d')
17 rcdir = os.path.join(path, 'hgrc.d')
18 try:
18 try:
19 rcs.extend([os.path.join(rcdir, f)
19 rcs.extend([os.path.join(rcdir, f)
20 for f, kind in osutil.listdir(rcdir)
20 for f, kind in osutil.listdir(rcdir)
21 if f.endswith(".rc")])
21 if f.endswith(".rc")])
22 except OSError:
22 except OSError:
23 pass
23 pass
24 return rcs
24 return rcs
25
25
26 def systemrcpath():
26 def systemrcpath():
27 path = []
27 path = []
28 if pycompat.sysplatform == 'plan9':
28 if pycompat.sysplatform == 'plan9':
29 root = 'lib/mercurial'
29 root = 'lib/mercurial'
30 else:
30 else:
31 root = 'etc/mercurial'
31 root = 'etc/mercurial'
32 # old mod_python does not set sys.argv
32 # old mod_python does not set sys.argv
33 if len(getattr(sys, 'argv', [])) > 0:
33 if len(getattr(sys, 'argv', [])) > 0:
34 p = os.path.dirname(os.path.dirname(pycompat.sysargv[0]))
34 p = os.path.dirname(os.path.dirname(pycompat.sysargv[0]))
35 if p != '/':
35 if p != '/':
36 path.extend(_rcfiles(os.path.join(p, root)))
36 path.extend(_rcfiles(os.path.join(p, root)))
37 path.extend(_rcfiles('/' + root))
37 path.extend(_rcfiles('/' + root))
38 return path
38 return path
39
39
40 def userrcpath():
40 def userrcpath():
41 if pycompat.sysplatform == 'plan9':
41 if pycompat.sysplatform == 'plan9':
42 return [encoding.environ['home'] + '/lib/hgrc']
42 return [encoding.environ['home'] + '/lib/hgrc']
43 elif pycompat.sysplatform == 'darwin':
43 elif pycompat.sysplatform == 'darwin':
44 return [os.path.expanduser('~/.hgrc')]
44 return [os.path.expanduser('~/.hgrc')]
45 else:
45 else:
46 confighome = encoding.environ.get('XDG_CONFIG_HOME')
46 confighome = encoding.environ.get('XDG_CONFIG_HOME')
47 if confighome is None or not os.path.isabs(confighome):
47 if confighome is None or not os.path.isabs(confighome):
48 confighome = os.path.expanduser('~/.config')
48 confighome = os.path.expanduser('~/.config')
49
49
50 return [os.path.expanduser('~/.hgrc'),
50 return [os.path.expanduser('~/.hgrc'),
51 os.path.join(confighome, 'hg', 'hgrc')]
51 os.path.join(confighome, 'hg', 'hgrc')]
52
52
53 def termsize(ui):
53 def termsize(ui):
54 try:
54 try:
55 import termios
55 import termios
56 TIOCGWINSZ = termios.TIOCGWINSZ # unavailable on IRIX (issue3449)
56 TIOCGWINSZ = termios.TIOCGWINSZ # unavailable on IRIX (issue3449)
57 except (AttributeError, ImportError):
57 except (AttributeError, ImportError):
58 return 80, 24
58 return 80, 24
59
59
60 for dev in (ui.ferr, ui.fout, ui.fin):
60 for dev in (ui.ferr, ui.fout, ui.fin):
61 try:
61 try:
62 try:
62 try:
63 fd = dev.fileno()
63 fd = dev.fileno()
64 except AttributeError:
64 except AttributeError:
65 continue
65 continue
66 if not os.isatty(fd):
66 if not os.isatty(fd):
67 continue
67 continue
68 arri = fcntl.ioctl(fd, TIOCGWINSZ, '\0' * 8)
68 arri = fcntl.ioctl(fd, TIOCGWINSZ, '\0' * 8)
69 height, width = array.array('h', arri)[:2]
69 height, width = array.array(r'h', arri)[:2]
70 if width > 0 and height > 0:
70 if width > 0 and height > 0:
71 return width, height
71 return width, height
72 except ValueError:
72 except ValueError:
73 pass
73 pass
74 except IOError as e:
74 except IOError as e:
75 if e[0] == errno.EINVAL:
75 if e[0] == errno.EINVAL:
76 pass
76 pass
77 else:
77 else:
78 raise
78 raise
79 return 80, 24
79 return 80, 24
General Comments 0
You need to be logged in to leave comments. Login now