Add bumblebee.util.asbool function

Harmonize the boolean parameter value. Now `t`, `true`, `y`, `yes`, `on`, `1` are considered truthy and
everything else falsy.
This commit is contained in:
Frederic Junod 2017-07-08 06:44:08 +02:00
parent cc6da2b70e
commit b0268a412b
6 changed files with 26 additions and 13 deletions

View file

@ -5,7 +5,7 @@
Parameters:
* memory.warning : Warning threshold in % of memory used (defaults to 80%)
* memory.critical: Critical threshold in % of memory used (defaults to 90%)
* memory.usedonly: Only show the amount of RAM in use.
* memory.usedonly: Only show the amount of RAM in use (defaults to False).
"""
try:
@ -29,7 +29,7 @@ class Module(bumblebee.engine.Module):
def memory_usage(self, widget):
used = self._mem.total - self._mem.available
if bool(self.parameter("usedonly", 0)) == 1:
if bumblebee.util.asbool(self.parameter("usedonly", False)):
return bumblebee.util.bytefmt(used)
return "{}/{} ({:05.02f}%)".format(
bumblebee.util.bytefmt(used),