[Git][NTPsec/ntpsec][master] Fixes formatting error, and makes ifstats less brittle.
Eric S. Raymond
gitlab at mg.gitlab.com
Sun May 7 19:17:59 UTC 2017
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
19d683db by Ian Bruene at 2017-05-07T14:00:20-05:00
Fixes formatting error, and makes ifstats less brittle.
Previous bugfix neglected to remove the column from the header.
IfstatsSummary.summary() now properly handles missing values, previous
version pretended to, but would have failed anyway.
- - - - -
1 changed file:
- pylib/util.py
Changes:
=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -1007,23 +1007,40 @@ class IfstatsSummary:
"Reusable class for ifstats entry summary generation."
header = """\
interface name send
- # address/broadcast drop flag ttl mc received sent failed peers uptime
+ # address/broadcast drop flag ttl received sent failed peers uptime
"""
- width = 72
+ width = 74
+ # Numbers are the fieldsize
+ fields = {'name': '%-24.24s',
+ 'flags': '%4x',
+ 'tl': '%3d',
+ 'rx': '%6d',
+ 'tx': '%6d',
+ 'txerr': '%6d',
+ 'pc': '%5d',
+ 'up': '%8d'}
def summary(self, i, variables):
+ formatted = {}
+ for name in self.fields.keys():
+ value = variables.get(name, "?")
+ if value == "?":
+ fmt = value
+ else:
+ fmt = self.fields[name] % value
+ formatted[name] = fmt
try:
- s = ("%3u %-24.24s %c %4x %3d %6d %6d %6d %5d %8d\n %s\n"
- % (i, variables['name'],
+ s = ("%3u %-24.24s %c %4s %3s %6s %6s %6s %5s %8s\n %s\n"
+ % (i, formatted['name'],
'.' if variables['en'] else 'D',
- variables.get('flags', '?'),
- variables.get('tl', '?'),
- variables.get('rx', '?'),
- variables.get('tx', '?'),
- variables.get('txerr', '?'),
- variables.get('pc', '?'),
- variables.get('up', '?'),
- variables.get('addr', '?')))
+ formatted['flags'],
+ formatted['tl'],
+ formatted['rx'],
+ formatted['tx'],
+ formatted['txerr'],
+ formatted['pc'],
+ formatted['up'],
+ variables.get('addr', '?')))
if variables.get("bcast"):
s += " %s\n" % variables['bcast']
except TypeError:
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/19d683db53cdb4d6af2607a775bb0faec3419230
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/19d683db53cdb4d6af2607a775bb0faec3419230
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/20170507/bd788c09/attachment.html>
More information about the vc
mailing list