Python ntpq

Achim Gratz Stromeko at nexgo.de
Sun Nov 27 10:22:19 UTC 2016


Achim Gratz writes:
> Yes, and please provide an option to set that width instead of trying to
> figure out a number that works for everyone.  Well, you can do that too,
> but I can guarantee that whatever number you come up with doesn't work
> for at least one person.

Like this perhaps:

--- a/ntpq/ntpq
+++ b/ntpq/ntpq
@@ -156,6 +156,7 @@ class Ntpq(cmd.Cmd):
         self.pktversion = ntp.packet.NTP_OLDVERSION + 1
         self.uservars = collections.OrderedDict()
         self.ai_family = socket.AF_UNSPEC
+        self.termwidth = ntp.util.termsize()[1]
 
     def emptyline(self):
         "Called when an empty line is entered in response to the prompt."
@@ -288,7 +289,7 @@ usage: help [ command ]
         if not self.__dogetassoc():
             return
         if self.showhostnames:
-            termwidth = ntp.util.termsize()[1]
+            termwidth = interpreter.termwidth
         else:
             termwidth = None   # Default width 
         report = ntp.util.PeerSummary(mode,
@@ -1501,7 +1502,10 @@ USAGE: ntpq [-46dphinOV] [-c str] [-D lvl] [ host ...]
                                 peers
    -n no  numeric        numeric host addresses
    -V opt version        Output version information and exit
-   -w no  wide           enable wide display of addresses
+   -w no  wide           enable wide display of addresses / hosts
+                         on a separate line
+   -W no  width          force output width to this value instead of
+                         querying the terminal size
 '''
 
 if __name__ == '__main__':
@@ -1510,12 +1514,12 @@ if __name__ == '__main__':
 
     try:
         (options, arguments) = getopt.getopt(sys.argv[1:],
-                                             "46c:dD:hinpVw",
+                                             "46c:dD:hinpVwW:",
                                              ["ipv4","ipv6", "command=",
                                               "debug", "set-debug-level=",
                                               "help", "interactive", "numeric",
                                               "peers", "version",
-                                              "wide"])
+                                              "wide", "width="])
     except getopt.GetoptError as e:
         sys.stderr.write("%s\n" % e)
         sys.stderr.write(usage)
@@ -1556,6 +1560,8 @@ if __name__ == '__main__':
             raise SystemExit(0)
         elif switch in ("-w", "--wide"):
             interpreter.wideremote = True
+        elif switch in ("-W", "--width"):
+            interpreter.termwidth = int(val)
 
     if interpreter.interactive and len(interpreter.ccmds) > 0:
         interpreter.warn("%s: invalid option combination.\n" % progname)


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

SD adaptation for Waldorf Blofeld V1.15B11:
http://Synth.Stromeko.net/Downloads.html#WaldorfSDada



More information about the devel mailing list