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