[Git][NTPsec/ntpsec][ntp.util-codacy] Codacy: should be clean 'fixes'
James Browning
gitlab at mg.gitlab.com
Fri Sep 11 19:20:19 UTC 2020
James Browning pushed to branch ntp.util-codacy at NTPsec / ntpsec
Commits:
96178b76 by James Browning at 2020-09-11T12:16:25-07:00
Codacy: should be clean 'fixes'
- - - - -
9 changed files:
- devel/python_paths.py
- ntpclients/ntpdig.py
- ntpclients/ntpkeygen.py
- ntpclients/ntpmon.py
- pylib/poly.py
- wafhelpers/bin_test.py
- wafhelpers/probes.py
- wafhelpers/refclock.py
- wafhelpers/waf.py
Changes:
=====================================
devel/python_paths.py
=====================================
@@ -41,6 +41,7 @@ PYTHON_PREFIX_NAMES = 'sys-prefix std-prefix exec-prefix'.split()
class BadReturn(Exception):
+
"""Bad return from subprocess."""
pass
=====================================
ntpclients/ntpdig.py
=====================================
@@ -78,7 +78,7 @@ def read_append(s, packets, packet, sockaddr):
def queryhost(server, concurrent, timeout=5, port=123):
- "Query IP addresses associated with a specified host."
+ """Query IP addresses associated with a specified host."""
try:
iptuples = socket.getaddrinfo(server, port,
af, socket.SOCK_DGRAM,
@@ -138,7 +138,7 @@ def queryhost(server, concurrent, timeout=5, port=123):
def clock_select(packets):
- "Select the pick-of-the-litter clock from the samples we've got."
+ """Select the pick-of-the-litter clock from the samples we've got."""
# This is a slightly simplified version of the filter ntpdate used
NTP_INFIN = 15 # max stratum, infinity a la Bellman-Ford
@@ -192,7 +192,7 @@ def clock_select(packets):
def report(packet, json):
- "Report on the SNTP packet selected for display, and its adjustment."
+ """Report on the SNTP packet selected for display, and its adjustment."""
say = sys.stdout.write
packet.posixize()
=====================================
ntpclients/ntpkeygen.py
=====================================
@@ -57,7 +57,7 @@ KEYSIZE = 16 # maximum key size
def gen_keys(ident, groupname):
- "Generate semi-random AES keys for versions of ntpd with CMAC support."
+ """Generate semi-random AES keys for versions of ntpd with CMAC support."""
with fheader("AES", ident, groupname) as wp:
for i in range(1, NUMKEYS+1):
key = gen_key(KEYSIZE, True)
@@ -74,7 +74,7 @@ def fheader(fileid, # file name id
ulink, # linkname
owner # owner name
):
- "Generate file header and link"
+ """Generate file header and link."""
try:
filename = "ntpkey_%s_%s.%u" % (fileid, owner, int(time.time()))
orig_umask = os.umask(stat.S_IWGRP | stat.S_IRWXO)
=====================================
ntpclients/ntpmon.py
=====================================
@@ -2,8 +2,7 @@
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-2-Clause
-'''\
-Any keystroke causes a poll and update. Keystroke commands:
+"""Any keystroke causes a poll and update. Keystroke commands:
'a': Change peer display to apeers mode, showing association IDs.
'd': Toggle detail mode (some peer will be reverse-video highlighted when on).
@@ -23,7 +22,7 @@ Any keystroke causes a poll and update. Keystroke commands:
'+': Increase debugging level. Output goes to ntpmon.log
'-': Decrease debugging level.
'?': Display helpscreen.
-'''
+"""
from __future__ import print_function, division
@@ -71,12 +70,12 @@ stdscr = None
def iso8601(t):
- "ISO8601 string from Unix time."
+ """ISO8601 string from Unix time."""
return time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(t))
def statline(_peerlist, _mrulist, nyquist):
- "Generate a status line"
+ """Generate a status line."""
# We don't use stdversion here because the presence of a date is confusing
leader = sysvars['version'][0]
leader = re.sub(r" \([^\)]*\)", "", leader)
@@ -91,7 +90,7 @@ def statline(_peerlist, _mrulist, nyquist):
def peer_detail(variables, showunits=False):
- "Show the things a peer summary doesn't, cooked slightly differently"
+ """Show the things a peer summary doesn't, cooked slightly differently."""
# All of an rv display except refid, reach, delay, offset, jitter.
# One of the goals here is to emit field values at fixed positions
# on the 2D display, so that changes in the details are easier to spot.
@@ -160,8 +159,8 @@ filtdisp = %(filtdisp)s
class Fatal(Exception):
- "Unrecoverable error."
+ """Unrecoverable error."""
def __init__(self, msg):
Exception.__init__(self)
self.msg = msg
@@ -172,7 +171,7 @@ class Fatal(Exception):
class OutputContext:
def __enter__(self):
- "Begin critical region."
+ """Begin critical region."""
if sys.version_info[0] < 3 and not disableunicode:
# This appears to only be needed under python 2, it is only
# activated when we already have UTF-8. Otherwise we drop
=====================================
pylib/poly.py
=====================================
@@ -2,7 +2,7 @@
# SPDX-License-Identifier: BSD-2-Clause
"""Handle bytes and strings in a polyglot fashion.
-copied from ../ntpclient/ntpq.py which got it from
+This is copied from ../ntpclient/ntpq.py which got it from
https://gitlab.com/esr/practical-python-porting/blob/master/polystr-inclusion.py
see http://www.catb.org/esr/faqs/practical-python-porting/ for more information.
"""
@@ -70,18 +70,16 @@ else: # Python 3
return bytes(s, encoding=master_encoding)
def polyord(c):
- "Polymorphic ord() function"
+ """Polymorphic ord() function."""
if isinstance(c, str):
return ord(c)
- else:
- return c
+ return c
def polychr(c):
- "Polymorphic chr() function"
+ """Polymorphic chr() function."""
if isinstance(c, int):
return chr(c)
- else:
- return c
+ return c
def string_escape(s):
"""Polymorphic string_escape/unicode_escape."""
=====================================
wafhelpers/bin_test.py
=====================================
@@ -41,12 +41,14 @@ test_logs = []
def addLog(color, text):
- test_logs.append((color, text))
+ """Append to the test logs."""
+ test_logs.append((color, text.rstrip()))
-def bin_test_summary(ctx):
+def bin_test_summary(_):
+ """Print out the test logs."""
for i in test_logs:
- waflib.Logs.pprint(i[0], i[1])
+ waflib.Logs.pprint(*i)
def run(cmd, reg, pythonic):
@@ -85,7 +87,7 @@ def run(cmd, reg, pythonic):
return False
-def cmd_bin_test(ctx, config):
+def cmd_bin_test(ctx, _):
"""Run a suite of binary tests."""
fails = 0
=====================================
wafhelpers/probes.py
=====================================
@@ -1,11 +1,9 @@
-"""
-This module exists to contain custom probe functions so they don't clutter
-up the logic in the main configure.py.
-"""
+"""This module exists to contain custom probe functions so they don't clutter
+up the logic in the main configure.py."""
def probe_header(ctx, header, prerequisites, mandatory=False, use=None):
- "Check that a header (with its prerequisites) compiles."
+ """Check that a header (with its prerequisites) compiles."""
src = ""
for hdr in prerequisites + [header]:
src += "#include <%s>\n" % hdr
@@ -24,7 +22,7 @@ def probe_header(ctx, header, prerequisites, mandatory=False, use=None):
def probe_function(ctx, function, prerequisites, mandatory=False, use=None):
- "Check that a function (with its prerequisites) compiles."
+ """Check that a function (with its prerequisites) compiles."""
src = ""
for hdr in prerequisites:
src += "#include <%s>\n" % hdr
=====================================
wafhelpers/refclock.py
=====================================
@@ -1,3 +1,4 @@
+"""Add refclock backing and handle refclock options."""
from waflib.Configure import conf
from waflib.Logs import pprint
@@ -105,6 +106,7 @@ refclock_map = {
@conf
def refclock_config(ctx):
+ """Handle refclock options."""
if ctx.options.refclocks == "all":
ids = refclock_map.keys()
else:
@@ -118,11 +120,11 @@ def refclock_config(ctx):
[unique_id.append(x) for x in ids if x not in unique_id]
refclock = False
- for id in unique_id:
- if id not in refclock_map:
- ctx.fatal("'%s' is not a valid Refclock ID" % id)
+ for ident in unique_id:
+ if ident not in refclock_map:
+ ctx.fatal("'%s' is not a valid Refclock ID" % ident)
- rc = refclock_map[id]
+ rc = refclock_map[ident]
if rc['define'] == "CLOCK_GENERIC":
parse_clocks = (
@@ -142,22 +144,21 @@ def refclock_config(ctx):
for subtype in parse_clocks:
ctx.define(subtype, 1, comment="Enable individual parse clock")
- ctx.start_msg("Enabling Refclock %s (%s):" % (rc["descr"], id))
+ ctx.start_msg("Enabling Refclock %s (%s):" % (rc["descr"], ident))
- if "require" in rc:
- if "ppsapi" in rc["require"]:
- if not ctx.get_define("HAVE_PPSAPI"):
- ctx.end_msg("No")
- pprint("RED",
- "Refclock \"%s\" disabled, PPS API has not "
- "been detected as working." % rc["descr"])
- continue
+ if not ctx.get_define("HAVE_PPSAPI"):
+ if "ppsapi" in rc.get("require", {}):
+ ctx.end_msg("No")
+ pprint("RED",
+ "Refclock \"%s\" disabled, PPS API has not "
+ "been detected as working." % rc["descr"])
+ continue
ctx.env.REFCLOCK_SOURCE.append((rc["file"], rc["define"]))
ctx.env["REFCLOCK_%s" % rc["file"].upper()] = True
ctx.define(rc["define"], 1,
comment="Enable '%s' refclock" % rc["descr"])
- ctx.env.REFCLOCK_LIST += [str(id)]
+ ctx.env.REFCLOCK_LIST += [str(ident)]
ctx.end_msg("Yes")
=====================================
wafhelpers/waf.py
=====================================
@@ -1,8 +1,10 @@
+"""Add three miscelaneous tools."""
from waflib.Configure import conf
from waflib.TaskGen import re_m4
def manpage_subst_fun(self, code):
+ """Convert asciidoc source for manpage."""
# Since we are providing a custom substitution method, we must implement
# the default behavior, since we want that too.
global re_m4
@@ -14,6 +16,7 @@ def manpage_subst_fun(self, code):
lst = []
def repl(match):
+ """Change @foo@ to %(foo) for (not) str.format()."""
g = match.group
if g(1):
lst.append(g(1))
@@ -40,7 +43,7 @@ def manpage_subst_fun(self, code):
@conf
def manpage(ctx, section, source):
-
+ """Build a man page in a section."""
if not ctx.env.BUILD_MAN:
return
@@ -54,6 +57,7 @@ def manpage(ctx, section, source):
@conf
def ntp_test(ctx, **kwargs):
+ """Run a (Python?) test."""
bldnode = ctx.bldnode.abspath()
tg = ctx(**kwargs)
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/96178b76875111eaef022096414b61c4fe726560
--
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/96178b76875111eaef022096414b61c4fe726560
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/20200911/3e5eda37/attachment-0001.htm>
More information about the vc
mailing list