[Git][NTPsec/ntpsec][master] More armoring for termsize().

Eric S. Raymond gitlab at mg.gitlab.com
Sat Dec 3 12:51:38 UTC 2016


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


Commits:
df2a2873 by Eric S. Raymond at 2016-12-03T07:51:23-05:00
More armoring for termsize().

- - - - -


1 changed file:

- pylib/util.py


Changes:

=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -69,18 +69,22 @@ TermSize = collections.namedtuple("TermSize", ["width", "height"])
 def termsize():
     "Return the current terminal size."
     # Alternatives at http://stackoverflow.com/questions/566746/how-to-get-console-window-width-in-python
-    if not os.isatty(1):
-        size = (80, 24)
-    try:
-        (w, h) = shutil.get_terminal_size((80, 24))
-        size = (w, h)
-    except AttributeError:
-        # OK, Python version < 3.3, cope
-        import fcntl, termios, struct
-        h, w, hp, wp = struct.unpack('HHHH',
-            fcntl.ioctl(2, termios.TIOCGWINSZ,
-            struct.pack('HHHH', 0, 0, 0, 0)))
-        size = (w, h)
+    # The way this is usedd makes it not a big deal if the default is wrong.
+    size = (80, 24)
+    if os.isatty(1):
+        try:
+            (w, h) = shutil.get_terminal_size((80, 24))
+            size = (w, h)
+        except AttributeError:
+            try:
+                # OK, Python version < 3.3, cope
+                import fcntl, termios, struct
+                h, w, hp, wp = struct.unpack('HHHH',
+                    fcntl.ioctl(2, termios.TIOCGWINSZ,
+                    struct.pack('HHHH', 0, 0, 0, 0)))
+                size = (w, h)
+            except IOError:
+                pass
     return TermSize(*size)
 
 class PeerSummary:



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


More information about the vc mailing list