OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 """Displays os.fpathconf values related to terminals. """ |
| 3 from __future__ import print_function |
| 4 import sys |
| 5 import os |
| 6 |
| 7 |
| 8 def display_fpathconf(): |
| 9 DISP_VALUES = ( |
| 10 ('PC_MAX_CANON', ('Max no. of bytes in a ' |
| 11 'terminal canonical input line.')), |
| 12 ('PC_MAX_INPUT', ('Max no. of bytes for which ' |
| 13 'space is available in a terminal input queue.')), |
| 14 ('PC_PIPE_BUF', ('Max no. of bytes which will ' |
| 15 'be written atomically to a pipe.')), |
| 16 ('PC_VDISABLE', 'Terminal character disabling value.') |
| 17 ) |
| 18 FMT = '{name:<13} {value:<5} {description}' |
| 19 |
| 20 # column header |
| 21 print(FMT.format(name='name', value='value', description='description')) |
| 22 print(FMT.format(name=('-' * 13), value=('-' * 5), description=('-' * 11))) |
| 23 |
| 24 fd = sys.stdin.fileno() |
| 25 for name, description in DISP_VALUES: |
| 26 key = os.pathconf_names.get(name, None) |
| 27 if key is None: |
| 28 value = 'UNDEF' |
| 29 else: |
| 30 try: |
| 31 value = os.fpathconf(fd, name) |
| 32 except OSError as err: |
| 33 value = 'OSErrno {0.errno}'.format(err) |
| 34 if name == 'PC_VDISABLE': |
| 35 value = hex(value) |
| 36 print(FMT.format(name=name, value=value, description=description)) |
| 37 print() |
| 38 |
| 39 |
| 40 if __name__ == '__main__': |
| 41 display_fpathconf() |
OLD | NEW |