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