[Git][NTPsec/ntpsec][units-decruftification] 3 commits: waf: add --enable-warnings option
Ian Bruene
gitlab at mg.gitlab.com
Thu Apr 20 00:35:51 UTC 2017
Ian Bruene pushed to branch units-decruftification at NTPsec / ntpsec
Commits:
5704c031 by Gary E. Miller at 2017-04-19T17:13:28-07:00
waf: add --enable-warnings option
Some CC warnings are too usefull to lose, but too annoying for
general usage. --enable-warnings turns them on for developera
that want to see them.
Warnings should generate no ouput are still on by default.
- - - - -
52785e36 by Ian Bruene at 2017-04-19T19:35:27-05:00
Removed strip argument from unitify.
strip was a holdover from the earliest version of these formatters, and
logicaly redundant with the width argument
Now width=None strips any whitespace, and width=N formats into a field size
- - - - -
9b6e8ecf by Ian Bruene at 2017-04-19T19:35:27-05:00
Changed stringfiltcooker() to not use magic number
stringfiltcooker() previously used a magic number to find the correct unit
for output. It now looks up the correct value for the starting unit.
- - - - -
6 changed files:
- ntpclients/ntpmon
- ntpclients/ntpq
- pylib/util.py
- tests/pylib/test_util.py
- wafhelpers/configure.py
- wafhelpers/options.py
Changes:
=====================================
ntpclients/ntpmon
=====================================
--- a/ntpclients/ntpmon
+++ b/ntpclients/ntpmon
@@ -104,19 +104,16 @@ def peer_detail(variables, showunits=False):
if name in vcopy:
vcopy[name] = ntp.util.unitify(vcopyraw[name],
ntp.util.UNIT_MS,
- strip=True,
width=None)
for name in ntp.util.PPM_VARS:
if name in vcopy:
vcopy[name] = ntp.util.unitify(vcopyraw[name],
ntp.util.UNIT_PPM,
- strip=True,
width=None)
for name in ntp.util.S_VARS:
if name in vcopy:
vcopy[name] = ntp.util.unitify(vcopyraw[name],
ntp.util.UNIT_S,
- strip=True,
width=None)
vcopy['filtdelay'] = ntp.util.stringfiltcooker(vcopyraw['filtdelay'])
vcopy['filtoffset'] = ntp.util.stringfiltcooker(vcopyraw['filtoffset'])
=====================================
ntpclients/ntpq
=====================================
--- a/ntpclients/ntpq
+++ b/ntpclients/ntpq
@@ -528,8 +528,7 @@ usage: timeout [ msec ]
self.say("%s %s\n" % (legend, value))
elif fmt in (NTP_UINT, NTP_INT, NTP_FLOAT):
if self.showunits:
- displayvalue = ntp.util.unitifyvar(rawvalue, name,
- strip=True)
+ displayvalue = ntp.util.unitifyvar(rawvalue, name)
else:
displayvalue = value
self.say("%s %s\n" % (legend, displayvalue))
=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -111,7 +111,8 @@ def stringfiltcooker(data):
if count > highestcount:
mostcommon = key
highestcount = count
- newunit = UNITS_SEC[mostcommon + 2] # 2==UNIT_MS, all the filt*s use ms
+ mspos = UNITS_SEC.index(UNIT_MS)
+ newunit = UNITS_SEC[mostcommon + mspos]
# Shift all values to the new unit
cooked = []
for part in parts:
@@ -325,7 +326,7 @@ def unitrelativeto(unit, move):
return None # couldn't find anything
-def unitifyvar(value, varname, baseunit=None, strip=False, width=8):
+def unitifyvar(value, varname, baseunit=None, width=8):
"Call unitify() with the correct units for varname"
if varname in S_VARS:
start = UNIT_S
@@ -335,10 +336,10 @@ def unitifyvar(value, varname, baseunit=None, strip=False, width=8):
start = UNIT_PPM
else:
return value
- return unitify(value, start, baseunit, strip, width)
+ return unitify(value, start, baseunit, width)
-def unitify(value, startingunit, baseunit=None, strip=False, width=8):
+def unitify(value, startingunit, baseunit=None, width=8):
"Formats a numberstring with relevant units. Attemps to fit in width."
if baseunit is None:
baseunit = getunitgroup(startingunit)[0]
@@ -357,7 +358,7 @@ def unitify(value, startingunit, baseunit=None, strip=False, width=8):
newvalue = fitinfield(newvalue, realwidth) + unitget
else: # don't have a replacement unit, use original
newvalue = value + startingunit
- if strip is True:
+ if width is None:
newvalue = newvalue.strip()
return newvalue
@@ -598,20 +599,17 @@ def cook(variables, showunits=False):
# missing variables here.
# Completion cannot occur until all units are tracked down.
if showunits:
- item += unitify(rawvalue, UNIT_MS, UNIT_NS,
- True, width=None)
+ item += unitify(rawvalue, UNIT_MS, UNIT_NS, width=None)
else:
item += repr(value)
elif name in S_VARS:
if showunits:
- item += unitify(rawvalue, UNIT_S, UNIT_NS,
- True, width=None)
+ item += unitify(rawvalue, UNIT_S, UNIT_NS, width=None)
else:
item += repr(value)
elif name in PPM_VARS:
if showunits:
- item += unitify(rawvalue, UNIT_PPM,
- strip=True, width=None)
+ item += unitify(rawvalue, UNIT_PPM, width=None)
else:
item += repr(value)
else:
=====================================
tests/pylib/test_util.py
=====================================
--- a/tests/pylib/test_util.py
+++ b/tests/pylib/test_util.py
@@ -199,7 +199,7 @@ class TestPylibUtilMethods(unittest.TestCase):
# Different units
self.assertEqual(f("12.345", nu.UNIT_PPM), "12.35ppm")
# Strip
- self.assertEqual(f("1.23", nu.UNIT_MS, strip=True), "1.23ms")
+ self.assertEqual(f("1.23", nu.UNIT_MS, width=None), "1.23ms")
# Different width
self.assertEqual(f("1.234", nu.UNIT_MS, width=12), " 1.234ms")
# Outside of available units
@@ -207,8 +207,7 @@ class TestPylibUtilMethods(unittest.TestCase):
# Seconds
self.assertEqual(f("42.23", nu.UNIT_S), " 42.23s")
# Attempt to catch bug
- self.assertEqual(f("15937.5", nu.UNIT_MS, strip=True, width=None),
- "15.9375s")
+ self.assertEqual(f("15937.5", nu.UNIT_MS, width=None), "15.9375s")
def test_stringfiltcooker(self):
# No scale
@@ -233,6 +232,7 @@ class TestPylibUtilMethods(unittest.TestCase):
self.assertEqual(ntp.util.stringfiltcooker(
"0.47 0.4200 0.4300 0.5000 0.4600 0.4200 0.4900 0.4800"),
" 0.47 0.4200 0.4300 0.5000 0.4600 0.4200 0.4900 0.4800 ms")
+
def test_unitrelativeto(self):
f = ntp.util.unitrelativeto
=====================================
wafhelpers/configure.py
=====================================
--- a/wafhelpers/configure.py
+++ b/wafhelpers/configure.py
@@ -301,6 +301,8 @@ def cmd_configure(ctx, config):
if ctx.options.enable_debug:
ctx.define("DEBUG", 1, comment="Enable debug mode")
ctx.env.BISONFLAGS += ["--debug"]
+
+ if ctx.options.enable_warnings:
# turn on some annoying warnings
ctx.env.CFLAGS = [
# "-Wall", # for masochists
=====================================
wafhelpers/options.py
=====================================
--- a/wafhelpers/options.py
+++ b/wafhelpers/options.py
@@ -76,6 +76,8 @@ def options_cmd(ctx, config):
help="Run tests")
grp.add_option('--enable-rtems-trace', action='store_true',
default=False, help="Enable RTEMS Trace.")
+ grp.add_option('--enable-warnings', action='store_true',
+ default=False, help="Enable annoying CC warnings")
grp.add_option('--rtems-trace-path', type='string', default="",
help="Path to rtems-tld.")
grp.add_option(
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/1ab5a99f6608a7bc1f0aba68592f42ddce44b841...9b6e8ecfa09b53302784abc94316369a468fc8b7
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/1ab5a99f6608a7bc1f0aba68592f42ddce44b841...9b6e8ecfa09b53302784abc94316369a468fc8b7
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/20170420/5f926b06/attachment.html>
More information about the vc
mailing list