From e763b55b86cf97f538861956e5ecb01f358c752b Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Wed, 2 Aug 2017 05:52:53 +0200 Subject: [PATCH] [modules/disk] Backwards compatibility Add support for showUsed, showSize and showPercent, but mark them as deprecated. see #151 --- bumblebee/engine.py | 4 ++++ bumblebee/modules/disk.py | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/bumblebee/engine.py b/bumblebee/engine.py index e08b639..8882c9b 100644 --- a/bumblebee/engine.py +++ b/bumblebee/engine.py @@ -74,6 +74,10 @@ class Module(object): def update_all(self): self.update(self._widgets) + def has_parameter(self, name): + v = self.parameter(name) + return v is not None + def parameter(self, name, default=None): """Return the config parameter 'name' for this module""" name = "{}.{}".format(self.name, name) diff --git a/bumblebee/modules/disk.py b/bumblebee/modules/disk.py index 625631e..a9b7888 100644 --- a/bumblebee/modules/disk.py +++ b/bumblebee/modules/disk.py @@ -8,6 +8,9 @@ Parameters: * disk.path: Path to calculate disk usage from (defaults to /) * disk.open: Which application / file manager to launch (default xdg-open) * disk.format: Format string, tags {path}, {used}, {left}, {size} and {percent} (defaults to "{path} {used}/{size} ({percent:05.02f}%)") + * (deprecated) disk.showUsed: Show used space (defaults to yes) + * (deprecated) disk.showSize: Show total size (defaults to yes) + * (deprecated) disk.showPercent: Show usage percentage (defaults to yes) """ import os @@ -42,11 +45,34 @@ class Module(bumblebee.engine.Module): left_str = bumblebee.util.bytefmt(self._left) percent_str = self._percent - return self._format.format(path = self._path, - used = used_str, - left = left_str, - size = size_str, - percent = percent_str) + sused = self.has_parameter("showUsed") + ssize = self.has_parameter("showSize") + spercent = self.has_parameter("showPercent") + + if all(not param for param in (sused, ssize, spercent)): + return self._format.format(path = self._path, + used = used_str, + left = left_str, + size = size_str, + percent = percent_str) + else: + rv = "" + sused = bumblebee.util.asbool(self.parameter("showUsed", True)) + ssize = bumblebee.util.asbool(self.parameter("showSize", True)) + spercent = bumblebee.util.asbool(self.parameter("showPercent", True)) + + if sused: + rv = "{}{}".format(rv, used_str) + if sused and ssize: + rv = "{}/".format(rv) + if ssize: + rv = "{}{}".format(rv, size_str) + if spercent: + if not sused and not ssize: + rv = "{:05.02f}%".format(percent_str) + else: + rv = "{} ({:05.02f}%)".format(rv, percent_str) + return rv def update(self, widgets):