[Git][NTPsec/ntpsec][master] pylib: handle stty OSError exception

Eric S. Raymond gitlab at mg.gitlab.com
Mon Oct 31 01:16:25 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
c6d7ac71 by Stephen Walker at 2016-10-30T21:00:21-04:00
pylib: handle stty OSError exception

$ pyntpq -p
Traceback (most recent call last):
  File "/usr/bin/pyntpq", line 1478, in <module>
    interpreter.onecmd(cmd)
  File "/usr/lib/python2.7/cmd.py", line 221, in onecmd
    return func(arg)
  File "/usr/bin/pyntpq", line 1083, in do_peers
    self.__dopeers(showall=False, mode="peers")
  File "/usr/bin/pyntpq", line 282, in __dopeers
    self.wideremote)
  File "/usr/lib/python2.7/site-packages/ntp/util.py", line 63, in __init__
    self.horizontal_slack = termsize()[1] - 80
  File "/usr/lib/python2.7/site-packages/ntp/util.py", line 44, in termsize
    output = subprocess.check_output(shlex.split('/bin/stty -a'))
  File "/usr/lib/python2.7/subprocess.py", line 567, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

Signed-off-by: Stephen Walker <stephendwalker+github at gmail.com>

- - - - -


1 changed file:

- pylib/util.py


Changes:

=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -39,7 +39,10 @@ def termsize():
     # Should work under Linux and Solaris at least.
     # Alternatives at http://stackoverflow.com/questions/566746/how-to-get-console-window-width-in-python
     import shlex, subprocess, re
-    output = subprocess.check_output(shlex.split('/bin/stty -a'))
+    try:
+        output = subprocess.check_output(shlex.split('/bin/stty -a'))
+    except OSError:
+        return (24, 80)
     m = re.search('rows\D+(\d+); columns\D+(\d+);', output)
     if m:
         return int(m.group(1)), int(m.group(2))



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/c6d7ac71da8626a45faa88f0898a4ddbeb1334d9
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161031/578cd120/attachment.html>


More information about the vc mailing list