##// END OF EJS Templates
py3: replace os.sep with pycompat.ossep (part 1 of 4)...
py3: replace os.sep with pycompat.ossep (part 1 of 4) os.sep returns unicodes on Python 3. We have pycompat.ossep which returns bytes. This patch is a part of 4 patch series which will replace all the occurrences of os.sep to pycompat.ossep

File last commit:

r30467:5b0baa9f default
r30613:1112ff99 default
Show More
scmposix.py
72 lines | 1.8 KiB | text/x-python | PythonLexer
Gregory Szorc
scmposix: use absolute_import
r27483 from __future__ import absolute_import
Yuya Nishihara
scmutil: narrow ImportError handling in termwidth()...
r30311 import array
Yuya Nishihara
scmutil: move util.termwidth()...
r30309 import errno
import fcntl
Gregory Szorc
scmposix: use absolute_import
r27483 import os
import sys
from . import (
Pulkit Goyal
py3: make scmposix.userrcpath() return bytes...
r30276 encoding,
Gregory Szorc
scmposix: use absolute_import
r27483 osutil,
Pulkit Goyal
py3: use pycompat.sysargv in scmposix.systemrcpath()...
r30467 pycompat,
Gregory Szorc
scmposix: use absolute_import
r27483 )
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690
def _rcfiles(path):
rcs = [os.path.join(path, 'hgrc')]
rcdir = os.path.join(path, 'hgrc.d')
try:
rcs.extend([os.path.join(rcdir, f)
for f, kind in osutil.listdir(rcdir)
if f.endswith(".rc")])
except OSError:
pass
return rcs
def systemrcpath():
path = []
if sys.platform == 'plan9':
root = 'lib/mercurial'
else:
root = 'etc/mercurial'
# old mod_python does not set sys.argv
if len(getattr(sys, 'argv', [])) > 0:
Pulkit Goyal
py3: use pycompat.sysargv in scmposix.systemrcpath()...
r30467 p = os.path.dirname(os.path.dirname(pycompat.sysargv[0]))
Mads Kiilerich
config: don't read the same config file twice...
r22583 if p != '/':
path.extend(_rcfiles(os.path.join(p, root)))
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 path.extend(_rcfiles('/' + root))
return path
def userrcpath():
if sys.platform == 'plan9':
Pulkit Goyal
py3: make scmposix.userrcpath() return bytes...
r30276 return [encoding.environ['home'] + '/lib/hgrc']
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 else:
return [os.path.expanduser('~/.hgrc')]
Yuya Nishihara
scmutil: move util.termwidth()...
r30309
Yuya Nishihara
scmutil: extend termwidth() to return terminal height, renamed to termsize()...
r30314 def termsize(ui):
Yuya Nishihara
scmutil: move util.termwidth()...
r30309 try:
import termios
Yuya Nishihara
scmutil: narrow ImportError handling in termwidth()...
r30311 TIOCGWINSZ = termios.TIOCGWINSZ # unavailable on IRIX (issue3449)
except (AttributeError, ImportError):
Yuya Nishihara
scmutil: extend termwidth() to return terminal height, renamed to termsize()...
r30314 return 80, 24
Yuya Nishihara
scmutil: remove superfluous indent from termwidth()
r30312
for dev in (ui.ferr, ui.fout, ui.fin):
try:
Yuya Nishihara
scmutil: move util.termwidth()...
r30309 try:
Yuya Nishihara
scmutil: remove superfluous indent from termwidth()
r30312 fd = dev.fileno()
except AttributeError:
continue
if not os.isatty(fd):
continue
arri = fcntl.ioctl(fd, TIOCGWINSZ, '\0' * 8)
Yuya Nishihara
scmutil: extend termwidth() to return terminal height, renamed to termsize()...
r30314 height, width = array.array('h', arri)[:2]
if width > 0 and height > 0:
return width, height
Yuya Nishihara
scmutil: remove superfluous indent from termwidth()
r30312 except ValueError:
pass
except IOError as e:
if e[0] == errno.EINVAL:
Yuya Nishihara
scmutil: move util.termwidth()...
r30309 pass
Yuya Nishihara
scmutil: remove superfluous indent from termwidth()
r30312 else:
raise
Yuya Nishihara
scmutil: extend termwidth() to return terminal height, renamed to termsize()...
r30314 return 80, 24