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