[Git][NTPsec/ntpsec][master] 3 commits: ntpwait: conform to pep8

Gary E. Miller gitlab at mg.gitlab.com
Tue Jan 3 02:43:02 UTC 2017


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
4810eb0a by Gary E. Miller at 2017-01-02T17:55:18-08:00
ntpwait: conform to pep8

- - - - -
92ef86b2 by Gary E. Miller at 2017-01-02T18:24:48-08:00
ntptrace: conform to pep8

- - - - -
4da49217 by Gary E. Miller at 2017-01-02T18:42:34-08:00
ntpsweep: conform to pep8

- - - - -


3 changed files:

- ntpclients/ntpsweep
- ntpclients/ntptrace
- ntpclients/ntpwait


Changes:

=====================================
ntpclients/ntpsweep
=====================================
--- a/ntpclients/ntpsweep
+++ b/ntpclients/ntpsweep
@@ -5,8 +5,9 @@ USAGE: ntpsweep [-<flag> [<val>] | --<name>[{=| }<val>]]... [hostfile]
 
     -l, --host-list=str        Host to execute actions on
                                    - may appear multiple times
-    -p, --peers                Recursively list all peers a host synchronizes to
-    -m, --maxlevel=num         Traverse peers up to this level (4 is a reasonable number)
+    -p, --peers                Recursively list all peers a host syncs to
+    -m, --maxlevel=num         Traverse peers up to this level
+                                   (4 is a reasonable number)
     -s, --strip=str            Strip this string from hostnames
 
 Options are specified by doubled hyphens and their name or by a single
@@ -22,19 +23,27 @@ hyphen and the flag character.
 
 from __future__ import print_function
 
-import os, sys, getopt
-import ntp.packet, ntp.util
+import os
+import sys
+import getopt
+import ntp.packet
+import ntp.util
+
 
 def ntp_peers(host):
-    "Return a list of peer IP addrs for a specified host, empty list if query failed."
+    """Return: a list of peer IP addrs for a specified host,
+            empty list if query failed.
+    """
     try:
         with os.popen("ntpq -npw " + host) as rp:
-            hostlines = rp.readlines()[2:]	# Drop display header
+            hostlines = rp.readlines()[2:]      # Drop display header
             # Strip tally mark from first field
-            return [ln.split()[0][1:] for ln in hostlines if ln[0] in " x.-+#*o"]
+            return [ln.split()[0][1:] for
+                    ln in hostlines if ln[0] in " x.-+#*o"]
     except OSError:
         return []
 
+
 def scan_host(host, level):
     stratum = 0
     offset = 0
@@ -53,14 +62,14 @@ def scan_host(host, level):
 
         # got answers ? If so, go on.
         if isinstance(sysvars, dict):
-            stratum       = sysvars['stratum']
-            offset        = sysvars['offset']
+            stratum = sysvars['stratum']
+            offset = sysvars['offset']
             daemonversion = sysvars['version']
-            system        = sysvars['system']
-            processor     = sysvars['processor']
+            system = sysvars['system']
+            processor = sysvars['processor']
 
             # Shorten daemon_version string.
-            #daemonversion =~ s/(|Mon|Tue|Wed|Thu|Fri|Sat|Sun).*$//
+            # daemonversion =~ s/(|Mon|Tue|Wed|Thu|Fri|Sat|Sun).*$//
             daemonversion = daemonversion.replace("version=", "")
             daemonversion = daemonversion.replace("ntpd ", "")
             daemonversion = daemonversion.replace("(", "").replace(")", "")
@@ -93,13 +102,14 @@ def scan_host(host, level):
             # Stratum level 0 is considered invalid
             known_host_info[host] = " ?"
 
-    if stratum or known_host: # Valid or known host
+    if stratum or known_host:   # Valid or known host
         printhost = (' ' * level) + (ntp.util.canonicalize_dns(host) or host)
         # Shorten host string
         if strip:
             printhost = printhost.replace(strip, "")
         # append number of peers in brackets if requested and valid
-        if recurse and known_host_info[host] != " ?" and host in known_host_peers:
+        if (recurse and (known_host_info[host] != " ?") and
+           (host in known_host_peers)):
             printhost += " (%d)" % len(known_host_peers[host])
         # Finally print complete host line
         print("%-32s %s" % (printhost[:32], known_host_info[host]))
@@ -122,7 +132,7 @@ def scan_host(host, level):
                     # NTPsec-style clock IDs.
                     if peer[0].isdigit() and not peer.startswith("127"):
                         scan_host(peer, level + 1)
-    else: # We did not get answers from this host
+    else:   # We did not get answers from this host
         printhost = (' ' * level) + (ntp.util.canonicalize_dns(host) or host)
         if strip:
             printhost = printhost.replace(strip, "")


=====================================
ntpclients/ntptrace
=====================================
--- a/ntpclients/ntptrace
+++ b/ntpclients/ntptrace
@@ -8,7 +8,7 @@ Usage: ntptrace [-n | --numeric] [-m number | --max-hosts=number]
 
 See the manual page for details.
 """
-#SPDX-License-Identifier: BSD-2-Clause
+# SPDX-License-Identifier: BSD-2-Clause
 
 from __future__ import print_function
 
@@ -18,6 +18,7 @@ import subprocess
 import sys
 import ntp.util
 
+
 def get_info(host):
     info = ntp_read_vars(0, [], host)
     if info is None or 'stratum' not in info:
@@ -55,7 +56,9 @@ def ntp_read_vars(peer, vars, host):
         cmd.append(host)
 
     try:
-        output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode('utf-8').splitlines()
+        output = subprocess.check_output(
+            cmd,
+            stderr=subprocess.STDOUT).decode('utf-8').splitlines()
     except subprocess.CalledProcessError as e:
         print("Could not start ntpq: %s" % e.output, file=sys.stderr)
         raise SystemExit(1)
@@ -67,7 +70,8 @@ def ntp_read_vars(peer, vars, host):
         if re.search(r'Connection refused', line):
             return
 
-        match = re.search(r'^asso?c?id=0 status=(\S{4}) (\S+), (\S+),', line, flags=re.IGNORECASE)
+        match = re.search(r'^asso?c?id=0 status=(\S{4}) (\S+), (\S+),', line,
+                          flags=re.IGNORECASE)
         if match:
             outvars['status_line']['status'] = match.group(1)
             outvars['status_line']['leap'] = match.group(2)
@@ -138,12 +142,14 @@ while True:
         host = ntp.util.canonicalize_dns(host)
 
     print("%s: stratum %d, offset %f, synch distance %f" %
-          (host, int(info['stratum']), info['offset'], info['syncdistance']), end='')
+          (host, int(info['stratum']), info['offset'], info['syncdistance']),
+          end='')
     if int(info['stratum']) == 1:
         print(", refid '%s'" % info['refid'], end='')
     print()
 
-    if int(info['stratum']) == 0 or int(info['stratum']) == 1 or int(info['stratum']) == 16:
+    if (int(info['stratum']) == 0 or int(info['stratum']) == 1 or
+            int(info['stratum']) == 16):
         break
 
     if re.search(r'^127\.127\.\d{1,3}\.\d{1,3}$', info['refid']):


=====================================
ntpclients/ntpwait
=====================================
--- a/ntpclients/ntpwait
+++ b/ntpclients/ntpwait
@@ -13,10 +13,13 @@ hyphen and the flag character.
 
 A spurious 'not running' message can result from queries being disabled.
 """
-#SPDX-License-Identifier: BSD-2-Clause
+# SPDX-License-Identifier: BSD-2-Clause
 from __future__ import print_function, division
 
-import sys, getopt, re, time
+import sys
+import getopt
+import re
+import time
 import socket
 import ntp.magic
 import ntp.packet
@@ -100,13 +103,16 @@ else:  # Python 3
         # This ensures that the encoding of standard output and standard
         # error on Python 3 matches the master encoding we use to turn
         # bytes to Unicode in polystr above
-        # line_buffering=True ensures that interactive command sessions work as expected
-        return io.TextIOWrapper(stream.buffer, encoding=master_encoding, newline="\n", line_buffering=True)
+        # line_buffering=True ensures that interactive command sessions
+        # work as expected
+        return io.TextIOWrapper(stream.buffer, encoding=master_encoding,
+                                newline="\n", line_buffering=True)
 
     sys.stdin = make_std_wrapper(sys.stdin)
     sys.stdout = make_std_wrapper(sys.stdout)
     sys.stderr = make_std_wrapper(sys.stderr)
 
+
 class Unbuffered(object):
     def __init__(self, stream):
         self.stream = stream
@@ -148,14 +154,14 @@ if __name__ == "__main__":
 
     for i in range(1, tries):
         session = ntp.packet.ControlSession()
-        #session.debug = 4
+        # session.debug = 4
         if not session.openhost("localhost"):
             if verbose:
                 sys.stdout.write("\bntpd is not running!\n")
             continue
 
         try:
-            msg = session.doquery(2)	# Request system variables
+            msg = session.doquery(2)     # Request system variables
         except socket.error:
             if verbose:
                 sys.stdout.write("\b" + "*+:."[i % 4])
@@ -184,7 +190,8 @@ if __name__ == "__main__":
                 time.sleep(sleep)
             continue
 
-        if leap in (ntp.magic.LEAP_NOWARNING, ntp.magic.LEAP_ADDSECOND, ntp.magic.LEAP_DELSECOND):
+        if leap in (ntp.magic.LEAP_NOWARNING, ntp.magic.LEAP_ADDSECOND,
+                    ntp.magic.LEAP_DELSECOND):
             # We could check "sync" here to make sure we like the source...
             if verbose:
                 sys.stdout.write("\bOK!\n")



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/46442bfccfca4491e236f8097bfe360f256aec00...4da49217cb74d0e905aef274dd5cba7f56aa9141
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170103/6306ef61/attachment.html>


More information about the vc mailing list