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