scmposix.py
85 lines
| 2.4 KiB
| text/x-python
|
PythonLexer
/ mercurial / scmposix.py
Gregory Szorc
|
r27483 | from __future__ import absolute_import | ||
Yuya Nishihara
|
r30311 | import array | ||
Yuya Nishihara
|
r30309 | import errno | ||
import fcntl | ||||
Gregory Szorc
|
r27483 | import os | ||
import sys | ||||
from . import ( | ||||
Pulkit Goyal
|
r30276 | encoding, | ||
Gregory Szorc
|
r27483 | osutil, | ||
Pulkit Goyal
|
r30467 | pycompat, | ||
Gregory Szorc
|
r27483 | ) | ||
Kevin Bullock
|
r18690 | |||
Yuya Nishihara
|
r32078 | # BSD 'more' escapes ANSI color sequences by default. This can be disabled by | ||
# $MORE variable, but there's no compatible option with Linux 'more'. Given | ||||
# OS X is widely used and most modern Unix systems would have 'less', setting | ||||
# 'less' as the default seems reasonable. | ||||
fallbackpager = 'less' | ||||
Kevin Bullock
|
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 = [] | ||||
Pulkit Goyal
|
r30641 | if pycompat.sysplatform == 'plan9': | ||
Kevin Bullock
|
r18690 | root = 'lib/mercurial' | ||
else: | ||||
root = 'etc/mercurial' | ||||
# old mod_python does not set sys.argv | ||||
if len(getattr(sys, 'argv', [])) > 0: | ||||
Pulkit Goyal
|
r30467 | p = os.path.dirname(os.path.dirname(pycompat.sysargv[0])) | ||
Mads Kiilerich
|
r22583 | if p != '/': | ||
path.extend(_rcfiles(os.path.join(p, root))) | ||||
Kevin Bullock
|
r18690 | path.extend(_rcfiles('/' + root)) | ||
return path | ||||
def userrcpath(): | ||||
Pulkit Goyal
|
r30641 | if pycompat.sysplatform == 'plan9': | ||
Pulkit Goyal
|
r30276 | return [encoding.environ['home'] + '/lib/hgrc'] | ||
David Demelier
|
r30941 | elif pycompat.sysplatform == 'darwin': | ||
return [os.path.expanduser('~/.hgrc')] | ||||
Kevin Bullock
|
r18690 | else: | ||
David Demelier
|
r30941 | confighome = encoding.environ.get('XDG_CONFIG_HOME') | ||
if confighome is None or not os.path.isabs(confighome): | ||||
confighome = os.path.expanduser('~/.config') | ||||
return [os.path.expanduser('~/.hgrc'), | ||||
os.path.join(confighome, 'hg', 'hgrc')] | ||||
Yuya Nishihara
|
r30309 | |||
Yuya Nishihara
|
r30314 | def termsize(ui): | ||
Yuya Nishihara
|
r30309 | try: | ||
import termios | ||||
Yuya Nishihara
|
r30311 | TIOCGWINSZ = termios.TIOCGWINSZ # unavailable on IRIX (issue3449) | ||
except (AttributeError, ImportError): | ||||
Yuya Nishihara
|
r30314 | return 80, 24 | ||
Yuya Nishihara
|
r30312 | |||
for dev in (ui.ferr, ui.fout, ui.fin): | ||||
try: | ||||
Yuya Nishihara
|
r30309 | try: | ||
Yuya Nishihara
|
r30312 | fd = dev.fileno() | ||
except AttributeError: | ||||
continue | ||||
if not os.isatty(fd): | ||||
continue | ||||
arri = fcntl.ioctl(fd, TIOCGWINSZ, '\0' * 8) | ||||
Pulkit Goyal
|
r31339 | height, width = array.array(r'h', arri)[:2] | ||
Yuya Nishihara
|
r30314 | if width > 0 and height > 0: | ||
return width, height | ||||
Yuya Nishihara
|
r30312 | except ValueError: | ||
pass | ||||
except IOError as e: | ||||
if e[0] == errno.EINVAL: | ||||
Yuya Nishihara
|
r30309 | pass | ||
Yuya Nishihara
|
r30312 | else: | ||
raise | ||||
Yuya Nishihara
|
r30314 | return 80, 24 | ||