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