summaryrefslogtreecommitdiff
path: root/tools/display-fpathconf.py
diff options
context:
space:
mode:
authorJeff Quast <contact@jeffquast.com>2015-10-06 10:17:50 -0700
committerJeff Quast <contact@jeffquast.com>2015-10-06 10:17:50 -0700
commitae932d179adc4c602f9a4298076cdc5a82f9351a (patch)
tree389f0a2ee8ba6722e600f5a8235c1e3b6026db5b /tools/display-fpathconf.py
parent0b7fee3c974d89b7f7f51fef9a1893e25ed980da (diff)
downloadpexpect-git-ae932d179adc4c602f9a4298076cdc5a82f9351a.tar.gz
2 new tools: display-{fpathconf.maxcanon}.py
tests/test_maxcanon.py has been deleted and turned into an "autodetection" tool of sorts, no longer attempting to assert exacting values, but determine it programmatically.
Diffstat (limited to 'tools/display-fpathconf.py')
-rw-r--r--tools/display-fpathconf.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/tools/display-fpathconf.py b/tools/display-fpathconf.py
new file mode 100644
index 0000000..d40cbae
--- /dev/null
+++ b/tools/display-fpathconf.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+"""Displays os.fpathconf values related to terminals. """
+from __future__ import print_function
+import sys
+import os
+
+
+def display_fpathconf():
+ DISP_VALUES = (
+ ('PC_MAX_CANON', ('Max no. of bytes in a '
+ 'terminal canonical input line.')),
+ ('PC_MAX_INPUT', ('Max no. of bytes for which '
+ 'space is available in a terminal input queue.')),
+ ('PC_PIPE_BUF', ('Max no. of bytes which will '
+ 'be written atomically to a pipe.')),
+ ('PC_VDISABLE', 'Terminal character disabling value.')
+ )
+ FMT = '{name:<13} {value:<5} {description}'
+
+ # column header
+ print(FMT.format(name='name', value='value', description='description'))
+ print(FMT.format(name=('-' * 13), value=('-' * 5), description=('-' * 11)))
+
+ fd = sys.stdin.fileno()
+ for name, description in DISP_VALUES:
+ key = os.pathconf_names.get(name, None)
+ if key is None:
+ value = 'UNDEF'
+ else:
+ try:
+ value = os.fpathconf(fd, name)
+ except OSError as err:
+ value = 'OSErrno {0.errno}'.format(err)
+ if name == 'PC_VDISABLE':
+ value = hex(value)
+ print(FMT.format(name=name, value=value, description=description))
+ print()
+
+
+if __name__ == '__main__':
+ display_fpathconf()