scmposix.py
72 lines
| 1.8 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 | |||
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
|
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(): | ||||
if sys.platform == 'plan9': | ||||
Pulkit Goyal
|
r30276 | return [encoding.environ['home'] + '/lib/hgrc'] | ||
Kevin Bullock
|
r18690 | else: | ||
return [os.path.expanduser('~/.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) | ||||
Yuya Nishihara
|
r30314 | height, width = array.array('h', arri)[:2] | ||
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 | ||