[Git][NTPsec/ntpsec][master] Address GitLab issue #371: ntpq ugly traceback

Eric S. Raymond gitlab at mg.gitlab.com
Sat Aug 26 11:31:52 UTC 2017


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


Commits:
5337a42d by Eric S. Raymond at 2017-08-26T07:31:06-04:00
Address GitLab issue #371: ntpq ugly traceback

- - - - -


2 changed files:

- ntpclients/ntpq
- pylib/packet.py


Changes:

=====================================
ntpclients/ntpq
=====================================
--- a/ntpclients/ntpq
+++ b/ntpclients/ntpq
@@ -146,7 +146,7 @@ class Ntpq(cmd.Cmd):
     def __init__(self, session):
         cmd.Cmd.__init__(self)
         self.session = session
-        self.prompt = "ntpq> "
+        self.prompt = "ntpq> " if os.isatty(0) else ""
         self.interactive = False        # set to True when we should prompt
         # self.auth_keyid   = 0# Keyid used for authentication.
         # self.auth_keytype = "NID_md5"# MD5 (FIXME: string value is a dummy)
@@ -1731,7 +1731,8 @@ if __name__ == '__main__':
                     session.close()
         raise SystemExit(0)
     except KeyboardInterrupt:
-        interpreter.say("\n")
+        if os.isatty(0):
+            interpreter.say("\n")
     except ntp.packet.ControlException as e:
         interpreter.warn(e.message + "\n")
     except IOError:


=====================================
pylib/packet.py
=====================================
--- a/pylib/packet.py
+++ b/pylib/packet.py
@@ -184,6 +184,7 @@ A Mode 6 packet cannot have extension fields.
 from __future__ import print_function, division
 import getpass
 import hashlib
+import os
 import select
 import socket
 import string
@@ -911,7 +912,10 @@ class ControlSession:
                     # There are no trusted keys.  Barf.
                     raise ControlException(SERR_NOTRUST)
             try:
-                key_id = int(input("Keyid: "))
+                if os.isatty(0):
+                    key_id = int(input("Keyid: "))
+                else:
+                    key_id = 0
                 if key_id == 0 or key_id > MAX_KEYID:
                     raise ControlException(SERR_BADKEY)
             except (SyntaxError, ValueError):



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/5337a42de07dbe57fafa321751d75e7f098f303b

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/5337a42de07dbe57fafa321751d75e7f098f303b
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170826/19639042/attachment.html>


More information about the vc mailing list